Path: blob/main/pkg/config/instrumentation/remote_config_metrics.go
4096 views
package instrumentation12import (3"fmt"4"sync"56"github.com/prometheus/client_golang/prometheus"7"github.com/prometheus/client_golang/prometheus/promauto"8)910type remoteConfigMetrics struct {11fetchStatusCodes *prometheus.CounterVec12fetchErrors prometheus.Counter13invalidConfigFetch *prometheus.CounterVec14}1516var remoteConfMetrics *remoteConfigMetrics17var remoteConfMetricsInitializer sync.Once1819func initializeRemoteConfigMetrics() {20remoteConfMetrics = newRemoteConfigMetrics()21}2223func newRemoteConfigMetrics() *remoteConfigMetrics {24var remoteConfigMetrics remoteConfigMetrics2526remoteConfigMetrics.fetchStatusCodes = promauto.NewCounterVec(27prometheus.CounterOpts{28Name: "agent_remote_config_fetches_total",29Help: "Number of fetch requests for the remote config by HTTP status code",30},31[]string{"status_code"},32)33remoteConfigMetrics.fetchErrors = promauto.NewCounter(34prometheus.CounterOpts{35Name: "agent_remote_config_fetch_errors_total",36Help: "Number of errors attempting to fetch remote config",37},38)3940remoteConfigMetrics.invalidConfigFetch = promauto.NewCounterVec(41prometheus.CounterOpts{42Name: "agent_remote_config_invalid_total",43Help: "Number of validation errors by reason (i.e. invalid yaml or an invalid agent config)",44},45[]string{"reason"},46)4748return &remoteConfigMetrics49}5051func InstrumentRemoteConfigFetch(statusCode int) {52remoteConfMetricsInitializer.Do(initializeRemoteConfigMetrics)53remoteConfMetrics.fetchStatusCodes.WithLabelValues(fmt.Sprintf("%d", statusCode)).Inc()54}5556func InstrumentRemoteConfigFetchError() {57remoteConfMetricsInitializer.Do(initializeRemoteConfigMetrics)58remoteConfMetrics.fetchErrors.Inc()59}6061func InstrumentInvalidRemoteConfig(reason string) {62remoteConfMetricsInitializer.Do(initializeRemoteConfigMetrics)63remoteConfMetrics.invalidConfigFetch.WithLabelValues(reason).Inc()64}656667