Vonng / pg_exporter

Advanced PostgreSQL & Pgbouncer Metrics Exporter for Prometheus
https://pigsty.io
Apache License 2.0
164 stars 42 forks source link

Add option to test selected metric(s) and also options to select metric(s) to test, explain and configuration dump #27

Open mjf opened 2 years ago

mjf commented 2 years ago

Hello. I suggest to add

Flags
       [...]

       --test
           Testing run (single pass run returning collected '/metrics' to the standard output to be revised).
           To limit the test run to a certain list of metrics use the '-M' option.

       -M, --metrics LIST
           Limit testing run (see the '--test' option) to a list of comma (',') separated metric names.
           Only the SQL queries of the selected metrics will be run (eg. '--test --metrics pg_up,pg_uptime'
           will run the SQL queries of the 'pg_up' and 'pg_uptime' metrics).

       [...]

I also suggest to apply --metrics LIST to --explain similarly, if possible.

The --dry-run option should not produce any output instead of eg. warnings or errors etc. In fact, it must not even try to perform the connection to the Postgres etc. Therefor it's "dry run" (!) and everybody expects that it does literally nothing, no real action (which connection certainly is).

To dump the actual configuration I suggest to provide another option, say --show-config, --dump-config or --format-config or similar and to apply --metrics LIST to it as well.

That way you could easily

  1. see what's configured for certain metric (eg. --show-config -M pg_up);
  2. check if there is no error or discrepancy in the configuration (eg. --dry-run);
  3. test the metric of interest (eg. --test -M pg_up).

The exporter should return proper exit codes so that these features could be used in scripts etc.

Whether to provide also environment variables for the suggested options remains a question. I generally do not see any point in not doing so (it could be good for container users who tend to use environment variables).


I think all these things are somewhat related one to each other so I aggregated them in this single feature request, sorry for that.

Vonng commented 2 years ago

That would be a great feature for testing & introspection. Maybe I could have some draft implementation in next release