Pushing Metrics to Grafana Cloud

To push metrics to Grafana Cloud via an agent, you must set up a Prometheus connection and configure the Grafana Agent. Follow the steps below:

Step 1: Create a Prometheus Connection

  • Log in to your Grafana Cloud account.

  • From the homepage, click Connections in the left-side menu.

  • Under Connections, click Add new connection.

  • Select Hosted Prometheus metrics.

  • Under Choose a method for forwarding metrics, select From my local Prometheus server.

  • Under Choose your use case for forwarding metrics, select Send metrics from a single Prometheus instance.

  • Under Select how to send the metrics from Prometheus to Grafana Cloud, select Directly.

  • Under Update Prometheus configuration, create a new token. Save the generated prometheus.yml snippet to your clipboard for later use (this will be needed to configure the agent).

Within the remote_write section, you can specify any Prometheus-compatible server endpoint to send data there.

global:
  scrape_interval: 60s
remote_write:
  - url: https://my-prometheus-connection.grafana.net/api/prom/push
    basic_auth:
      username: my-grafana-username
      password: my-grafana-password
scrape_configs:
  - job_name: node
    static_configs:
      - targets: ["localhost:9090"]

Step 2. Configure the Grafana Agent

Create a file named agent-config.yml. This file will define the Prometheus endpoints to scrape and the basic authentication details.

1. Example configuration:

server:
  log_level: info

metrics:
  configs:
    - name: example-metrics-config
      scrape_configs:
        - job_name: 'tntasd123' # This can be any value but your vgs Vault ID is a clear choice
          static_configs:
            - targets: ['metrics.apps.verygood.systems']
          metrics_path: /vaults/tntasd123/api/metrics # note, your Vault ID must be added to the path
          scheme: https
          basic_auth:
            username: prometheus
            password: hunter2
      remote_write: # Paste the Prometheus connection configuration from the previous step
        - url: 'https://my-prometheus-connection.grafana.net/api/prom/push'
          basic_auth:
            username: my-grafana-username
            password: my-grafana-password

Step 3. Start the Grafana Agent in Docker

Run the following command to start the Grafana Agent in a Docker container. Replace path/to/your/agent-config.yml with the correct path to your configuration file:

docker run -d --name grafana-agent \
  -v path/to/your/agent-config.yml:/etc/agent/agent.yaml \
  grafana/agent:latest

Step 4. Verify Metrics in Grafana Cloud

Once the Docker container is running, the Grafana Agent will begin scraping metrics and pushing them to your Grafana Cloud account. You can verify this by checking the metrics in your Grafana dashboard.

Further Reading

For more information on integrating Prometheus metrics with Grafana, check out these resources:

Last updated