Skip to content

Commit b35badc

Browse files
authored
Merge pull request #239 from msvticket/unset_metrics
fix: don't expose metrics with no values
2 parents d773108 + 85da556 commit b35badc

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

internal/app/exporter/exporter.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -582,9 +582,15 @@ func (c *rdsCollector) Collect(ch chan<- prometheus.Metric) {
582582
instance.CACertificateIdentifier,
583583
instance.Arn,
584584
)
585-
ch <- prometheus.MustNewConstMetric(c.maxAllocatedStorage, prometheus.GaugeValue, float64(instance.MaxAllocatedStorage), c.awsAccountID, c.awsRegion, dbidentifier)
586-
ch <- prometheus.MustNewConstMetric(c.allocatedDiskIOPS, prometheus.GaugeValue, float64(instance.MaxIops), c.awsAccountID, c.awsRegion, dbidentifier)
587-
ch <- prometheus.MustNewConstMetric(c.allocatedDiskThroughput, prometheus.GaugeValue, float64(instance.StorageThroughput), c.awsAccountID, c.awsRegion, dbidentifier)
585+
if instance.MaxAllocatedStorage > 0 {
586+
ch <- prometheus.MustNewConstMetric(c.maxAllocatedStorage, prometheus.GaugeValue, float64(instance.MaxAllocatedStorage), c.awsAccountID, c.awsRegion, dbidentifier)
587+
}
588+
if instance.MaxIops > 0 {
589+
ch <- prometheus.MustNewConstMetric(c.allocatedDiskIOPS, prometheus.GaugeValue, float64(instance.MaxIops), c.awsAccountID, c.awsRegion, dbidentifier)
590+
}
591+
if instance.StorageThroughput > 0 {
592+
ch <- prometheus.MustNewConstMetric(c.allocatedDiskThroughput, prometheus.GaugeValue, float64(instance.StorageThroughput), c.awsAccountID, c.awsRegion, dbidentifier)
593+
}
588594
ch <- prometheus.MustNewConstMetric(c.status, prometheus.GaugeValue, float64(instance.Status), c.awsAccountID, c.awsRegion, dbidentifier)
589595
ch <- prometheus.MustNewConstMetric(c.backupRetentionPeriod, prometheus.GaugeValue, float64(instance.BackupRetentionPeriod), c.awsAccountID, c.awsRegion, dbidentifier)
590596

@@ -597,8 +603,12 @@ func (c *rdsCollector) Collect(ch chan<- prometheus.Metric) {
597603
storageThroughput = min(float64(instance.StorageThroughput), ec2Metrics.BaselineThroughput)
598604
}
599605

600-
ch <- prometheus.MustNewConstMetric(c.maxIops, prometheus.GaugeValue, float64(maxIops), c.awsAccountID, c.awsRegion, dbidentifier)
601-
ch <- prometheus.MustNewConstMetric(c.storageThroughput, prometheus.GaugeValue, storageThroughput, c.awsAccountID, c.awsRegion, dbidentifier)
606+
if maxIops > 0 {
607+
ch <- prometheus.MustNewConstMetric(c.maxIops, prometheus.GaugeValue, float64(maxIops), c.awsAccountID, c.awsRegion, dbidentifier)
608+
}
609+
if storageThroughput > 0 {
610+
ch <- prometheus.MustNewConstMetric(c.storageThroughput, prometheus.GaugeValue, storageThroughput, c.awsAccountID, c.awsRegion, dbidentifier)
611+
}
602612

603613
if c.configuration.CollectInstanceTags {
604614
names, values := c.getInstanceTagLabels(dbidentifier, instance)

0 commit comments

Comments
 (0)