Path: blob/main/pkg/integrations/statsd_exporter/metrics.go
5371 views
package statsd_exporter //nolint:golint12import "github.com/prometheus/client_golang/prometheus"34// Metrics holds metrics used by the statsd_exporter integration. These metrics5// are distinct from the set of metrics used by the exporter itself, and are just6// used to monitor the stats of the listeners that forward data to the exporter.7type Metrics struct {8EventStats *prometheus.CounterVec9EventsFlushed prometheus.Counter10EventsUnmapped prometheus.Counter11UDPPackets prometheus.Counter12TCPConnections prometheus.Counter13TCPErrors prometheus.Counter14TCPLineTooLong prometheus.Counter15UnixgramPackets prometheus.Counter16LinesReceived prometheus.Counter17SamplesReceived prometheus.Counter18SampleErrors *prometheus.CounterVec19TagsReceived prometheus.Counter20TagErrors prometheus.Counter21MappingsCount prometheus.Gauge22ConflictingEventStats *prometheus.CounterVec23ErrorEventStats *prometheus.CounterVec24EventsActions *prometheus.CounterVec25MetricsCount *prometheus.GaugeVec26}2728// NewMetrics initializes Metrics and registers them to the given Registerer.29func NewMetrics(r prometheus.Registerer) (*Metrics, error) {30var m Metrics3132m.EventStats = prometheus.NewCounterVec(prometheus.CounterOpts{33Name: "statsd_exporter_events_total",34Help: "The total number of StatsD events seen.",35}, []string{"type"})36m.EventsFlushed = prometheus.NewCounter(prometheus.CounterOpts{37Name: "statsd_exporter_event_queue_flushed_total",38Help: "Number of times events were flushed to exporter",39})40m.EventsUnmapped = prometheus.NewCounter(prometheus.CounterOpts{41Name: "statsd_exporter_events_unmapped_total",42Help: "The total number of StatsD events no mapping was found for.",43})44m.UDPPackets = prometheus.NewCounter(prometheus.CounterOpts{45Name: "statsd_exporter_udp_packets_total",46Help: "The total number of StatsD packets received over UDP.",47})48m.TCPConnections = prometheus.NewCounter(prometheus.CounterOpts{49Name: "statsd_exporter_tcp_connections_total",50Help: "The total number of TCP connections handled.",51})52m.TCPErrors = prometheus.NewCounter(prometheus.CounterOpts{53Name: "statsd_exporter_tcp_connection_errors_total",54Help: "The number of errors encountered reading from TCP.",55})56m.TCPLineTooLong = prometheus.NewCounter(prometheus.CounterOpts{57Name: "statsd_exporter_tcp_too_long_lines_total",58Help: "The number of lines discarded due to being too long.",59})60m.UnixgramPackets = prometheus.NewCounter(prometheus.CounterOpts{61Name: "statsd_exporter_unixgram_packets_total",62Help: "The total number of StatsD packets received over Unixgram.",63})64m.LinesReceived = prometheus.NewCounter(prometheus.CounterOpts{65Name: "statsd_exporter_lines_total",66Help: "The total number of StatsD lines received.",67})68m.SamplesReceived = prometheus.NewCounter(prometheus.CounterOpts{69Name: "statsd_exporter_samples_total",70Help: "The total number of StatsD samples received.",71})72m.SampleErrors = prometheus.NewCounterVec(prometheus.CounterOpts{73Name: "statsd_exporter_sample_errors_total",74Help: "The total number of errors parsing StatsD samples.",75}, []string{"reason"})76m.TagsReceived = prometheus.NewCounter(prometheus.CounterOpts{77Name: "statsd_exporter_tags_total",78Help: "The total number of DogStatsD tags processed.",79})80m.TagErrors = prometheus.NewCounter(prometheus.CounterOpts{81Name: "statsd_exporter_tag_errors_total",82Help: "The number of errors parsing DogStatsD tags.",83})84m.MappingsCount = prometheus.NewGauge(prometheus.GaugeOpts{85Name: "statsd_exporter_loaded_mappings",86Help: "The current number of configured metric mappings.",87})88m.ConflictingEventStats = prometheus.NewCounterVec(prometheus.CounterOpts{89Name: "statsd_exporter_events_conflict_total",90Help: "The total number of StatsD events with conflicting names.",91}, []string{"type"})92m.ErrorEventStats = prometheus.NewCounterVec(prometheus.CounterOpts{93Name: "statsd_exporter_events_error_total",94Help: "The total number of StatsD events discarded due to errors.",95}, []string{"reason"})96m.EventsActions = prometheus.NewCounterVec(prometheus.CounterOpts{97Name: "statsd_exporter_events_actions_total",98Help: "The total number of StatsD events by action.",99}, []string{"action"})100m.MetricsCount = prometheus.NewGaugeVec(prometheus.GaugeOpts{101Name: "statsd_exporter_metrics_total",102Help: "The total number of metrics.",103}, []string{"type"})104105cs := []prometheus.Collector{106m.EventStats,107m.EventsFlushed,108m.EventsUnmapped,109m.UDPPackets,110m.TCPConnections,111m.TCPErrors,112m.TCPLineTooLong,113m.UnixgramPackets,114m.LinesReceived,115m.SamplesReceived,116m.SampleErrors,117m.TagsReceived,118m.TagErrors,119m.MappingsCount,120m.ConflictingEventStats,121m.ErrorEventStats,122m.EventsActions,123m.MetricsCount,124}125if r != nil {126for _, c := range cs {127if err := r.Register(c); err != nil {128return nil, err129}130}131}132133return &m, nil134}135136137