postgres_exporter icon indicating copy to clipboard operation
postgres_exporter copied to clipboard

Adding new metrics via a config file problem

Open hunterhuang8810 opened this issue 3 years ago • 2 comments

Hi Team,

From doc I see we can add new metrics via config file: Adding new metrics via a config file The -extend.query-path command-line argument specifies a YAML file containing additional queries to run. Some examples are provided in queries.yaml.

so I I try to test adding below metric pg_hunter in my queries.yaml:

pg_replication: query: "SELECT CASE WHEN NOT pg_is_in_recovery() THEN 0 ELSE GREATEST (0, EXTRACT(EPOCH FROM (now() - pg_last_xact_replay_timestamp()))) END AS lag" master: true metrics: - lag: usage: "GAUGE" description: "Replication lag behind master in seconds"

pg_hunter: query: "SELECT 8888,9999" master: true metrics: - metri01: usage: "GAUGE" description: "hunter metric01" - metri02: usage: "GAUGE" description: "hunter metric02"

pg_postmaster: query: "SELECT pg_postmaster_start_time as start_time_seconds from pg_postmaster_start_time()" master: true metrics: - start_time_seconds: usage: "GAUGE" description: "Time at which postmaster started"

And when I try to start postgres_exporter, it failed. Can't I add new metrics like above? how to do that?

[root@localhost postgres_exporter-0.9.0.linux-amd64]# ./postgres_exporter --extend.query-path queries.yaml INFO[0000] Starting Server: :9187 source="postgres_exporter.go:1850" INFO[0000] Established new database connection to "127.0.0.1:54322". source="postgres_exporter.go:983" INFO[0000] Semantic Version Changed on "127.0.0.1:54322": 0.0.0 -> 12.5.0 source="postgres_exporter.go:1552" panic: "pg_hunter_?column?" is not a valid metric name

goroutine 17 [running]: github.com/prometheus/client_golang/prometheus.MustNewConstMetric(...) /go/pkg/mod/github.com/prometheus/[email protected]/prometheus/value.go:107 main.queryNamespaceMapping(0xc00008aa50, 0xc00017c650, 0x9, 0x0, 0x0, 0x0, 0xc0001c0930, 0x1, 0x0, 0x0, ...) /app/cmd/postgres_exporter/postgres_exporter.go:1443 +0x2c2a main.queryNamespaceMappings(0xc0000575c0, 0xc00008aa50, 0x0) /app/cmd/postgres_exporter/postgres_exporter.go:1495 +0x80f main.(*Server).Scrape(0xc00008aa50, 0xc0000575c0, 0xc00008aa00, 0x0, 0x0) /app/cmd/postgres_exporter/postgres_exporter.go:1035 +0xac main.(*Exporter).scrapeDSN(0xc00008a9a0, 0xc0000575c0, 0xc000028061, 0x37, 0x5, 0x1) /app/cmd/postgres_exporter/postgres_exporter.go:1728 +0x147 main.(*Exporter).scrape(0xc00008a9a0, 0xc0000575c0) /app/cmd/postgres_exporter/postgres_exporter.go:1618 +0x134 main.(*Exporter).Collect(0xc00008a9a0, 0xc0000575c0) /app/cmd/postgres_exporter/postgres_exporter.go:1259 +0x39 github.com/prometheus/client_golang/prometheus.(*Registry).Gather.func1() /go/pkg/mod/github.com/prometheus/[email protected]/prometheus/registry.go:448 +0x169 created by github.com/prometheus/client_golang/prometheus.(*Registry).Gather /go/pkg/mod/github.com/prometheus/[email protected]/prometheus/registry.go:538 +0xe8e [root@localhost postgres_exporter-0.9.0.linux-amd64]#

hunterhuang8810 avatar Mar 05 '21 09:03 hunterhuang8810

It's failing on the metric that has no column names. ?column? is the column name that postgres gives when you run a bare select statement like that

# SELECT 8888,9999;
 ?column? | ?column? 
----------+----------
     8888 |     9999

If you either give those columns an alias and reference it like you did your other metrics, it should work fine. Or remove that hunter metric and it should work fine.

keithf4 avatar Mar 05 '21 16:03 keithf4

OK , thanks

Is there doc to reference all the default metrics for postgres_exporter? seems most metrics is accumulative, but under many scenarios, delta metrics more helpful

hunterhuang8810 avatar Mar 08 '21 07:03 hunterhuang8810