# 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 metric**s, 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.

```yaml
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:***

```yaml
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:

```bash
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:

* [Configure the Prometheus data source](https://grafana.com/docs/grafana-cloud/connect-externally-hosted/data-sources/prometheus/configure/)
* [metrics\_config | Grafana Agent documentation](https://grafana.com/docs/agent/latest/static/configuration/metrics-config/)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.verygoodsecurity.com/enterprise-platform/core-platform-services/observability/accessing-vgs-metrics-via-prometheus-api/pushing-metrics-to-grafana-cloud.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
