Documentation ¶
Overview ¶
Package main provides a program that periodically collects metrics about Amazon RDS clusters and instances and exports them in Prometheus format. It uses the AWS SDK for Go and the Prometheus Go client library to perform these operations.
The program reads two environment variables: EXPORTER_AWS_API & INTERVAL_SECONDS, which specifies the time interval in seconds for fetching the data, and EXPORTER_SERVER_PORT, which specifies the port number for serving the Prometheus metrics.
The program defines two main types: Config, which holds the AWS RDS API client, and Metrics, which holds the Prometheus metrics. The program also defines a struct RDSInfo to represent information about an Amazon RDS cluster.
The main() function initializes the program by setting up the configuration, metrics, and HTTP server, and then starts a goroutine that periodically fetches RDS cluster and instance data and exports the metrics. The goroutine uses the snapshot() function to fetch the data and export the metrics.
The snapshot() function fetches RDS cluster and instance data, merges them into a single slice of RDSInfos, and then exports the metrics for each RDSInfo. If any error occurs during the metric exporting process, the function will skip the problematic RDSInfo and continue exporting other RDSInfos.
The export() function collects RDS info and validates its engine version against a map of allowed engine versions. If the version is deprecated, it will set the deprecatedGauge Prometheus metric to 1 and the availableGauge metric to 0, and vice versa if the version is available.
The program also defines two helper functions: getEnvInteger() to read integer environment variables, and initHttpServer() to initialize the HTTP server.