Accessing specific datafields for Prometheus Exporter

Using Postgres_Exporter on my PSQL servers and piping them to the Prometheus MetricBeat with a sample config of

# Module: prometheus
# Docs: https://www.elastic.co/guide/en/beats/metricbeat/7.6/metricbeat-module-prometheus.html

- module: prometheus
  period: 10s
  hosts: ["192.168.100.102:9187"]
  metrics_path: '/metrics'

- module: prometheus
  period: 10s
  hosts: ["192.168.100.101:9187"]
  metrics_path: '/metrics'

A sample of the metrics collected:

# HELP pg_stat_database_conflicts Number of queries canceled due to conflicts with recovery in this database. (Conflicts occur only on standby servers; see pg_stat_database_conflicts for details.)
# TYPE pg_stat_database_conflicts counter
pg_stat_database_conflicts{datid="1",datname="template1"} 0
pg_stat_database_conflicts{datid="12136",datname="template0"} 0
pg_stat_database_conflicts{datid="12141",datname="postgres"} 0
pg_stat_database_conflicts{datid="16385",datname="gis"} 0
...
# HELP pg_stat_activity_max_tx_duration max duration in seconds any active transaction has been running
# TYPE pg_stat_activity_max_tx_duration gauge
pg_stat_activity_max_tx_duration{datname="gis",state="active"} 0
pg_stat_activity_max_tx_duration{datname="gis",state="disabled"} 0
pg_stat_activity_max_tx_duration{datname="gis",state="fastpath function call"} 0
pg_stat_activity_max_tx_duration{datname="gis",state="idle"} 0
pg_stat_activity_max_tx_duration{datname="gis",state="idle in transaction"} 0
pg_stat_activity_max_tx_duration{datname="gis",state="idle in transaction (aborted)"} 0
pg_stat_activity_max_tx_duration{datname="postgres",state="active"} 0
pg_stat_activity_max_tx_duration{datname="postgres",state="disabled"} 0
pg_stat_activity_max_tx_duration{datname="postgres",state="fastpath function call"} 0
pg_stat_activity_max_tx_duration{datname="postgres",state="idle"} 0
pg_stat_activity_max_tx_duration{datname="postgres",state="idle in transaction"} 0
pg_stat_activity_max_tx_duration{datname="postgres",state="idle in transaction (aborted)"} 0
pg_stat_activity_max_tx_duration{datname="template0",state="active"} 0
pg_stat_activity_max_tx_duration{datname="template0",state="disabled"} 0
pg_stat_activity_max_tx_duration{datname="template0",state="fastpath function call"} 0
pg_stat_activity_max_tx_duration{datname="template0",state="idle"} 0
pg_stat_activity_max_tx_duration{datname="template0",state="idle in transaction"} 0
pg_stat_activity_max_tx_duration{datname="template0",state="idle in transaction (aborted)"} 0
pg_stat_activity_max_tx_duration{datname="template1",state="active"} 0
pg_stat_activity_max_tx_duration{datname="template1",state="disabled"} 0
pg_stat_activity_max_tx_duration{datname="template1",state="fastpath function call"} 0
pg_stat_activity_max_tx_duration{datname="template1",state="idle"} 0
pg_stat_activity_max_tx_duration{datname="template1",state="idle in transaction"} 0
pg_stat_activity_max_tx_duration{datname="template1",state="idle in transaction (aborted)"} 0

How should I get the metrics for the specific databases? Currently, all I see is the generic fieldname, unsure where the value of the field is obtained from.

Hi,

could you please post a sample document from Elasticsearch? I'm curious if there is any field that's related to a database name.

There is a label!

Now my timelion expression will be like:

.es(index=metricbeat-*, 
metric=sum:prometheus.metrics.pg_stat_database_conflicts,
q="service.address:192.168.100.101* AND  prometheus.labels.datname:postgres")
    .color(red),

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.