- Notifications
You must be signed in to change notification settings - Fork67
Lightweight alternative to github.com/prometheus/client_golang
License
VictoriaMetrics/metrics
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
- Lightweight. Has minimal number of third-party dependencies and all these deps are small.Seethis article for details.
- Easy to use. See theAPI docs.
- Fast.
- Allows exporting distinct metric sets via distinct endpoints. SeeSet.
- Supportseasy-to-use histograms, which just work without any tuning.Read more about VictoriaMetrics histograms atthis article.
- Can push metrics to VictoriaMetrics or to any other remote storage, which accepts metricsinPrometheus text exposition format.Seethese docs.
- It doesn't implement advanced functionality fromgithub.com/prometheus/client_golang.
import"github.com/VictoriaMetrics/metrics"// Register various metrics.// Metric 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 {returnfloat64(foobarQueue.Len())})// Register histogram with a single label.responseSize=metrics.NewHistogram(`response_size{path="/foo/bar"}`))// ...funcrequestHandler() {// Increment requestTotal counter.requestsTotal.Inc()startTime:=time.Now()processRequest()// Update requestDuration summary.requestDuration.UpdateDuration(startTime)// Update responseSize histogram.responseSize.Update(responseSize)}// Expose the registered metrics at `/metrics` path.http.HandleFunc("/metrics",func(w http.ResponseWriter,req*http.Request) {metrics.WritePrometheus(w,true)})// ... or push registered metrics every 10 seconds to http://victoria-metrics:8428/api/v1/import/prometheus// with the added `instance="foobar"` label to all the pushed metrics.metrics.InitPush("http://victoria-metrics:8428/api/v1/import/prometheus",10*time.Second,`instance="foobar"`,true)
By default, exposed metricsdo not haveTYPE
orHELP
meta information. CallExposeMetadata(true)
in order to generateTYPE
andHELP
meta information per each metric.
Seedocs for more info.
Metrics
has been extracted fromVictoriaMetrics sources.Seethis articlefor more info aboutVictoriaMetrics
.
Because thegithub.com/prometheus/client_golang
is too complex and is hard to use.
Because this documentation is ignored by Prometheus. The documentation is for users.Just givemeaningful names to the exported metricsor add comments in the source code or in other suitable place explaining each metric exposed from your application.
How to implementCounterVec inmetrics
?
Just useGetOrCreateCounterinstead ofCounterVec.With
. Seethis example for details.
WhyHistogram buckets containvmrange
labels instead ofle
labels like in Prometheus histograms?
Buckets withvmrange
labels occupy less disk space compared to Promethes-style buckets withle
labels,becausevmrange
buckets don't include counters for the previous ranges.VictoriaMetrics providesprometheus_buckets
function, which convertsvmrange
buckets to Prometheus-style buckets withle
labels. This is useful for building heatmaps in Grafana.Additionally, its'histogram_quantile
function transparently handles histogram buckets withvmrange
labels.
About
Lightweight alternative to github.com/prometheus/client_golang