Prometheus Database query exporter
Simple Prometheus client application that exports database query results to an endpoint that Prometheus can pull data from.
Built with Spring Boot, Kotlin and Prometheus simple client. Externalized config to run queries based on YAML configuration files.
Application has two config classes, first one,
App.kt, creates Spring context and initializes base Spring boot monitoring.
This context also reads all YAML files from queries folder. Second configuration,
QueryConfig.kt, creates individual Prometheus export metric objects.
Set up database properties and query intervals in
application.properties file within
config folder. Note that queries are launched at the same time for each type of metric.
Query file needs 5 properties:
name- Name of the metric
description- Prometheus help text associated with the metric
type- metric type. Possible values:
labels- a list of labels to be associated with the metric
query- The actual SQL query. Note that number of columns return should be
length of labels + 1, where the final column is the actual metric number.
Example query file:
name: amount_of_users description: Gauge to how many users are in the database type: gauge labels: - 'registration_type' - 'age_bracket' query: | SELECT source as registration_type, age_bracket, count(*) as amount FROM USER GROUP BY source, age_bracket ORDER BY source, age_bracket
Metrics are available at:
Add maven dependency for your DB vendor to pom.xml. Change DB drivers in application.properties.
mvn clean package
- Copy created JAR file (prometheus-db-exporter-1.0.0.jar) from /target to your desired location
- Create 2 folders on that same directory:
- Fill mentioned folders with application.properties & query files.
- Run with
java -jar prometheus-db-exporter-1.0.0.jar