What is Query Exporter?
Query Exporter is a Prometheus exporter that allows you to collect metrics from database queries at specified time intervals. It uses SQLAlchemy to connect to different database engines, enabling you to monitor any database that supports SQL queries. With Query Exporter, you can:- Run SQL queries on multiple databases simultaneously
- Export query results as Prometheus metrics (gauge, counter, summary, histogram, enum)
- Schedule queries at specific intervals or using cron expressions
- Track query execution with built-in monitoring metrics
- Apply custom labels to databases and metrics for better organization
Key features
Multi-database support
Connect to PostgreSQL, MySQL, Oracle, SQL Server, SQLite, and more through SQLAlchemy
Flexible scheduling
Run queries at fixed intervals or using cron-style schedules
Multiple metric types
Support for gauge, counter, summary, histogram, and enum metric types
Built-in monitoring
Track query latency, execution counts, errors, and timestamps automatically
Label support
Add custom labels to databases and derive labels from query results
Easy deployment
Available via pip, Docker, and Snap with minimal configuration required
How it works
Query Exporter runs as a lightweight web service that:- Loads your configuration file defining databases, metrics, and queries
- Connects to your databases using SQLAlchemy
- Executes queries on schedule (interval-based or cron-based)
- Exports results as Prometheus metrics on the
/metricsendpoint (default port 9560) - Provides built-in metrics for query health and performance
Who should use Query Exporter?
Database administrators
Database administrators
Monitor database performance, connection counts, query statistics, and other operational metrics without custom exporters.
DevOps engineers
DevOps engineers
Export application-specific metrics stored in databases to Prometheus for unified monitoring and alerting.
Site reliability engineers
Site reliability engineers
Track business metrics, SLA compliance, and application health through database queries.
Data engineers
Data engineers
Monitor data pipeline health, row counts, data freshness, and processing metrics.
Example use cases
- Database monitoring: Export connection counts, table sizes, replication lag, lock statistics
- Business metrics: Track user signups, order counts, revenue figures from application databases
- Data quality: Monitor null counts, duplicate records, data freshness timestamps
- Application health: Export error counts, processing queues, job statuses from application tables
- Custom metrics: Any metric that can be queried with SQL
Quick example
Here’s a minimal configuration that queries a SQLite database:- Connects to a SQLite database at
data.db - Defines a gauge metric called
user_count - Runs a query every 60 seconds to count users
- Exports the result as
user_countmetric at/metrics
Next steps
Get started
Follow our quickstart guide to run your first query
Installation
Install Query Exporter using pip, Docker, or Snap
Configuration
Learn about all configuration options
GitHub
View source code and contribute
Query Exporter is open source and available under the GPL-3.0 license. It’s actively maintained and used in production by many organizations.