Prerequisites
Before starting, make sure you have:- Query Exporter installed (see Installation)
- A database to connect to (we’ll use SQLite for this guide)
- Basic familiarity with YAML and SQL
Your first Query Exporter setup
Create a configuration file
Create a file named This configuration:
config.yaml in your working directory:config.yaml
- Connects to an in-memory SQLite database
- Defines a gauge metric to store a random value
- Runs a query every 5 seconds to generate a random number
Using
sqlite:// creates an in-memory database - perfect for testing. For a real database, use a DSN like sqlite:///path/to/database.db.View your metrics
Open your browser or use curl to access the metrics endpoint:You should see output including:
Real-world example
Let’s create a more practical example that monitors a real database:Configuration options
Command-line options
Host address to bind. Use
0.0.0.0 to listen on all interfaces.Port to run the webserver on.
Path under which metrics are exposed.
Minimum log level:
critical, error, warning, info, or debug.Configuration file path. Can be specified multiple times for partial configs.
Validate configuration without starting the exporter.
Include process resource usage metrics.
Environment variables
All command-line options can be set via environment variables with theQE_ prefix:
.env file in your working directory:
.env
Built-in metrics
Query Exporter automatically exports these metrics:Number of database connection errors per databaseLabels:
databaseNumber of executed queries per database, query, and statusLabels:
database, query, status (success/error/timeout)Configured query execution interval in secondsLabels:
queryQuery execution latency in secondsLabels:
database, queryLast query execution timestamp (Unix time)Labels:
database, queryTesting your setup
Common patterns
Using query timeouts
Using cron schedules
Using environment variables in DSN
Multiple metrics from one query
Troubleshooting
Configuration errors
Configuration errors
Validate your configuration:Enable debug logging:
Database connection issues
Database connection issues
- Verify your DSN format is correct for your database engine
- Check that required database drivers are installed
- Test database connectivity outside of Query Exporter
- Check firewall rules and network connectivity
Metrics not updating
Metrics not updating
- Check query interval or schedule is configured correctly
- Look for errors in logs:
query-exporter --log-level debug - Verify query syntax is correct for your database
- Check
queries_totalmetric withstatus="error"label
Docker issues
Docker issues
- Ensure config directory is mounted:
-v "$PWD:/config" - Check config.yaml exists in mounted directory
- Verify port mapping:
-p 9560:9560 - Check container logs:
docker logs query-exporter
Next steps
Configuration reference
Learn about all configuration options in detail
Database setup
Database-specific connection and query examples
Metric types
Understanding gauge, counter, histogram, summary, and enum metrics
Production deployment
Best practices for running in production