forked from webdevops/azure-devops-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics_project.go
57 lines (45 loc) · 1.42 KB
/
metrics_project.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
package main
import (
"context"
"github.com/prometheus/client_golang/prometheus"
"github.com/webdevops/go-common/prometheus/collector"
"go.uber.org/zap"
devopsClient "github.com/webdevops/azure-devops-exporter/azure-devops-client"
)
type MetricsCollectorProject struct {
collector.Processor
prometheus struct {
project *prometheus.GaugeVec
repository *prometheus.GaugeVec
}
}
func (m *MetricsCollectorProject) Setup(collector *collector.Collector) {
m.Processor.Setup(collector)
m.prometheus.project = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "azure_devops_project_info",
Help: "Azure DevOps project",
},
[]string{
"projectID",
"projectName",
},
)
m.Collector.RegisterMetricList("project", m.prometheus.project, true)
}
func (m *MetricsCollectorProject) Reset() {}
func (m *MetricsCollectorProject) Collect(callback chan<- func()) {
ctx := m.Context()
logger := m.Logger()
for _, project := range AzureDevopsServiceDiscovery.ProjectList() {
projectLogger := logger.With(zap.String("project", project.Name))
m.collectProject(ctx, projectLogger, callback, project)
}
}
func (m *MetricsCollectorProject) collectProject(ctx context.Context, logger *zap.SugaredLogger, callback chan<- func(), project devopsClient.Project) {
projectMetric := m.Collector.GetMetricList("project")
projectMetric.AddInfo(prometheus.Labels{
"projectID": project.Id,
"projectName": project.Name,
})
}