Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/pkg/config/instrumentation/remote_config_metrics.go
4096 views
1
package instrumentation
2
3
import (
4
"fmt"
5
"sync"
6
7
"github.com/prometheus/client_golang/prometheus"
8
"github.com/prometheus/client_golang/prometheus/promauto"
9
)
10
11
type remoteConfigMetrics struct {
12
fetchStatusCodes *prometheus.CounterVec
13
fetchErrors prometheus.Counter
14
invalidConfigFetch *prometheus.CounterVec
15
}
16
17
var remoteConfMetrics *remoteConfigMetrics
18
var remoteConfMetricsInitializer sync.Once
19
20
func initializeRemoteConfigMetrics() {
21
remoteConfMetrics = newRemoteConfigMetrics()
22
}
23
24
func newRemoteConfigMetrics() *remoteConfigMetrics {
25
var remoteConfigMetrics remoteConfigMetrics
26
27
remoteConfigMetrics.fetchStatusCodes = promauto.NewCounterVec(
28
prometheus.CounterOpts{
29
Name: "agent_remote_config_fetches_total",
30
Help: "Number of fetch requests for the remote config by HTTP status code",
31
},
32
[]string{"status_code"},
33
)
34
remoteConfigMetrics.fetchErrors = promauto.NewCounter(
35
prometheus.CounterOpts{
36
Name: "agent_remote_config_fetch_errors_total",
37
Help: "Number of errors attempting to fetch remote config",
38
},
39
)
40
41
remoteConfigMetrics.invalidConfigFetch = promauto.NewCounterVec(
42
prometheus.CounterOpts{
43
Name: "agent_remote_config_invalid_total",
44
Help: "Number of validation errors by reason (i.e. invalid yaml or an invalid agent config)",
45
},
46
[]string{"reason"},
47
)
48
49
return &remoteConfigMetrics
50
}
51
52
func InstrumentRemoteConfigFetch(statusCode int) {
53
remoteConfMetricsInitializer.Do(initializeRemoteConfigMetrics)
54
remoteConfMetrics.fetchStatusCodes.WithLabelValues(fmt.Sprintf("%d", statusCode)).Inc()
55
}
56
57
func InstrumentRemoteConfigFetchError() {
58
remoteConfMetricsInitializer.Do(initializeRemoteConfigMetrics)
59
remoteConfMetrics.fetchErrors.Inc()
60
}
61
62
func InstrumentInvalidRemoteConfig(reason string) {
63
remoteConfMetricsInitializer.Do(initializeRemoteConfigMetrics)
64
remoteConfMetrics.invalidConfigFetch.WithLabelValues(reason).Inc()
65
}
66
67