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:
Log into your Cloud Portal and select your stack.
Click the name of your stack under Grafana Cloud located on the left navigation panel.
On the Prometheus tile, click Send Metrics.
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.
Just below the code sample, click Generate now to generate an API token.
The API token ensures a secure connection to Grafana Cloud.
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.
On the Create an API token screen, click Close.
Just below the code snippet, click Copy to clipboard.
In the following steps, you’ll add the code snippet to the
prometheus.yml
file.Log into the machine on which Prometheus is installed.
Open a terminal and if required, switch to a user with write privileges.
For example:
sudo su -
Open the
prometheus.yml
file located under/etc/prometheus
.For example, if you are using Vim, run
vim /etc/prometheus/prometheus.yml
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.
Scroll to the end of the file and paste the snippet of code you copied from the Grafana Cloud Portal.
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.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.
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
orjournalctl
.
In the next stop in your journey, you’ll verify that Prometheus is sending metrics to Grafana Cloud.
Troubleshooting options
Please tell us what didn't work:
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