Config file throwing errors on every line
What did you do? Installed postgres_exporter on AWS EC2 instance with postgres installed on it.
What did you expect to see? Metrics? And running service
What did you see instead? Under which circumstances?
ts=2023-09-18T08:17:24.266Z caller=main.go:86 level=warn msg="Error loading config" err="Error parsing config file \"/etc/postgres_exporter/postgres_exporter.yml\": yaml: unmarshal errors:\n line 1: field user not found in type config.Config\n line 2: field password not found in type config.Config\n line 3: field host not found in type config.Config\n line 4: field port not found in type config.Config\n line 5: field sslmode not found in type config.Config\n line 6: field queries not found in type config.Config"
ts=2023-09-18T08:17:24.266Z caller=proc.go:250 msg="Excluded databases" databases=[]
ts=2023-09-18T08:17:24.266Z caller=main.go:142 level=warn msg="Failed to create PostgresCollector" err="empty dsn"
ts=2023-09-18T08:17:24.267Z caller=tls_config.go:274 level=info msg="Listening on" address=[::]:9187
ts=2023-09-18T08:17:24.267Z caller=tls_config.go:277 level=info msg="TLS is disabled." http2=false address=[::]:9187```
**Environment**
`Linux`
* System information:
`Linux 5.19.0-1029-aws x86_64`
* postgres_exporter version:
```$ postgres_exporter --version
postgres_exporter, version 0.13.2 (branch: HEAD, revision: 8c3604b85e38ae7141e84ecdc318b6015a196c97)
build user: root@2ea2be721819
build date: 20230724-00:08:19
go version: go1.20.6
platform: linux/amd64
tags: netgo static_build```
* postgres_exporter flags:
$ /usr/local/bin/postgres_exporter --config.file=/etc/postgres_exporter/postgres_exporter.yml
* PostgreSQL version:
`psql (PostgreSQL) 15.3 (Ubuntu 15.3-1.pgdg22.04+1)`
* Logs:
$ sudo systemctl status postgres_exporter × postgres_exporter.service - PostgreSQL Exporter for Prometheus Loaded: loaded (/etc/systemd/system/postgres_exporter.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Mon 2023-09-18 08:21:40 UTC; 678ms ago Process: 1651999 ExecStart=/usr/local/bin/postgres_exporter --config.file=/etc/postgres_exporter/postgres_exporter.yml (code=exited, status=200/CHDIR) Main PID: 1651999 (code=exited, status=200/CHDIR) CPU: 2ms
Sep 18 08:21:40 staging-db2 systemd[1]: postgres_exporter.service: Scheduled restart job, restart counter is at 2. Sep 18 08:21:40 staging-db2 systemd[1]: Stopped PostgreSQL Exporter for Prometheus. Sep 18 08:21:40 staging-db2 systemd[1]: postgres_exporter.service: Start request repeated too quickly. Sep 18 08:21:40 staging-db2 systemd[1]: postgres_exporter.service: Failed with result 'exit-code'. Sep 18 08:21:40 staging-db2 systemd[1]: Failed to start PostgreSQL Exporter for Prometheus.
Fixed the file throwing errors. But still Main PID: 1651999 (code=exited, status=200/CHDIR) remains.
What does your config file look like? The errors seem to indicate a problem with the config file.
What happens when you try to start the exporter from the CLI without systemd?
Sure. I managed to get the file going but I see I don't collect metrics.
Loaded: loaded (/etc/systemd/system/postgres_exporter.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2023-09-19 11:42:39 UTC; 1 day 4h ago
Main PID: 1795362 (postgres_export)
Tasks: 4 (limit: 9507)
Memory: 1.5M
CPU: 115ms
CGroup: /system.slice/postgres_exporter.service
└─1795362 /usr/local/bin/postgres_exporter --config.file=/etc/postgres_exporter/postgres_exporter.yml
Sep 19 11:42:39 staging-db2 systemd[1]: Started PostgreSQL Exporter for Prometheus.
Sep 19 11:42:39 staging-db2 postgres_exporter[1795362]: ts=2023-09-19T11:42:39.359Z caller=main.go:86 level=warn msg="Error loading config" err="Error parsing config file \"/etc/postgres_exporter/postgres_exporter>
Sep 19 11:42:39 staging-db2 postgres_exporter[1795362]: ts=2023-09-19T11:42:39.359Z caller=proc.go:250 msg="Excluded databases" databases=[]
Sep 19 11:42:39 staging-db2 postgres_exporter[1795362]: ts=2023-09-19T11:42:39.359Z caller=main.go:142 level=warn msg="Failed to create PostgresCollector" err="empty dsn"
Sep 19 11:42:39 staging-db2 postgres_exporter[1795362]: ts=2023-09-19T11:42:39.359Z caller=tls_config.go:274 level=info msg="Listening on" address=[::]:9187
Sep 19 11:42:39 staging-db2 postgres_exporter[1795362]: ts=2023-09-19T11:42:39.359Z caller=tls_config.go:277 level=info msg="TLS is disabled." http2=false address=[::]:9187```
That's from systemd status. And that's the config file:
user: postgres password: password host: 172.xx.xx.xx port: 5432 sslmode: disable queries:
- query: "SELECT * FROM pg_stat_activity"
metrics:
- state
- count
We don't support specifying the host in the config file. You may not get metrics because you don't have a DSN specified. The logs still show that the config file is invalid.
Also we don't support having custom queries in the config file. There is a different file you can specify for custom queries although that feature is deprecated.
Can you show me properly working files for config and queries in this scenario then?
The README has an example of the config file here: https://github.com/prometheus-community/postgres_exporter#auth_modules
The queries.yaml file in the repo is now empty because the feature is deprecated. This is the old example: https://github.com/prometheus-community/postgres_exporter/blob/e7f58a42e8040936d7e28f0a99c6823dba7ef6f7/queries.yaml