Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RDS storage encrypted metric #12

Merged
merged 4 commits into from
Dec 3, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions rds.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ type RDSExporter struct {
DBInstanceClass *prometheus.Desc
DBInstanceStatus *prometheus.Desc
EngineVersion *prometheus.Desc
LatestRestorableTime *prometheus.Desc
MaxConnections *prometheus.Desc
MaxConnectionsMappingError *prometheus.Desc
PubliclyAccessible *prometheus.Desc
StorageEncrypted *prometheus.Desc

mutex *sync.Mutex
}
Expand Down Expand Up @@ -68,6 +71,12 @@ func NewRDSExporter(sess *session.Session) *RDSExporter {
[]string{"aws_region", "dbinstance_identifier", "engine", "engine_version"},
nil,
),
LatestRestorableTime: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "rds_latestrestorabletime"),
"Latest restorable time (UTC date timestamp).",
[]string{"aws_region", "dbinstance_identifier"},
nil,
),
MaxConnections: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "rds_maxconnections"),
"The DB's max_connections value",
Expand All @@ -80,14 +89,31 @@ func NewRDSExporter(sess *session.Session) *RDSExporter {
[]string{"aws_region", "dbinstance_identifier", "instance_class"},
nil,
),
PubliclyAccessible: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "rds_publiclyaccessible"),
"Indicates if the DB is publicly accessible",
[]string{"aws_region", "dbinstance_identifier"},
nil,
),
StorageEncrypted: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "rds_storageencrypted"),
"Indicates if the DB storage is encrypted",
[]string{"aws_region", "dbinstance_identifier"},
nil,
),
}
}

// Describe is used by the Prometheus client to return a description of the metrics
func (e *RDSExporter) Describe(ch chan<- *prometheus.Desc) {
ch <- e.AllocatedStorage
ch <- e.DBInstanceClass
ch <- e.DBInstanceStatus
ch <- e.EngineVersion
ch <- e.LatestRestorableTime
ch <- e.MaxConnections
ch <- e.MaxConnectionsMappingError
ch <- e.StorageEncrypted
}

// Collect is used by the Prometheus client to collect and return the metrics values
Expand Down Expand Up @@ -133,10 +159,28 @@ func (e *RDSExporter) Collect(ch chan<- prometheus.Metric) {
*instance.DBInstanceClass)
ch <- prometheus.MustNewConstMetric(e.MaxConnectionsMappingError, prometheus.GaugeValue, 1, *e.sess.Config.Region, *instance.DBInstanceIdentifier, *instance.DBInstanceClass)
}

if *instance.PubliclyAccessible {
ch <- prometheus.MustNewConstMetric(e.PubliclyAccessible, prometheus.GaugeValue, 1, *e.sess.Config.Region, *instance.DBInstanceIdentifier)

} else {
ch <- prometheus.MustNewConstMetric(e.PubliclyAccessible, prometheus.GaugeValue, 0, *e.sess.Config.Region, *instance.DBInstanceIdentifier)

}

if *instance.StorageEncrypted {
ch <- prometheus.MustNewConstMetric(e.StorageEncrypted, prometheus.GaugeValue, 1, *e.sess.Config.Region, *instance.DBInstanceIdentifier)

} else {
ch <- prometheus.MustNewConstMetric(e.StorageEncrypted, prometheus.GaugeValue, 0, *e.sess.Config.Region, *instance.DBInstanceIdentifier)

}

ch <- prometheus.MustNewConstMetric(e.MaxConnections, prometheus.GaugeValue, float64(maxConnections), *e.sess.Config.Region, *instance.DBInstanceIdentifier)
ch <- prometheus.MustNewConstMetric(e.AllocatedStorage, prometheus.GaugeValue, float64(*instance.AllocatedStorage*1024*1024*1024), *e.sess.Config.Region, *instance.DBInstanceIdentifier)
ch <- prometheus.MustNewConstMetric(e.DBInstanceStatus, prometheus.GaugeValue, 1, *e.sess.Config.Region, *instance.DBInstanceIdentifier, *instance.DBInstanceStatus)
ch <- prometheus.MustNewConstMetric(e.EngineVersion, prometheus.GaugeValue, 1, *e.sess.Config.Region, *instance.DBInstanceIdentifier, *instance.Engine, *instance.EngineVersion)
ch <- prometheus.MustNewConstMetric(e.DBInstanceClass, prometheus.GaugeValue, 1, *e.sess.Config.Region, *instance.DBInstanceIdentifier, *instance.DBInstanceClass)
ch <- prometheus.MustNewConstMetric(e.LatestRestorableTime, prometheus.CounterValue, float64(instance.LatestRestorableTime.Unix()), *e.sess.Config.Region, *instance.DBInstanceIdentifier)
}
}