-
Notifications
You must be signed in to change notification settings - Fork 51
/
metrics_statistics.go
58 lines (44 loc) · 1.8 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
55
56
57
58
package main
import (
"encoding/json"
"time"
"github.com/go-kit/kit/log/level"
"github.com/prometheus/client_golang/prometheus"
)
func (h *HarborExporter) collectStatisticsMetric(ch chan<- prometheus.Metric) bool {
start := time.Now()
type statisticsMetric struct {
TotalProjectCount float64 `json:"total_project_count"`
PublicProjectCount float64 `json:"public_project_count"`
PrivateProjectCount float64 `json:"private_project_count"`
PublicRepoCount float64 `json:"public_repo_count"`
TotalRepoCount float64 `json:"total_repo_count"`
PrivateRepoCount float64 `json:"private_repo_count"`
}
body, _ := h.request("/statistics")
var data statisticsMetric
if err := json.Unmarshal(body, &data); err != nil {
level.Error(h.logger).Log(err.Error())
return false
}
ch <- prometheus.MustNewConstMetric(
allMetrics["project_count_total"].Desc, allMetrics["project_count_total"].Type, data.TotalProjectCount, "total_project",
)
ch <- prometheus.MustNewConstMetric(
allMetrics["project_count_total"].Desc, allMetrics["project_count_total"].Type, data.PublicProjectCount, "public_project",
)
ch <- prometheus.MustNewConstMetric(
allMetrics["project_count_total"].Desc, allMetrics["project_count_total"].Type, data.PrivateProjectCount, "private_project",
)
ch <- prometheus.MustNewConstMetric(
allMetrics["repo_count_total"].Desc, allMetrics["repo_count_total"].Type, data.PublicRepoCount, "public_repo",
)
ch <- prometheus.MustNewConstMetric(
allMetrics["repo_count_total"].Desc, allMetrics["repo_count_total"].Type, data.TotalRepoCount, "total_repo",
)
ch <- prometheus.MustNewConstMetric(
allMetrics["repo_count_total"].Desc, allMetrics["repo_count_total"].Type, data.PrivateRepoCount, "private_repo",
)
reportLatency(start, "statistics_latency", ch)
return true
}