-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
70 lines (57 loc) · 1.82 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"log"
"math/rand"
"net/http"
"os"
"time"
"github.com/alecthomas/kong"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
type CLI struct {
Teams []string `help:"All of the teams to emit metrics for" env:"TEAMS"`
MaxSize uint `help:"The largest that the metric can grow" default:"100000"`
MaxIncrease int `help:"The highest that the metric can be increased by" default:"10000"`
MinIncrease int `help:"The lowest that the metric can be increased by" default:"5000"`
Interval time.Duration `help:"The interval at which the metric increases" default:"5s"`
ServerName string `help:"The name of the server" optional:""`
}
var (
teamVals map[string]uint64 = map[string]uint64{}
processMemoryConsumptionGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "process_memory_total_bytes",
Help: "The total amount of memory being used by this process",
}, []string{"server", "team"})
)
func recordMetrics(cli *CLI) {
for {
for _, team := range cli.Teams {
toIncrease := rand.Intn(cli.MaxIncrease-cli.MinIncrease) + cli.MinIncrease
if teamVals[team]+uint64(toIncrease) > uint64(cli.MaxSize) {
teamVals[team] = 0
}
teamVals[team] += uint64(toIncrease)
processMemoryConsumptionGauge.WithLabelValues(cli.ServerName, team).Set(float64(teamVals[team]))
}
time.Sleep(cli.Interval)
}
}
func main() {
cli := CLI{}
_ = kong.Parse(&cli)
if cli.ServerName == "" {
name, err := os.Hostname()
if err != nil {
log.Fatalln(err)
}
cli.ServerName = name
}
for _, team := range cli.Teams {
teamVals[team] = 0
}
go recordMetrics(&cli)
http.Handle("/metrics", promhttp.Handler())
http.ListenAndServe(":23456", nil)
}