use label for metric type and decrement

Signed-off-by: Brian Akins <brian@akins.org>
This commit is contained in:
Brian Akins 2019-04-12 13:29:25 -04:00
parent 92957ce080
commit 45402964a4
2 changed files with 11 additions and 6 deletions

View file

@ -102,7 +102,7 @@ func (c *CounterContainer) Get(metricName string, labels prometheus.Labels, help
counterVec, ok := c.Elements[mapKey] counterVec, ok := c.Elements[mapKey]
if !ok { if !ok {
metricsCount.Inc() metricsCount.WithLabelValues("counter").Inc()
counterVec = prometheus.NewCounterVec(prometheus.CounterOpts{ counterVec = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: metricName, Name: metricName,
Help: help, Help: help,
@ -120,6 +120,7 @@ func (c *CounterContainer) Delete(metricName string, labels prometheus.Labels) {
mapKey := getContainerMapKey(metricName, labelNames) mapKey := getContainerMapKey(metricName, labelNames)
if _, ok := c.Elements[mapKey]; ok { if _, ok := c.Elements[mapKey]; ok {
c.Elements[mapKey].Delete(labels) c.Elements[mapKey].Delete(labels)
metricsCount.WithLabelValues("counter").Dec()
} }
} }
@ -139,7 +140,7 @@ func (c *GaugeContainer) Get(metricName string, labels prometheus.Labels, help s
gaugeVec, ok := c.Elements[mapKey] gaugeVec, ok := c.Elements[mapKey]
if !ok { if !ok {
metricsCount.Inc() metricsCount.WithLabelValues("gauge").Inc()
gaugeVec = prometheus.NewGaugeVec(prometheus.GaugeOpts{ gaugeVec = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: metricName, Name: metricName,
Help: help, Help: help,
@ -157,6 +158,7 @@ func (c *GaugeContainer) Delete(metricName string, labels prometheus.Labels) {
mapKey := getContainerMapKey(metricName, labelNames) mapKey := getContainerMapKey(metricName, labelNames)
if _, ok := c.Elements[mapKey]; ok { if _, ok := c.Elements[mapKey]; ok {
c.Elements[mapKey].Delete(labels) c.Elements[mapKey].Delete(labels)
metricsCount.WithLabelValues("gauge").Dec()
} }
} }
@ -178,7 +180,7 @@ func (c *SummaryContainer) Get(metricName string, labels prometheus.Labels, help
summaryVec, ok := c.Elements[mapKey] summaryVec, ok := c.Elements[mapKey]
if !ok { if !ok {
metricsCount.Inc() metricsCount.WithLabelValues("summary").Inc()
quantiles := c.mapper.Defaults.Quantiles quantiles := c.mapper.Defaults.Quantiles
if mapping != nil && mapping.Quantiles != nil && len(mapping.Quantiles) > 0 { if mapping != nil && mapping.Quantiles != nil && len(mapping.Quantiles) > 0 {
quantiles = mapping.Quantiles quantiles = mapping.Quantiles
@ -206,6 +208,7 @@ func (c *SummaryContainer) Delete(metricName string, labels prometheus.Labels) {
mapKey := getContainerMapKey(metricName, labelNames) mapKey := getContainerMapKey(metricName, labelNames)
if _, ok := c.Elements[mapKey]; ok { if _, ok := c.Elements[mapKey]; ok {
c.Elements[mapKey].Delete(labels) c.Elements[mapKey].Delete(labels)
metricsCount.WithLabelValues("summary").Dec()
} }
} }
@ -227,7 +230,7 @@ func (c *HistogramContainer) Get(metricName string, labels prometheus.Labels, he
histogramVec, ok := c.Elements[mapKey] histogramVec, ok := c.Elements[mapKey]
if !ok { if !ok {
metricsCount.Inc() metricsCount.WithLabelValues("histogram").Inc()
buckets := c.mapper.Defaults.Buckets buckets := c.mapper.Defaults.Buckets
if mapping != nil && mapping.Buckets != nil && len(mapping.Buckets) > 0 { if mapping != nil && mapping.Buckets != nil && len(mapping.Buckets) > 0 {
buckets = mapping.Buckets buckets = mapping.Buckets
@ -251,6 +254,7 @@ func (c *HistogramContainer) Delete(metricName string, labels prometheus.Labels)
mapKey := getContainerMapKey(metricName, labelNames) mapKey := getContainerMapKey(metricName, labelNames)
if _, ok := c.Elements[mapKey]; ok { if _, ok := c.Elements[mapKey]; ok {
c.Elements[mapKey].Delete(labels) c.Elements[mapKey].Delete(labels)
metricsCount.WithLabelValues("histogram").Dec()
} }
} }

View file

@ -116,11 +116,12 @@ var (
}, },
[]string{"action"}, []string{"action"},
) )
metricsCount = prometheus.NewCounter( metricsCount = prometheus.NewGaugeVec(
prometheus.CounterOpts{ prometheus.GaugeOpts{
Name: "statsd_exporter_metrics_total", Name: "statsd_exporter_metrics_total",
Help: "The total number of metrics.", Help: "The total number of metrics.",
}, },
[]string{"type"},
) )
) )