Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Lightweight alternative to github.com/prometheus/client_golang

License

NotificationsYou must be signed in to change notification settings

VictoriaMetrics/metrics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build StatusGoDocGo Reportcodecov

metrics - lightweight package for exporting metrics in Prometheus format

Features

Limitations

Usage

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.

Users

FAQ

Why themetrics API isn't compatible withgithub.com/prometheus/client_golang?

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

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

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_bucketsfunction, 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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp