postgres_exporter icon indicating copy to clipboard operation
postgres_exporter copied to clipboard

The feature `Adding new metrics` exists in README but not implemented

Open Sasasu opened this issue 1 year ago • 6 comments

What did you do?

Read the README about how to add a new metric.

What did you expect to see?

Find the method about how to add a new metric.

What did you see instead? Under which circumstances?

In the README:

### Adding new metrics
The exporter will attempt to dynamically export additional metrics if they are added in the
future, but they will be marked as "untyped". Additional metric maps can be easily created
from Postgres documentation by copying the tables and using the following Python snippet:

x = """tab separated raw text of a documentation table"""
for l in StringIO(x):
    column, ctype, description = l.split('\t')
    print """"{0}" : {{ prometheus.CounterValue, prometheus.NewDesc("pg_stat_database_{0}", "{2}", nil, nil) }}, """.format(column.strip(), ctype, description.strip())

Adjust the value of the resultant prometheus value type appropriately. This helps build
rich self-documenting metrics for the exporter.

And I cannot find any way to add this Python code. And checked the code, there is no there method to add new metric except Adding new metrics via a config file.

Check the commit, the document comes from the very early commit https://github.com/prometheus-community/postgres_exporter/commit/2a08787a90840a27d10ec519005ff92148055cd1#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R31 looks it means I need to create a new view in PostgreSQL using PL/Python, then add a new metric type in metricMaps and recompile postgres_exporter.

I think this is a document mistake.

Sasasu avatar Sep 20 '24 04:09 Sasasu

I also second this. Adding new metrics via a config file is deprecated but there's no clear guideline as to how we can implement custom queries.

jamius19 avatar Oct 18 '24 10:10 jamius19

I also third this :) Since PG_EXPORTER_EXTEND_QUERY_PATH is deprecated how can we implement custom queries/metrics now?

Is the answer is :

Use this exporter For generic SQL database monitoring see the [sql_exporter](https://github.com/burningalchemist/sql_exporter)

fguiet avatar Oct 25 '24 11:10 fguiet

@fguiet I'm currently using this to good effect. Vonng/pg_exporter

jamius19 avatar Oct 25 '24 15:10 jamius19

Thank you @jamius19 , I will give it a try :)

fguiet avatar Oct 26 '24 09:10 fguiet

I am also looking for way to implement custom metrics since the old way was deprecated. Will there be a replacement implementation with collectors of this feature or do I have to resort to using other collectors? I try to maintain as few different deployments as possible, so a configurable Postgres exporter would be much better for us than another third party tool

RSchindler93 avatar Feb 11 '25 12:02 RSchindler93

Any plans on providing custom metrics at all?

  • the only way to do it right now being documented as deprecated
  • the new metrics documentation is more of a hint for developers
  • users are pointed to another tool that basically does the same as this project, just with built in support for custom metrics

I don't like to say it but it seems like anyone with custom requirements is shied away from the project.

dgeissl avatar Feb 11 '25 12:02 dgeissl

+1

I just installed this tool because I thought it would enable to me to have custom queries, I'm disappointed it's marked as deprecated. Can someone give a hint about an alternative ?

tony-engineering avatar Jul 31 '25 16:07 tony-engineering