forked from c4po/harbor_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics_health.go
40 lines (33 loc) · 953 Bytes
/
metrics_health.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) collectHealthMetric(ch chan<- prometheus.Metric) bool {
start := time.Now()
type scanMetric struct {
Status string `json:"status"`
Components []struct {
Name string `json:"name"`
Status string `json:"status"`
}
}
body, _ := h.request("/health")
var data scanMetric
if err := json.Unmarshal(body, &data); err != nil {
level.Error(h.logger).Log(err.Error())
return false
}
ch <- prometheus.MustNewConstMetric(
allMetrics["health"].Desc, allMetrics["health"].Type, float64(Status2i(data.Status)),
)
for _, c := range data.Components {
ch <- prometheus.MustNewConstMetric(
allMetrics["components_health"].Desc, allMetrics["components_health"].Type, float64(Status2i(c.Status)), c.Name,
)
}
reportLatency(start, "health_latency", ch)
return true
}