-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
49 lines (42 loc) · 1.28 KB
/
main.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
package main
import (
"flag"
"fmt"
"math"
"math/rand"
"net/http"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var (
numTimeseries = flag.Int("timeseries", 10000, "The number of timeseries to return.")
metric = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "example_timeseries_total",
Help: "Timeseries being exposed",
},
[]string{"label"},
)
)
type collector struct {
}
func randFloat() float64 {
// Simulate nanosecond precision latency around 1s.
r := rand.NormFloat64() + 1
r *= 1e9
return math.Round(r) / 1e9
}
func (collector) Describe(ch chan<- *prometheus.Desc) {
metric.Describe(ch)
}
func (collector) Collect(ch chan<- prometheus.Metric) {
for i := 0; i < *numTimeseries; i++ {
metric.WithLabelValues(fmt.Sprintf("labelabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij%d", i)).Add(math.Max(0, randFloat()))
}
metric.Collect(ch)
}
func main() {
prometheus.MustRegister(collector{})
flag.Parse()
http.Handle("/metrics", promhttp.Handler())
http.ListenAndServe(":1234", nil)
}