# Pushing Metrics in Self-Hosted Grafana Instances

To push metrics to a self-hosted Grafana instance, you will need to configure a Prometheus server to scrape metrics and set up a Grafana data source to connect to the server. This example demonstrates how to create both the Prometheus server and Grafana instance on a single Docker container.

### Step 1. Configure Prometheus and Grafana Services

**a. Create the Prometheus Configuration.** Create a file named prometheus.yml to define the endpoints to scrape and the basic authentication details.

***Example configuration:***

```yaml
scrape_configs:
  - job_name: 'vgs'
    static_configs:
        - targets: ['metrics.apps.verygood.systems']
    metrics_path: /vaults/tntasd123/api/metrics
    scheme: https
    basic_auth:
      username: prometheus
      password: hunter2
```

**b. Create the Docker Compose Configuration.** Create a file named `docker-compose.yml` to configure the Prometheus server and Grafana instance.

***Example configuration:***

```yaml
services:
  prometheus:
    image: prom/prometheus
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml
    ports:
      - "9090:9090"
  grafana:
    image: grafana/grafana
    ports:
      - "3000:3000"
    depends_on:
      - prometheus
```

### Step 2. Start the Services

Run the following command in the directory containing the configuration files to start both services:

```bash
docker-compose up -d
```

### Step 3. Set Up a Prometheus Data Source in Grafana

* Log in to the Grafana instance (Default credentials: **Username**: `admin` / **Password**: `admin`).
* From the homepage, navigate to **Data Sources** in the side menu.
* Click **Add data source** and search for **Prometheus**.
* Under the **Connection** section, set the URL to the Prometheus instance: `http://prometheus:9090` in this example
* Click **Save & Test** to verify the connection.

### Step 4. Explore Your Metrics

With the Prometheus server and Grafana instance now connected, you can begin exploring metrics directly in Grafana. Use the **Explore** section or create custom dashboards to visualize your data.

### 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/latest/datasources/prometheus/configure-prometheus-data-source/)


---

# 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-in-self-hosted-grafana-instances.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.
