paint-brush
How to Set Up Docker Compose For Prometheus + Grafanaby@neenadingole
25,912 reads
25,912 reads

How to Set Up Docker Compose For Prometheus + Grafana

by Neenad IngoleFebruary 7th, 2023
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Prometheus + Grafana is a docker-compose setup for testing end-to-end. I am using it to send telemetry data from my Golang web application to Prometheus and then create a GraFana dashboard out of it. If you also need a similar setup and save your setup time in future refer to this post or my Github Repository.
featured image - How to Set Up Docker Compose For Prometheus + Grafana
Neenad Ingole HackerNoon profile picture

With all the tools you have in production, it’s important that you can effortlessly test the user flows end-to-end, locally. The rationale behind such is the reduced feedback cycle that saves a developer a lot of time to achieve the desired outcome.


I was working on sending some telemetry data from my Golang web application to Prometheus, and then creating a Grafana dashboard out of it. But to test the flow, I needed a local setup of Prometheus + Grafana to check if the metrics were correct, and that I was building the right PromQL query to create the dashboard.


I am maintaining a Github repo for all the docker-compose setups I require for my local testing, with Prometheus + Grafana being a new addition to it. If you need a similar setup, refer to this post or my Github Repository and save your setup time to focus more on building things.


Clone the repo: https://github.com/ninadingole/docker-images


Then go to prometheus-grafana folder and run docker-compose up -d.

This will start Prometheus on http://localhost:9090 and Grafana on http://localhost:3000.


Prometheus running on localhost:9090


There is also a prometheus.yml, the configuration file which you can use to add the local apps that you want to scrape.


Note: if your application is running inside a docker, then use host.docker.internal as your hostname with the port to scrape the target.

global:
  scrape_interval:     15s
  evaluation_interval: 15s

rule_files:
  # - "first.rules"
  # - "second.rules"

scrape_configs:
  - job_name: prometheus
    static_configs:
      - targets: ['localhost:9090']
  - job_name: app
    scrape_interval: 5s
    static_configs:
      - targets: ['host.docker.internal:10088']


Grafana settings to connect to local Prometheus


Once you have added the configs to connect Grafana to Prometheus like the image above, you are ready with an end-to-end setup on your local.


If you also have your own docker-compose stack setups that you use during your development, please don't hesitate to share with me by sending me a PR to the repository.


I hope you will find this docker-compose configuration useful and time saving. Please subscribe to the newsletter to get more articles delivered right to your inbox.


Thanks and Happy Coding!

Reference