Configure Prometheus remote write to send metrics to Grafana Cloud

In this step of the journey you’ll update a YAML file in your Prometheus installation with a snippet of code taken from your Grafana Cloud Portal account. The snippet of code provides Prometheus with the URL of the Grafana Cloud metrics instance and credentials for sending metrics.

To configure Prometheus to remote write to Grafana Cloud, complete the following steps:

  1. Log into your Cloud Portal and select your stack.

    Image of stack selected in the Grafana Cloud Portal

  2. Click the name of your stack under Grafana Cloud located on the left navigation panel.

  3. On the Prometheus tile, click Send Metrics.

  4. Scroll down the page until you locate the Sending metrics with Prometheus section.

    This section contains a snippet of code that you’ll add to your Prometheus deployment.

  5. Just below the code sample, click Generate now to generate an API token.

    The API token ensures a secure connection to Grafana Cloud.

    Picture of Generate now link to create API token

  6. On the Create an API token screen, enter a name for the token and click Create token.

    The code snippet populates with the token you just created.

  7. On the Create an API token screen, click Close.

  8. Just below the code snippet, click Copy to clipboard.

    In the following steps, you’ll add the code snippet to the prometheus.yml file.

  9. Log into the machine on which Prometheus is installed.

  10. Open a terminal and if required, switch to a user with write privileges.

    For example: sudo su -

  11. Open the prometheus.yml file located under /etc/prometheus.

    For example, if you are using Vim, run vim /etc/prometheus/prometheus.yml

  12. Edit the YAML file.

    When using Vi or Vim as the text editor, press i to edit the YAML file.

    The button you use to the edit the YAML file depends on the text editor you are using.

  13. Scroll to the end of the file and paste the snippet of code you copied from the Grafana Cloud Portal.

  14. Exit edit mode and save your changes.

    For example, when using Vi or Vim, press the Esc key to exit insert mode type :wq to save your changes and exit.

  15. Restart the Prometheus service to apply the changes.

    For example: run the commend systemctl restart prometheus.yml

    After restarting the Prometheus service, metrics should be forwarded to Grafana Cloud.

  16. To check the Prometheus service status, run the following command:

    systemctl status prometheus.service

    If there are errors, refer to the relevant logs in /var/log/syslog or journalctl.

In the next stop in your journey, you’ll verify that Prometheus is sending metrics to Grafana Cloud.

Were you successful?

More to explore (optional)

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

Send data from multiple Prometheus instances

Send data from multiple high-availability Prometheus instances