queries section defines SQL queries to execute against databases. Each query updates one or more metrics with its results.
Basic Configuration
Configuration Options
List of databases to run the query on. Names must match those defined in the
databases section.- Must contain at least 1 database
- Must not contain duplicates
- Metrics are automatically tagged with the
databaselabel
List of metrics that the query updates. Names must match those defined in the
metrics section.- Must contain at least 1 metric
- Must not contain duplicates
The SQL text of the query.The query must return columns with names matching:
- The metric names defined in
metrics - All label names for those metrics (if any)
The time interval at which the query is run.
- Can be an integer (interpreted as seconds)
- Can be a string with suffix:
s(seconds),m(minutes),h(hours),d(days) - Must be a positive number
- Cannot be specified together with
schedule - If not specified, query only runs on HTTP requests
30, 5m, 1h, 7dA Cron-like schedule expression for executing queries at specific times.Format:
minute hour day month day_of_weekExamples:*/5 * * * *- Every 5 minutes0 * * * *- Every hour at minute 00 0 * * *- Daily at midnight0 0 * * 0- Weekly on Sunday at midnight
interval.Optional parameters to run the query with. Can be specified as a list or a matrix.See Query Parameters below for details.
Query timeout in seconds. Must be a positive number and a multiple of 0.1.Examples:
0.5, 1.0, 30.0Interval vs Schedule
Using Interval
Runs the query repeatedly at fixed intervals:Using Schedule
Runs the query on a Cron schedule:On-Demand Only
If neitherinterval nor schedule is specified, the query only runs when the /metrics endpoint is accessed:
Writing Queries
Column Names Must Match Metrics
Your SQL query must return columns with names matching the metric names:Multiple Metrics
Queries can update multiple metrics at once:Including Labels
When metrics have labels, the query must return columns for each label:The
database label is automatically added. You don’t need to include it in your query.Multi-line SQL
Use YAML’s| or > syntax for multi-line queries:
Query Parameters
Parameters allow you to run the same query multiple times with different values.List Format
Run the query once for each parameter set:SELECT COUNT(*) AS row_count FROM usersSELECT COUNT(*) AS row_count FROM ordersSELECT COUNT(*) AS row_count FROM products
Matrix Format
Generate all permutations of parameter combinations:Variable format in matrix mode:
:top_level_key__inner_keyWHERE os = 'MacOS' AND arch = 'arm64' AND lang = 'Python3'WHERE os = 'MacOS' AND arch = 'arm64' AND lang = 'Java'- … and so on
Escaping Colons
Since: is used for parameter markers, literal colons at the beginning of words must be escaped:
Timeout
Set a timeout to prevent long-running queries from blocking:Timeout must be a multiple of 0.1 seconds. Examples:
0.5, 1.0, 10.5Complete Examples
Simple Gauge Query
Counter with Increment
Scheduled Report Query
Multi-Database Query
Each database will have separate metric series thanks to the automatic
database label.