2019-06-01 23:18:41 +03:00
|
|
|
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.
|
2019-06-01 23:24:25 +03:00
|
|
|
var bb bytes.Buffer
|
2019-06-01 23:18:41 +03:00
|
|
|
s.WritePrometheus(&bb)
|
|
|
|
fmt.Printf("set metrics:\n%s\n", bb.String())
|
|
|
|
|
|
|
|
// Output:
|
|
|
|
// set metrics:
|
|
|
|
// set_counter 1
|
|
|
|
// set_gauge{foo="bar"} 42
|
|
|
|
}
|