Add cluster namespace and name labels to postgres-exporter metrics
Currently postgres-exporter metrics does not have custom labels for metrics. In order to be able to identify from what StackGres cluster those metrics are, it's necessary to add some constant labels.
An example of one of the current metrics:
# HELP pg_stat_activity_count number of connections in this state
# TYPE pg_stat_activity_count gauge
pg_stat_activity_count{datname="postgres",server="localhost:5432",state="active"} 1
pg_stat_activity_count{datname="postgres",server="localhost:5432",state="disabled"} 0
pg_stat_activity_count{datname="postgres",server="localhost:5432",state="fastpath function call"} 0
pg_stat_activity_count{datname="postgres",server="localhost:5432",state="idle"} 1
The labels suggested to be added are: cluster_name
and namespace
so the metrics will look like:
# HELP pg_stat_activity_count number of connections in this state
# TYPE pg_stat_activity_count gauge
pg_stat_activity_count{cluster_name="my_cluster",namespace="my_namespace",datname="postgres",server="localhost:5432",state="active"} 1
pg_stat_activity_count{cluster_name="my_cluster",namespace="my_namespace",datname="postgres",server="localhost:5432",state="disabled"} 0
pg_stat_activity_count{cluster_name="my_cluster",namespace="my_namespace",datname="postgres",server="localhost:5432",state="fastpath function call"} 0
pg_stat_activity_count{cluster_name="my_cluster",namespace="my_namespace",datname="postgres",server="localhost:5432",state="idle"} 1
In some environments with multiple clusters will be more easy to identify where those metrics come from.
To add these metrics to the postgres-exporter is necesary to configure this next parameter:
PG_EXPORTER_CONSTANT_LABELS="cluster_name=MY_CLUSTER, namespace=MY_NAMESPACE"
Edited by Matteo Melli