Skip to content

Commit

Permalink
Merge pull request #200 from bakins/metrics-count
Browse files Browse the repository at this point in the history
Add metric to track unique metric names the exporter is tracking
  • Loading branch information
Matthias Rampke authored Apr 16, 2019
2 parents 468c70d + 4540296 commit 526a81b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func (c *CounterContainer) Get(metricName string, labels prometheus.Labels, help

counterVec, ok := c.Elements[mapKey]
if !ok {
metricsCount.WithLabelValues("counter").Inc()
counterVec = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: metricName,
Help: help,
Expand All @@ -119,6 +120,7 @@ func (c *CounterContainer) Delete(metricName string, labels prometheus.Labels) {
mapKey := getContainerMapKey(metricName, labelNames)
if _, ok := c.Elements[mapKey]; ok {
c.Elements[mapKey].Delete(labels)
metricsCount.WithLabelValues("counter").Dec()
}
}

Expand All @@ -138,6 +140,7 @@ func (c *GaugeContainer) Get(metricName string, labels prometheus.Labels, help s

gaugeVec, ok := c.Elements[mapKey]
if !ok {
metricsCount.WithLabelValues("gauge").Inc()
gaugeVec = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: metricName,
Help: help,
Expand All @@ -155,6 +158,7 @@ func (c *GaugeContainer) Delete(metricName string, labels prometheus.Labels) {
mapKey := getContainerMapKey(metricName, labelNames)
if _, ok := c.Elements[mapKey]; ok {
c.Elements[mapKey].Delete(labels)
metricsCount.WithLabelValues("gauge").Dec()
}
}

Expand All @@ -176,6 +180,7 @@ func (c *SummaryContainer) Get(metricName string, labels prometheus.Labels, help

summaryVec, ok := c.Elements[mapKey]
if !ok {
metricsCount.WithLabelValues("summary").Inc()
quantiles := c.mapper.Defaults.Quantiles
if mapping != nil && mapping.Quantiles != nil && len(mapping.Quantiles) > 0 {
quantiles = mapping.Quantiles
Expand Down Expand Up @@ -203,6 +208,7 @@ func (c *SummaryContainer) Delete(metricName string, labels prometheus.Labels) {
mapKey := getContainerMapKey(metricName, labelNames)
if _, ok := c.Elements[mapKey]; ok {
c.Elements[mapKey].Delete(labels)
metricsCount.WithLabelValues("summary").Dec()
}
}

Expand All @@ -224,6 +230,7 @@ func (c *HistogramContainer) Get(metricName string, labels prometheus.Labels, he

histogramVec, ok := c.Elements[mapKey]
if !ok {
metricsCount.WithLabelValues("histogram").Inc()
buckets := c.mapper.Defaults.Buckets
if mapping != nil && mapping.Buckets != nil && len(mapping.Buckets) > 0 {
buckets = mapping.Buckets
Expand All @@ -247,6 +254,7 @@ func (c *HistogramContainer) Delete(metricName string, labels prometheus.Labels)
mapKey := getContainerMapKey(metricName, labelNames)
if _, ok := c.Elements[mapKey]; ok {
c.Elements[mapKey].Delete(labels)
metricsCount.WithLabelValues("histogram").Dec()
}
}

Expand Down
8 changes: 8 additions & 0 deletions telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ var (
},
[]string{"action"},
)
metricsCount = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "statsd_exporter_metrics_total",
Help: "The total number of metrics.",
},
[]string{"type"},
)
)

func init() {
Expand All @@ -135,4 +142,5 @@ func init() {
prometheus.MustRegister(conflictingEventStats)
prometheus.MustRegister(errorEventStats)
prometheus.MustRegister(eventsActions)
prometheus.MustRegister(metricsCount)
}

0 comments on commit 526a81b

Please sign in to comment.