-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics_collector.go
50 lines (40 loc) · 1.17 KB
/
metrics_collector.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
package main
import (
"context"
"time"
"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
prometheusCommon "github.com/webdevops/go-prometheus-common"
)
type (
MetricsCollectorCollector struct {
CollectorProcessorGeneral
}
AppreleaseVersion struct {
Tag string
Version string
CreatedAt *time.Time
}
)
func (m *MetricsCollectorCollector) Setup(collector *CollectorGeneral) {
m.CollectorReference = collector
}
func (m *MetricsCollectorCollector) Reset() {
}
func (m *MetricsCollectorCollector) Collect(ctx context.Context, logger *log.Entry, callback chan<- func()) {
m.collectCollectorStats(ctx, logger, callback)
}
func (m *MetricsCollectorCollector) collectCollectorStats(ctx context.Context, logger *log.Entry, callback chan<- func()) {
statsMetrics := prometheusCommon.NewMetricsList()
for _, collector := range collectorList {
if collector.LastScrapeDuration != nil {
statsMetrics.AddDuration(prometheus.Labels{
"name": collector.Name,
"type": "collectorDuration",
}, *collector.LastScrapeDuration)
}
}
callback <- func() {
statsMetrics.GaugeSet(m.CollectorReference.PrometheusStatsGauge())
}
}