forked from webdevops/azure-resourcemanager-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics_exporter.go
61 lines (50 loc) · 1.42 KB
/
metrics_exporter.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
package main
import (
"context"
"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
prometheusCommon "github.com/webdevops/go-prometheus-common"
)
type MetricsCollectorExporter struct {
CollectorProcessorCustom
prometheus struct {
stats *prometheus.GaugeVec
}
}
func (m *MetricsCollectorExporter) Setup(collector *CollectorCustom) {
m.CollectorReference = collector
m.prometheus.stats = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "azurerm_stats",
Help: "Azure ResourceManager stats",
},
[]string{
"name",
"type",
},
)
prometheus.MustRegister(m.prometheus.stats)
}
func (m *MetricsCollectorExporter) Collect(ctx context.Context, logger *log.Entry) {
m.collectCollectorStats(ctx, logger)
}
func (m *MetricsCollectorExporter) collectCollectorStats(ctx context.Context, logger *log.Entry) {
statsMetrics := prometheusCommon.NewMetricsList()
for _, collector := range collectorGeneralList {
if collector.LastScrapeDuration != nil {
statsMetrics.AddDuration(prometheus.Labels{
"name": collector.Name,
"type": "collectorDuration",
}, *collector.LastScrapeDuration)
}
}
for _, collector := range collectorCustomList {
if collector.LastScrapeDuration != nil {
statsMetrics.AddDuration(prometheus.Labels{
"name": collector.Name,
"type": "collectorDuration",
}, *collector.LastScrapeDuration)
}
}
statsMetrics.GaugeSet(m.prometheus.stats)
}