Skip to content

Commit f4abebb

Browse files
committed
safely convert MaxAllocatedStorage incase of nil
1 parent 360e8d7 commit f4abebb

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

pkg/rds.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ var DBMaxConnections = map[string]map[string]int64{
123123
"default.postgres13": 5000,
124124
"default.postgres14": 5000,
125125
},
126-
"db.m5d.large": {
126+
"db.m5d.large": map[string]int64{
127127
"default": 830,
128128
"default.postgres10": 830,
129129
"default.postgres11": 830,
@@ -510,11 +510,17 @@ func (e *RDSExporter) addAllInstanceMetrics(sessionIndex int, instances []*rds.D
510510
if instance.LatestRestorableTime != nil {
511511
restoreTime = float64(instance.LatestRestorableTime.Unix())
512512
}
513+
514+
var MaxAllocatedStorageValue = 0.0
515+
if instance.MaxAllocatedStorage != nil {
516+
MaxAllocatedStorageValue = float64(*instance.MaxAllocatedStorage*1024*1024*1024)
517+
}
518+
513519
e.cache.AddMetric(prometheus.MustNewConstMetric(LatestRestorableTime, prometheus.CounterValue, restoreTime, e.getRegion(sessionIndex), *instance.DBInstanceIdentifier))
514520

515521
e.cache.AddMetric(prometheus.MustNewConstMetric(MaxConnections, prometheus.GaugeValue, float64(maxConnections), e.getRegion(sessionIndex), *instance.DBInstanceIdentifier))
516522
e.cache.AddMetric(prometheus.MustNewConstMetric(AllocatedStorage, prometheus.GaugeValue, float64(*instance.AllocatedStorage*1024*1024*1024), e.getRegion(sessionIndex), *instance.DBInstanceIdentifier))
517-
e.cache.AddMetric(prometheus.MustNewConstMetric(MaxAllocatedStorage, prometheus.GaugeValue, float64(*instance.MaxAllocatedStorage*1024*1024*1024), e.getRegion(sessionIndex), *instance.DBInstanceIdentifier))
523+
e.cache.AddMetric(prometheus.MustNewConstMetric(MaxAllocatedStorage, prometheus.GaugeValue, MaxAllocatedStorageValue, e.getRegion(sessionIndex), *instance.DBInstanceIdentifier))
518524
e.cache.AddMetric(prometheus.MustNewConstMetric(DBInstanceStatus, prometheus.GaugeValue, 1, e.getRegion(sessionIndex), *instance.DBInstanceIdentifier, *instance.DBInstanceStatus))
519525
e.cache.AddMetric(prometheus.MustNewConstMetric(EngineVersion, prometheus.GaugeValue, 1, e.getRegion(sessionIndex), *instance.DBInstanceIdentifier, *instance.Engine, *instance.EngineVersion))
520526
e.cache.AddMetric(prometheus.MustNewConstMetric(DBInstanceClass, prometheus.GaugeValue, 1, e.getRegion(sessionIndex), *instance.DBInstanceIdentifier, *instance.DBInstanceClass))

0 commit comments

Comments
 (0)