VictoriaMetrics/vendor/github.com/VictoriaMetrics/metrics
2019-10-06 11:20:03 +03:00
..
counter.go vendor: update github.com/VictoriaMetrics/metrics from v1.7.1 to v1.7.2 2019-10-06 11:20:03 +03:00
gauge.go vendor: update github.com/VictoriaMetrics/metrics from v1.7.1 to v1.7.2 2019-10-06 11:20:03 +03:00
go.mod vendor: update github.com/VictoriaMetrics/metrics to v1.6.2 2019-06-28 14:18:24 +03:00
go.sum all: open-sourcing single-node version 2019-05-23 00:18:06 +03:00
go_metrics.go vendor: update github.com/VictoriaMetrics/metrics to v1.7.0 2019-07-12 17:24:58 +03:00
LICENSE all: open-sourcing single-node version 2019-05-23 00:18:06 +03:00
metrics.go vendor: update github.com/VictoriaMetrics/metrics to v1.7.0 2019-07-12 17:24:58 +03:00
process_metrics_linux.go vendor: update github.com/VictoriaMetrics/metrics to v1.7.1 2019-08-05 19:21:53 +03:00
process_metrics_other.go vendor: update github.com/VictoriaMetrics/metrics to v1.7.0 2019-07-12 17:24:58 +03:00
README.md vendor: update github.com/VictoriaMetrics/metrics from v1.7.1 to v1.7.2 2019-10-06 11:20:03 +03:00
set.go vendor: update github.com/VictoriaMetrics/metrics from v1.7.1 to v1.7.2 2019-10-06 11:20:03 +03:00
summary.go vendor: update github.com/VictoriaMetrics/metrics from v1.7.1 to v1.7.2 2019-10-06 11:20:03 +03:00
validator.go all: open-sourcing single-node version 2019-05-23 00:18:06 +03:00

Build Status GoDoc Go Report codecov

metrics - lightweight package for exporting metrics in Prometheus format

Features

  • Lightweight. Has minimal number of third-party dependencies and all these deps are small. See this article for details.
  • Easy to use. See the API docs.
  • Fast.
  • Allows exporting distinct metric sets via distinct endpoints. See Set.

Limitations

Usage

import "github.com/VictoriaMetrics/metrics"

// Register various time series.
// Time series name may contain labels in Prometheus format - see below.
var (
	// Register counter without labels.
	requestsTotal = metrics.NewCounter("requests_total")

	// Register summary with a single label.
	requestDuration = metrics.NewSummary(`requests_duration_seconds{path="/foobar/baz"}`)

	// Register gauge with two labels.
	queueSize = metrics.NewGauge(`queue_size{queue="foobar",topic="baz"}`, func() float64 {
		return float64(foobarQueue.Len())
	})
)

// ...
func requestHandler() {
	// Increment requestTotal counter.
	requestsTotal.Inc()

	startTime := time.Now()
	processRequest()
	// Update requestDuration summary.
	requestDuration.UpdateDuration(startTime)
}

// Expose the registered metrics at `/metrics` path.
http.HandleFunc("/metrics", func(w http.ResponseWriter, req *http.Request) {
	metrics.WritePrometheus(w, true)
})

See docs for more info.

Users

FAQ

Why the metrics API isn't compatible with github.com/prometheus/client_golang?

Because the github.com/prometheus/client_golang is too complex and is hard to use.

Why the metrics.WritePrometheus doesn't expose documentation for each metric?

Because this documentation is ignored by Prometheus. The documentation is for users. Just add comments in the source code or in other suitable place explaining each metric exposed from your application.

How to implement CounterVec in metrics?

Just use GetOrCreateCounter instead of CounterVec.With. See this example for details.