-
Notifications
You must be signed in to change notification settings - Fork 66
/
set_example_test.go
78 lines (66 loc) · 2.05 KB
/
set_example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package metrics_test
import (
"bytes"
"fmt"
"github.com/VictoriaMetrics/metrics"
)
func ExampleSet() {
// Create a set with a counter
s := metrics.NewSet()
sc := s.NewCounter("set_counter")
sc.Inc()
s.NewGauge(`set_gauge{foo="bar"}`, func() float64 { return 42 })
// Dump metrics from s.
var bb bytes.Buffer
s.WritePrometheus(&bb)
fmt.Printf("set metrics:\n%s\n", bb.String())
// Output:
// set metrics:
// set_counter 1
// set_gauge{foo="bar"} 42
}
func ExampleExposeMetadata() {
metrics.ExposeMetadata(true)
defer metrics.ExposeMetadata(false)
s := metrics.NewSet()
sc := s.NewCounter("set_counter")
sc.Inc()
s.NewGauge(`unused_bytes{foo="bar"}`, func() float64 { return 58 })
s.NewGauge(`used_bytes{foo="bar"}`, func() float64 { return 42 })
s.NewGauge(`used_bytes{foo="baz"}`, func() float64 { return 43 })
h := s.NewHistogram(`request_duration_seconds{path="/foo/bar"}`)
h.Update(1)
h.Update(2)
s.NewSummary("response_size_bytes").Update(1)
// Dump metrics from s.
var bb bytes.Buffer
s.WritePrometheus(&bb)
fmt.Printf("set metrics:\n%s\n", bb.String())
// Output:
// set metrics:
// # HELP request_duration_seconds
// # TYPE request_duration_seconds histogram
// request_duration_seconds_bucket{path="/foo/bar",vmrange="8.799e-01...1.000e+00"} 1
// request_duration_seconds_bucket{path="/foo/bar",vmrange="1.896e+00...2.154e+00"} 1
// request_duration_seconds_sum{path="/foo/bar"} 3
// request_duration_seconds_count{path="/foo/bar"} 2
// # HELP response_size_bytes
// # TYPE response_size_bytes summary
// response_size_bytes_sum 1
// response_size_bytes_count 1
// response_size_bytes{quantile="0.5"} 1
// response_size_bytes{quantile="0.9"} 1
// response_size_bytes{quantile="0.97"} 1
// response_size_bytes{quantile="0.99"} 1
// response_size_bytes{quantile="1"} 1
// # HELP set_counter
// # TYPE set_counter counter
// set_counter 1
// # HELP unused_bytes
// # TYPE unused_bytes gauge
// unused_bytes{foo="bar"} 58
// # HELP used_bytes
// # TYPE used_bytes gauge
// used_bytes{foo="bar"} 42
// used_bytes{foo="baz"} 43
}