queries section defines the SQL queries that will be executed against databases to populate metrics. Each query is configured with a unique name as the key.
Query Structure
Dictionary of query configurations, keyed by query name.
Required Fields
List of database names to run this query against.Database names must reference databases defined in the
databases section.Constraints:- Must contain at least 1 database name
- Must not contain duplicate database names
List of metric names to populate with query results.Metric names must reference metrics defined in the
metrics section. Query results must include columns matching the metric names and their labels.Constraints:- Must contain at least 1 metric name
- Must not contain duplicate metric names
The SQL query to execute.The query results should include:
- Columns matching the metric names
- Columns for each label defined in the metrics
!file tag.Scheduling Fields
How often to run the query.Cannot be used with:
schedule (must use one or the other)Format:- Integer: seconds
- String: number followed by optional suffix (
s=seconds,m=minutes,h=hours,d=days)
- Must be a positive number
- Must match pattern
^[0-9]+[smhd]?$for string format
interval and schedule will raise: ValueError: can't set both interval and scheduleCron expression for when to run the query.Cannot be used with:
interval (must use one or the other)Use this for more complex scheduling needs (e.g., specific times, days of week).Format: Standard cron expression (validated using croniter)Validation:- Must be a valid cron expression
- Setting both
intervalandschedulewill raise:ValueError: can't set both interval and schedule
Optional Fields
Query timeout in seconds.If the query takes longer than this timeout, it will be cancelled.Constraints:
- Must be greater than 0
- Must be a multiple of 0.1 (one decimal place precision)
Query parameters for running the same query with different parameter values.This allows running a single query multiple times with different parameters, creating separate metric series for each parameter set.Two formats supported:
- List format: Simple list of parameter sets
- Matrix format: Dictionary with parameter groups that are combined
- If specified, must contain at least 1 parameter set
Query Parameters
List Format
Provide a simple list of parameter dictionaries. The query runs once for each set.Matrix Format
Provide a dictionary where each key is a parameter group, and values are lists of parameter sets. Query Exporter will run the query for every combination (Cartesian product) of parameters.region__name=us-east, status__value=activeregion__name=us-east, status__value=inactiveregion__name=us-west, status__value=activeregion__name=us-west, status__value=inactiveregion__name=eu-west, status__value=activeregion__name=eu-west, status__value=inactive
__ (e.g., region__name, status__value).
Parameters with Labels
Parameters are often used to create metric labels:Complete Examples
Simple Query with Interval
Query with Schedule
Query with Timeout
Query with List Parameters
Query with Matrix Parameters
Multi-Database Query
Query with Multiple Metrics and Labels
Validation Rules
The following validation rules are enforced on query configurations:-
Database validation:
databasesmust contain at least 1 database name- Database names must not contain duplicates
-
Metric validation:
metricsmust contain at least 1 metric name- Metric names must not contain duplicates
-
SQL validation:
sqlis required and must be a non-empty string
-
Scheduling validation:
- Cannot set both
intervalandschedule intervalmust be a positive numberintervalstring format must match^[0-9]+[smhd]?$schedulemust be a valid cron expression
- Cannot set both
-
Timeout validation:
- Must be greater than 0
- Must be a multiple of 0.1
-
Parameter validation:
- If specified, must contain at least 1 parameter set
- In matrix format, each group must contain at least 1 parameter set
Error Messages
Common validation errors:ValueError: can't set both interval and schedule- Bothintervalandschedulewere specifiedAssertionError: must not contain duplicate items- Duplicate database or metric namesAssertionError: invalid interval definition- Invalid interval formatcroniter.CroniterBadCronError- Invalid cron expression inscheduleAssertionError: must be a positive number- Invalid timeout or interval value
Time Interval Format Reference
Time intervals can be specified as:-
Integers: Interpreted as seconds
30= 30 seconds300= 300 seconds (5 minutes)
-
Strings with suffixes:
s= seconds:30s= 30 secondsm= minutes:5m= 5 minutes (300 seconds)h= hours:2h= 2 hours (7200 seconds)d= days:1d= 1 day (86400 seconds)
Cron Expression Format Reference
Cron expressions follow the standard format:0 * * * *- Every hour0 0 * * *- Every day at midnight30 2 * * *- Every day at 2:30 AM0 9 * * 1- Every Monday at 9 AM0 0 1 * *- First day of every month at midnight*/15 * * * *- Every 15 minutes