client_golang/prometheus
Michael Stapelberg c1370d07ca Strip trailing / from push URL.
This circumvents the following problem:
• The prometheus client library appends “/metrics/…” to the pushURL.
• When pushURL ends in a trailing slash, the URL becomes e.g.
  http://pushgateway.example.com:9091//metrics/…
• The pushgateway will reply with an HTTP 307 status code
  (temporary redirect).
• While Go’s net/http client follows redirects by default, it will only
  follow HTTP 302 (Found) and HTTP 303 (See Other) redirects for PUT and
  POST requests, which the prometheus client library uses.

Hence, when calling e.g.:

    prometheus.Push("foo", "bar", "http://pushgateway.example.com:9091/")

…your metrics would not actually get pushed successfully, but rather
you’d see the error message:

    2015/11/26 10:59:49 main.go:209: unexpected status code 307 while pushing to http://push...
2015-11-26 19:16:53 +01:00
..
.gitignore Rearrange file and package per convention. 2013-04-04 15:27:09 +02:00
README.md Fix document 2015-02-11 17:35:04 -05:00
benchmark_test.go concurrency benchmark 2015-11-09 14:34:37 +01:00
collector.go Change "Prometheus Team" to "The Prometheus Authors". 2015-02-02 15:14:36 +01:00
counter.go Inline hash/fnv. 2015-11-09 15:16:26 +01:00
counter_test.go Use non-rewritten Godep imports. 2015-02-27 16:49:40 +01:00
desc.go use local fnv hash everywhere 2015-11-12 14:07:23 +01:00
doc.go Mention histograms in doc.go. 2015-06-13 12:20:08 +02:00
example_clustermanager_test.go Change "Prometheus Team" to "The Prometheus Authors". 2015-02-02 15:14:36 +01:00
example_memstats_test.go Change "Prometheus Team" to "The Prometheus Authors". 2015-02-02 15:14:36 +01:00
example_selfcollector_test.go Use non-rewritten Godep imports. 2015-02-27 16:49:40 +01:00
examples_test.go Document the possibility to create "empty" metrics in a metric vector. 2015-07-15 13:13:56 +02:00
expvar.go Change "Prometheus Team" to "The Prometheus Authors". 2015-02-02 15:14:36 +01:00
expvar_test.go Use non-rewritten Godep imports. 2015-02-27 16:49:40 +01:00
fnv.go use local fnv hash everywhere 2015-11-12 14:07:23 +01:00
gauge.go Inline hash/fnv. 2015-11-09 15:16:26 +01:00
gauge_test.go Use non-rewritten Godep imports. 2015-02-27 16:49:40 +01:00
go_collector.go heap bytes released total 2015-10-07 11:21:49 -07:00
go_collector_test.go Fix minor typos in comment. 2015-08-17 12:58:16 +02:00
histogram.go Inline hash/fnv. 2015-11-09 15:16:26 +01:00
histogram_test.go Inline hash/fnv. 2015-11-09 15:16:26 +01:00
http.go Solve "The Proxy Problem" of InstrumentHandler 2015-06-04 23:48:40 +02:00
http_test.go Use non-rewritten Godep imports. 2015-02-27 16:49:40 +01:00
metric.go Remove client_golang/model als direct dependency 2015-08-23 13:51:32 +02:00
metric_test.go Change "Prometheus Team" to "The Prometheus Authors". 2015-02-02 15:14:36 +01:00
process_collector.go Inline and remove processCollectSupported(). 2015-04-01 01:18:20 +02:00
process_collector_test.go Use non-rewritten Godep imports. 2015-02-27 16:49:40 +01:00
push.go fix typo: s/addr/url/ 2015-11-25 08:46:01 +01:00
registry.go Strip trailing / from push URL. 2015-11-26 19:16:53 +01:00
registry_test.go Fix a number of minor things. 2015-06-09 12:03:07 +02:00
summary.go Inline hash/fnv. 2015-11-09 15:16:26 +01:00
summary_test.go Return NaN when summaries have no observations yet. 2015-03-15 16:33:56 +01:00
untyped.go Inline hash/fnv. 2015-11-09 15:16:26 +01:00
value.go Ensure alignment of struct members used in sync.atomic functions. 2015-05-21 12:19:38 +02:00
vec.go try getting metrics with a read lock, first 2015-11-09 15:16:26 +01:00
vec_test.go Inline hash/fnv. 2015-11-09 15:16:26 +01:00

README.md

Overview

This is the Prometheus telemetric instrumentation client Go client library. It enable authors to define process-space metrics for their servers and expose them through a web service interface for extraction, aggregation, and a whole slew of other post processing techniques.

Installing

$ go get github.com/prometheus/client_golang/prometheus

Example

package main

import (
	"net/http"

	"github.com/prometheus/client_golang/prometheus"
)

var (
	indexed = prometheus.NewCounter(prometheus.CounterOpts{
		Namespace: "my_company",
		Subsystem: "indexer",
		Name:      "documents_indexed",
		Help:      "The number of documents indexed.",
	})
	size = prometheus.NewGauge(prometheus.GaugeOpts{
		Namespace: "my_company",
		Subsystem: "storage",
		Name:      "documents_total_size_bytes",
		Help:      "The total size of all documents in the storage.",
	})
)

func main() {
	http.Handle("/metrics", prometheus.Handler())

	indexed.Inc()
	size.Set(5)

	http.ListenAndServe(":8080", nil)
}

func init() {
	prometheus.MustRegister(indexed)
	prometheus.MustRegister(size)
}

Documentation

GoDoc