forked from c4po/harbor_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics_statistics.go
54 lines (41 loc) · 1.58 KB
/
metrics_statistics.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
package main
import (
"encoding/json"
"github.com/go-kit/kit/log/level"
"github.com/prometheus/client_golang/prometheus"
)
func (e *HarborExporter) collectStatisticsMetric(ch chan<- prometheus.Metric) bool {
type statisticsMetric struct {
Total_project_count float64
Public_project_count float64
Private_project_count float64
Public_repo_count float64
Total_repo_count float64
Private_repo_count float64
}
body, _ := e.request("/statistics")
var data statisticsMetric
if err := json.Unmarshal(body, &data); err != nil {
level.Error(e.logger).Log(err.Error())
return false
}
ch <- prometheus.MustNewConstMetric(
allMetrics["project_count_total"].Desc, allMetrics["project_count_total"].Type, data.Total_project_count, "total_project",
)
ch <- prometheus.MustNewConstMetric(
allMetrics["project_count_total"].Desc, allMetrics["project_count_total"].Type, data.Public_project_count, "public_project",
)
ch <- prometheus.MustNewConstMetric(
allMetrics["project_count_total"].Desc, allMetrics["project_count_total"].Type, data.Private_project_count, "private_project",
)
ch <- prometheus.MustNewConstMetric(
allMetrics["repo_count_total"].Desc, allMetrics["repo_count_total"].Type, data.Public_repo_count, "public_repo",
)
ch <- prometheus.MustNewConstMetric(
allMetrics["repo_count_total"].Desc, allMetrics["repo_count_total"].Type, data.Total_repo_count, "total_repo",
)
ch <- prometheus.MustNewConstMetric(
allMetrics["repo_count_total"].Desc, allMetrics["repo_count_total"].Type, data.Private_repo_count, "private_repo",
)
return true
}