forked from webdevops/azure-devops-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics_general.go
92 lines (76 loc) · 2.2 KB
/
metrics_general.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"context"
"github.com/prometheus/client_golang/prometheus"
)
type MetricsCollectorGeneral struct {
CollectorProcessorGeneral
prometheus struct {
stats *prometheus.GaugeVec
}
}
func (m *MetricsCollectorGeneral) Setup(collector *CollectorGeneral) {
m.CollectorReference = collector
m.prometheus.stats = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "azure_devops_stats",
Help: "Azure DevOps statistics",
},
[]string{
"name",
"type",
},
)
prometheus.MustRegister(m.prometheus.stats)
}
func (m *MetricsCollectorGeneral) Reset() {
m.prometheus.stats.Reset()
}
func (m *MetricsCollectorGeneral) Collect(ctx context.Context, callback chan<- func()) {
m.collectAzureDevopsClientStats(ctx, callback)
m.collectCollectorStats(ctx, callback)
}
func (m *MetricsCollectorGeneral) collectAzureDevopsClientStats(ctx context.Context, callback chan<- func()) {
statsMetrics := NewMetricCollectorList()
statsMetrics.Add(prometheus.Labels{
"name": "dev.azure.com",
"type": "requests",
}, AzureDevopsClient.GetRequestCount())
statsMetrics.Add(prometheus.Labels{
"name": "dev.azure.com",
"type": "concurrency",
}, AzureDevopsClient.GetCurrentConcurrency())
callback <- func() {
statsMetrics.GaugeSet(m.prometheus.stats)
}
}
func (m *MetricsCollectorGeneral) collectCollectorStats(ctx context.Context, callback chan<- func()) {
statsMetrics := NewMetricCollectorList()
for _, collector := range collectorGeneralList {
if collector.LastScrapeDuration != nil {
statsMetrics.AddDuration(prometheus.Labels{
"name": collector.Name,
"type": "collectorDuration",
}, *collector.LastScrapeDuration)
}
}
for _, collector := range collectorAgentPoolList {
if collector.LastScrapeDuration != nil {
statsMetrics.AddDuration(prometheus.Labels{
"name": collector.Name,
"type": "collectorDuration",
}, *collector.LastScrapeDuration)
}
}
for _, collector := range collectorProjectList {
if collector.LastScrapeDuration != nil {
statsMetrics.AddDuration(prometheus.Labels{
"name": collector.Name,
"type": "collectorDuration",
}, *collector.LastScrapeDuration)
}
}
callback <- func() {
statsMetrics.GaugeSet(m.prometheus.stats)
}
}