forked from c4po/harbor_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics_scan.go
40 lines (33 loc) · 1015 Bytes
/
metrics_scan.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"
"github.com/go-kit/kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"strconv"
)
func (e *HarborExporter) collectScanMetric(ch chan<- prometheus.Metric) bool {
type scanMetric struct {
Total float64
Completed float64
metrics []interface{}
Requester string
Ongoing bool
}
body, _ := e.request("/scans/all/metrics")
var data scanMetric
if err := json.Unmarshal(body, &data); err != nil {
level.Error(e.logger).Log(err.Error())
return false
}
scan_requester, _ := strconv.ParseFloat(data.Requester, 64)
ch <- prometheus.MustNewConstMetric(
allMetrics["scans_requester"].Desc, allMetrics["scans_requester"].Type, float64(scan_requester),
)
ch <- prometheus.MustNewConstMetric(
allMetrics["scans_total"].Desc, allMetrics["scans_total"].Type, float64(data.Total),
)
ch <- prometheus.MustNewConstMetric(
allMetrics["scans_completed"].Desc, allMetrics["scans_completed"].Type, float64(data.Completed),
)
return true
}