Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example for synchronous gauge #5492

Merged
merged 12 commits into from
Jun 24, 2024
18 changes: 18 additions & 0 deletions metric/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,24 @@ func ExampleMeter_upDownCounter() {
}
}

// Gauges can be used to record non-additive values when changes occur.
//
// Here's how you might report the current speed of a cpu fan.
func ExampleMeter_gauge() {
speedGauge, err := meter.Int64Gauge(
"cpu.fan.speed",
metric.WithDescription("Speed of CPU fan"),
metric.WithUnit("RPM"),
)
if err != nil {
panic(err)
}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
// hard-code 1500 RPM for demonstrative purposes
speedGauge.Record(r.Context(), 1500)
})
MrAlias marked this conversation as resolved.
Show resolved Hide resolved
}

// Histograms are used to measure a distribution of values over time.
//
// Here's how you might report a distribution of response times for an HTTP handler.
Expand Down
Loading