Skip to main content

Export Prometheus metrics generated from SQL queries.

Project description

Latest Version Build Status Coverage Status

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.

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

query-exporter-1.2.2.tar.gz (23.9 kB view details)

Uploaded Source

Built Distribution

query_exporter-1.2.2-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file query-exporter-1.2.2.tar.gz.

File metadata

File hashes

Hashes for query-exporter-1.2.2.tar.gz
Algorithm Hash digest
SHA256 c7a7982a54e73359bb2bcd66aecbd1bda0dbc4c932a52810e373f3eaed2ff588
MD5 21bc11e4073571d10bc7cb82e410e462
BLAKE2b-256 f57901f728e03f7fc1fbe0b6595c8ff229ed9618801c5eb1828015ea9704913d

See more details on using hashes here.

File details

Details for the file query_exporter-1.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for query_exporter-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9c387da277019936ec5f9bdb319e0ad153eec06d034e1202982e9f07f7893e32
MD5 f27af40a02a60dc02536d8f6bd9dde9e
BLAKE2b-256 1a7fb28fd709776d1dd559ba7352664ffd21903fe9678c17fe1698bbfc5acfad

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page