client_golang/prometheus
Bjoern Rabenstein 159e96f6c7 Allow error reporting during metrics collection and simplify Register().
Both are interface changes I want to get in before public
announcement. They only break rare usage cases, and are always easy to
fix, but still we want to avoid breaking changes after a wider
announcement of the project.

The change of Register() simply removes the return of the Collector,
which nobody was using in practice. It was just bloating the call
syntax. Note that this is different from RegisterOrGet(), which is
used at various occasions where you want to register something that
might or might not be registered already, but if it is, you want the
previously registered Collector back (because that's the relevant
one).

WRT error reporting: I first tried the obvious way of letting the
Collector methods Describe() and Collect() return error. However, I
had to conclude that that bloated _many_ calls and their handling in
very obnoxious ways. On the other hand, the case where you actually
want to report errors during registration or collection is very
rare. Hence, this approach has the wrong trade-off. The approach taken
here might at first appear clunky but is in practice quite handy,
mostly because there is almost no change for the "normal" case of "no
special error handling", but also because it plays well with the way
descriptors and metrics are handled (via channels).

Explaining the approach in more detail:

- During registration / describe: Error handling was actually already
  in place (for invalid descriptors, which carry an error anyway). I
  only added a convenience function to create an invalid descriptor
  with a given error on purpose.

- Metrics are now treated in a similar way. The Write method returns
  an error now (the only change in interface). An "invalid metric" is
  provided that can be sent via the channel to signal that that metric
  could not be collected. It alse transports an error.

NON-GOALS OF THIS COMMIT:

This is NOT yet the major improvement of the whole registry part,
where we want a public Registry interface and plenty of modular
configurations (for error handling, various auto-metrics, http
instrumentation, testing, ...). However, we can do that whole thing
without breaking existing interfaces. For now (which is a significant
issue) any error during collection will either cause a 500 HTTP
response or a panic (depending on registry config). Later, we
definitely want to have a possibility to skip (and only report
somehow) non-collectible metrics instead of aborting the whole scrape.
2015-01-12 19:16:09 +01:00
..
.gitignore Rearrange file and package per convention. 2013-04-04 15:27:09 +02:00
README.md Complete rewrite of the exposition library. 2014-06-17 14:08:22 +02:00
benchmark_test.go Complete rewrite of the exposition library. 2014-06-17 14:08:22 +02:00
collector.go Allow error reporting during metrics collection and simplify Register(). 2015-01-12 19:16:09 +01:00
counter.go Added "callback" metrics, e.g. GaugeFunc. 2014-06-23 14:35:01 +02:00
counter_test.go Complete rewrite of the exposition library. 2014-06-17 14:08:22 +02:00
desc.go Allow error reporting during metrics collection and simplify Register(). 2015-01-12 19:16:09 +01:00
doc.go Complete rewrite of the exposition library. 2014-06-17 14:08:22 +02:00
example_clustermanager_test.go Complete rewrite of the exposition library. 2014-06-17 14:08:22 +02:00
example_memstats_test.go Complete rewrite of the exposition library. 2014-06-17 14:08:22 +02:00
example_selfcollector_test.go Allow error reporting during metrics collection and simplify Register(). 2015-01-12 19:16:09 +01:00
examples_test.go Allow error reporting during metrics collection and simplify Register(). 2015-01-12 19:16:09 +01:00
expvar.go Allow error reporting during metrics collection and simplify Register(). 2015-01-12 19:16:09 +01:00
expvar_test.go Complete rewrite of the exposition library. 2014-06-17 14:08:22 +02:00
gauge.go Added "callback" metrics, e.g. GaugeFunc. 2014-06-23 14:35:01 +02:00
gauge_test.go Added "callback" metrics, e.g. GaugeFunc. 2014-06-23 14:35:01 +02:00
go_collector.go Add ProcessCollector and GoCollector 2014-12-22 13:49:45 -05:00
go_collector_test.go Allow error reporting during metrics collection and simplify Register(). 2015-01-12 19:16:09 +01:00
http.go Fix a race condition in the http instrumentation. 2014-10-08 19:01:24 +02:00
http_test.go Add a configurable version of InstrumentHandler and InstrumentHandlerFunc. 2014-07-22 17:40:20 +02:00
metric.go Allow error reporting during metrics collection and simplify Register(). 2015-01-12 19:16:09 +01:00
metric_test.go Complete rewrite of the exposition library. 2014-06-17 14:08:22 +02:00
process_collector.go Allow error reporting during metrics collection and simplify Register(). 2015-01-12 19:16:09 +01:00
process_collector_test.go Add ProcessCollector and GoCollector 2014-12-22 13:49:45 -05:00
registry.go Allow error reporting during metrics collection and simplify Register(). 2015-01-12 19:16:09 +01:00
registry_test.go Add a configurable version of InstrumentHandler and InstrumentHandlerFunc. 2014-07-22 17:40:20 +02:00
summary.go Allow error reporting during metrics collection and simplify Register(). 2015-01-12 19:16:09 +01:00
summary_test.go Disable the timing-sensitive test TestSummaryDecay for now. 2014-12-18 18:05:06 +01:00
untyped.go Added "callback" metrics, e.g. GaugeFunc. 2014-06-23 14:35:01 +02:00
value.go Allow error reporting during metrics collection and simplify Register(). 2015-01-12 19:16:09 +01:00
vec.go Fix typo in doc comment. 2014-09-19 13:20:59 +02:00
vec_test.go Complete rewrite of the exposition library. 2014-06-17 14:08:22 +02: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