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:

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:

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:

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:

Last updated