...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package metric_test
16
17 import (
18 "net/http"
19
20 "go.opencensus.io/metric"
21 "go.opencensus.io/metric/metricdata"
22 )
23
24 func ExampleRegistry_AddInt64Gauge() {
25 r := metric.NewRegistry()
26
27
28 g, _ := r.AddInt64Gauge("active_request",
29 metric.WithDescription("Number of active requests, per method."),
30 metric.WithUnit(metricdata.UnitDimensionless),
31 metric.WithLabelKeys("method"))
32
33 http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
34 e, _ := g.GetEntry(metricdata.NewLabelValue(request.Method))
35 e.Add(1)
36 defer e.Add(-1)
37
38 })
39 }
40
View as plain text