Now that we have started postgres_exporter on the Postgres server, we should tell Prometheus to collect the metrics and store them on the Prometheus database in regular intervals (defaults to 15 seconds). In this recipe, we shall see how the metrics being exposed by the Postgres exporter are collected by Prometheus on the monitoring server.
Getting ready
In order to add a collection of metrics, postgres_exporter must be started in the Postgres server. Additionally, the port on which the metrics are being exposed must be open for the Prometheus server. Else, the metrics cannot be stored or collected in regular intervals by Prometheus.
How to do it...
We will collect and store the metrics as follows:
- Add the Postgres server and the port used by postgres_exporter as a target to the prometheus.yml file:
- targets: ['192.168.29.20:9187']
scrape_configs, after adding node_exporter and postgres_exporter, looks like the following...