query-exporter - Export Prometheus metrics from SQL queries
query-exporter is a Prometheus exporter which allows collecting metrics from database queries, at specified time intervals.
It uses SQLAlchemy to connect to different database engines, including PostgreSQL, MySQL, Oracle and Microsoft SQL Server.
Each query can be run on multiple databases, and update multiple metrics.
The application is called with a configuration file that looks like this:
databases:
db1:
dsn: sqlite://
db2:
dsn: sqlite://
metrics:
metric1:
type: gauge
description: A sample gauge
metric2:
type: summary
description: A sample summary
metric3:
type: histogram
description: A sample histogram
buckets: [10, 20, 50, 100, 1000]
queries:
query1:
interval: 5
databases: [db1]
metrics: [metric1]
sql: SELECT random() / 1000000000000000
query2:
interval: 20
databases: [db1, db2]
metrics: [metric2, metric3]
sql: |
SELECT abs(random() / 1000000000000000),
abs(random() / 10000000000000000)
The dsn connection string has the following format:
dialect[+driver]://[username:password][@host:port]/database
(see SQLAlchemy documentation for details on the available options).
The metrics list in the query configuration must match values returned by the query defined in sql.
The interval value is interpreted as seconds if no suffix is specified; valid suffix are s, m, h, d. Only integer values can be specified. If no value is specified (or specified as null), the query is executed at every HTTP request.
Queries will usually return a single row, but multiple rows are supported, and each row will cause an update of the related metrics. This is relevant for any kind of metric except gauges, which will be effectively updated to the value from the last row.
For the configuration above, exported metrics look like this:
# HELP metric1 A sample gauge
# TYPE metric1 gauge
metric1{database="db1"} 1549.0
# HELP metric2 A sample summary
# TYPE metric2 summary
metric2_count{database="db2"} 6.0
metric2_sum{database="db2"} 25329.0
metric2_count{database="db1"} 6.0
metric2_sum{database="db1"} 30170.0
# HELP metric3 A sample histogram
# TYPE metric3 histogram
metric3_bucket{database="db2",le="10.0"} 0.0
metric3_bucket{database="db2",le="20.0"} 1.0
metric3_bucket{database="db2",le="50.0"} 2.0
metric3_bucket{database="db2",le="100.0"} 2.0
metric3_bucket{database="db2",le="1000.0"} 6.0
metric3_bucket{database="db2",le="+Inf"} 6.0
metric3_count{database="db2"} 6.0
metric3_sum{database="db2"} 2542.0
metric3_bucket{database="db1",le="10.0"} 1.0
metric3_bucket{database="db1",le="20.0"} 1.0
metric3_bucket{database="db1",le="50.0"} 1.0
metric3_bucket{database="db1",le="100.0"} 2.0
metric3_bucket{database="db1",le="1000.0"} 6.0
metric3_bucket{database="db1",le="+Inf"} 6.0
metric3_count{database="db1"} 6.0
metric3_sum{database="db1"} 2901.0
Metrics are automatically tagged with the database label so that indipendent series are generated for each database.
Database engines
SQLAlchemy doesn’t depend on specific Python database modules at installation. This means additional modules might need to be installed for engines in use (e.g. psycopg2 for PostgreSQL or MySQL-python for MySQL).
See supported databases for details.
Metadata
Release files for query-exporter 1.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| query-exporter-1.3.0.tar.gz | 24.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| query_exporter-1.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 40.2 kB
Release files / query-exporter-1.3.0.tar.gz
| Download URL | query-exporter-1.3.0.tar.gz |
|---|---|
| Size | 24.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
94da98db2a138a0d45d9580852adb358aeae17674ecbf94d4d0e67e31d59144a
|
|
BLAKE2b-256 checksum How to use checksums |
a686982b47f6c80f2458dcac788fd147cde048e3f6a09238023c63c3114163d3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / query_exporter-1.3.0-py3-none-any.whl
| Download URL | query_exporter-1.3.0-py3-none-any.whl |
|---|---|
| Size | 15.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
607b1982e6b8680ed405bccab19d8c96b2f3297ad6fef828d5a3554268e41f50
|
|
BLAKE2b-256 checksum How to use checksums |
a3f1938e899b30043b6b628d7f889567762fade7df33db736323a6237d541bd3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for query-exporter 1.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.