-
Notifications
You must be signed in to change notification settings - Fork 51
/
metrics_systemvolumes.go
40 lines (34 loc) · 1 KB
/
metrics_systemvolumes.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
package main
import (
"encoding/json"
"time"
"github.com/go-kit/kit/log/level"
"github.com/prometheus/client_golang/prometheus"
)
func (h *HarborExporter) collectSystemVolumesMetric(ch chan<- prometheus.Metric) bool {
start := time.Now()
type systemVolumesMetric struct {
Storage []struct {
Total float64
Free float64
}
}
body, _ := h.request("/systeminfo/volumes")
var data systemVolumesMetric
if err := json.Unmarshal(body, &data); err != nil {
level.Error(h.logger).Log(err.Error())
return false
}
if len(data.Storage) < 1 {
level.Error(h.logger).Log("msg", "Error retrieving system volumes")
return false
}
ch <- prometheus.MustNewConstMetric(
allMetrics["system_volumes_bytes"].Desc, allMetrics["system_volumes_bytes"].Type, data.Storage[0].Total, "total",
)
ch <- prometheus.MustNewConstMetric(
allMetrics["system_volumes_bytes"].Desc, allMetrics["system_volumes_bytes"].Type, data.Storage[0].Free, "free",
)
reportLatency(start, "system_volumes_latency", ch)
return true
}