Configure Grafana Alloy for PostgreSQL monitoring

In this milestone, you configure Grafana Alloy using the configuration snippets provided by the PostgreSQL integration. These snippets enable Grafana Alloy to collect PostgreSQL metrics and logs and send them to your Grafana Cloud instance.

The configuration includes components for PostgreSQL metrics collection using the Prometheus PostgreSQL exporter component and log collection using Loki source file components. You’ll customize the configuration with your PostgreSQL connection details and ensure secure credential handling.

To configure Grafana Alloy for PostgreSQL monitoring, complete the following steps:

  1. On the PostgreSQL integration page in Grafana Cloud, scroll to the Set up Grafana Alloy to use the PostgreSQL integration section.

  2. At the bottom of the snippet, click Copy to clipboard.

  3. Open the Grafana Alloy configuration file on your system.

    For example, on a Linux machine, run:

    sudo nano /etc/alloy/config.alloy
  4. Paste the integration snippet into the configuration file.

  5. Update the data_source_names parameter with your PostgreSQL connection details:

    Replace the placeholder postgresql://localhost:5432/postgres with your actual connection string.

    For example, use postgresql://alloy_monitor:secure_password@localhost:5432/postgres.

  6. Review the log path in the logs configuration and update it if necessary:

    • For Linux systems, the default path is /var/log/postgresql/postgres.log.
    • For macOS systems, the default path is /var/log/postgresql/postgres.log.
    • For Windows systems, the default path is C:\\Program Files\\PostgreSQL\\*\\data\\pg_log.
  7. Save the configuration file and exit the editor.

  8. Restart the Grafana Alloy service to apply the configuration:

    On a Linux machine, run:

    sudo systemctl restart alloy
  9. Check the service status to ensure it started successfully:

    On a Linux machine, run:

    sudo systemctl status alloy

The Grafana Alloy service should restart successfully and begin collecting PostgreSQL metrics and logs based on your configuration.

In the next milestone, you test the connection to verify that data is being collected and sent to Grafana Cloud.

More to explore (optional)

At this point in your journey, you can explore the following paths:

Grafana Alloy configuration reference


page 6 of 10