forked from juliusv/prometheus_demo_service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
disk.go
47 lines (40 loc) · 893 Bytes
/
disk.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
package main
import (
"math/rand"
"time"
"github.com/prometheus/client_golang/prometheus"
)
var (
diskUsage = prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: "disk",
Name: "usage_bytes",
Help: "Disk usage in bytes.",
},
)
diskTotal = prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: "disk",
Name: "total_bytes",
Help: "Total disk space in bytes.",
},
)
)
func init() {
prometheus.MustRegister(diskUsage)
prometheus.MustRegister(diskTotal)
}
func runDiskSim(total int64, inc int64) {
diskTotal.Set(float64(total))
usage := int64(0.1 * float64(total))
for {
usage += int64(float64(inc) * (1 - (rand.Float64() - 0.5)))
if float64(usage) > 0.9*float64(total) {
usage = int64(0.1 * float64(total))
}
diskUsage.Set(float64(usage))
time.Sleep(time.Second)
}
}