"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors"
"github.com/prometheus/client_golang/prometheus/promhttp"
var rpcDurations = prometheus.NewSummaryVec(
Name: "rpc_durations_seconds",
Help: "RPC latency distributions.",
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
reg := prometheus.NewRegistry()
reg.MustRegister(collectors.NewBuildInfoCollector())
collectors.NewGoCollector(),
collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}),
reg.MustRegister(rpcDurations)
oscillationFactor := func() float64 {
return 2 + math.Sin(math.Sin(2*math.Pi*float64(time.Since(start))/float64(10*time.Minute)))
v := rand.Float64() * 0.0002
rpcDurations.WithLabelValues("uniform").Observe(v)
time.Sleep(time.Duration(100*oscillationFactor()) * time.Millisecond)
v := (rand.NormFloat64() * 0.0002) + 0.00001
rpcDurations.WithLabelValues("normal").Observe(v)
time.Sleep(time.Duration(75*oscillationFactor()) * time.Millisecond)
v := rand.ExpFloat64() / 1e6
rpcDurations.WithLabelValues("exponential").Observe(v)
time.Sleep(time.Duration(50*oscillationFactor()) * time.Millisecond)
http.Handle("/metrics", promhttp.HandlerFor(
reg, promhttp.HandlerOpts{},
http.ListenAndServe(":2023", nil)