prometheus-community / postgres_exporter

A PostgreSQL metric exporter for Prometheus
Apache License 2.0
2.66k stars 710 forks source link

Only first record exported in extended queries #469

Open franck102 opened 3 years ago

franck102 commented 3 years ago

I was assuming that if an extended query returns multiple results with distinct labels then the exporter would export multiple time series, but this doesn't seem to work? This query:

SELECT J.job_id, J.application_name,coalesce(CA.view_name, J.hypertable_name) as relation, J.schedule_interval,
      JS.total_runs, JS.total_successes, JS.total_failures
    FROM timescaledb_information.jobs J
    LEFT JOIN timescaledb_information.continuous_aggregates CA on J.hypertable_name = CA.materialization_hypertable_name
    LEFT JOIN timescaledb_information.job_stats JS on J.job_id = JS.job_id

which generates this result set:

job_id|application_name                          |relation                      |schedule_interval|total_runs|total_successes|total_failures|
------|------------------------------------------|------------------------------|-----------------|----------|---------------|--------------|
     1|Telemetry Reporter [1]                    |                              |         24:00:00|        13|              9|             4|
  1092|Retention Policy [1092]                   |service:dms_fdo_query:increase|            1 day|         1|              1|             0|
  1093|Retention Policy [1093]                   |service:applications:increase |            1 day|         1|              1|             0|
  1094|Retention Policy [1094]                   |service:legal_notices:increase|            1 day|         1|              1|             0|
  1095|Retention Policy [1095]                   |service:campaigns:increase    |            1 day|         1|              1|             0|

gives only the 3 total_xxx time series for job_id=1 in Prometheus with the configuration below - the other jobs don't appear??

    job_stats:
      query: |
        SELECT J.job_id, J.application_name,coalesce(CA.view_name, J.hypertable_name) as relation, J.schedule_interval,
          JS.total_runs, JS.total_successes, JS.total_failures
        FROM timescaledb_information.jobs J
        LEFT JOIN timescaledb_information.continuous_aggregates CA on J.hypertable_name = CA.materialization_hypertable_name
        LEFT JOIN timescaledb_information.job_stats JS on J.job_id = JS.job_id
      metrics:
        - job_id:
            usage: "LABEL"
            description: "Unique ID of the job"
        - application_name:
            usage: "LABEL"
            description: "Application name of the job"
        - relation:
            usage: "LABEL"
            description: "View or hypertable targeted by the job"
        - schedule_interval:
            usage: "LABEL"
            description: "Job schedule interval"
        - total_runs:
            usage: "COUNTER"
            description: "Total number of job runs so far"
        - total_successes:
            usage: "COUNTER"
            description: "Total successful runs"
        - total_failures:
            usage: "COUNTER"
            description: "Total failure runs"
franck102 commented 3 years ago

A simpler query works as expected:

rel_stats:
  query: |
    select relname,relpages from pg_catalog.pg_class
  metrics:
    - relname:
        usage: "LABEL"
    - relpages:
        usage: "GAUGE"

... so I really don't know what is happening. Querying the /metrics endpoint directly confirms that the exporter only reports one time series:

# HELP job_stats_total_failures Total failure runs
# TYPE job_stats_total_failures counter
job_stats_total_failures{application_name="Telemetry Reporter [1]",job_id="1",namespace="dmp-monitoring",relation="",release="dms-timescaledb",schedule_interval="24:00:00",server="/var/run/postgresql:5432"} 4
# HELP job_stats_total_runs Total number of job runs so far
# TYPE job_stats_total_runs counter
job_stats_total_runs{application_name="Telemetry Reporter [1]",job_id="1",namespace="dmp-monitoring",relation="",release="dms-timescaledb",schedule_interval="24:00:00",server="/var/run/postgresql:5432"} 14
# HELP job_stats_total_successes Total successful runs
# TYPE job_stats_total_successes counter
job_stats_total_successes{application_name="Telemetry Reporter [1]",job_id="1",namespace="dmp-monitoring",relation="",release="dms-timescaledb",schedule_interval="24:00:00",server="/var/run/postgresql:5432"} 10