DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Monitoring Spring Boot Applications with Prometheus and Grafana
  • Building a Simple AIOps Monitoring Dashboard With Prometheus and Grafana
  • Grafana Loki Fundamentals and Architecture
  • Operation and Network Administration Management of Telecom 5G Network Functions Using Openshift Kubernetes Tools

Trending

  • How to Format Articles for DZone
  • Building a DevOps-Ready Internal Developer Platform: A Hands-On Guide to Golden Paths, Self-Service, and Automated Delivery Pipelines
  • LLM-Powered Deep Parsing for Industrial Inventory Search
  • Optimizing High-Volume REST APIs Using Redis Caching and Spring Boot (With Load Testing Code)
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Monitoring and Observability
  4. Automated Monitoring With Grafana and Prometheus

Automated Monitoring With Grafana and Prometheus

In this article, I would like to explain a Docker image that I created to keep Grafana dashboards in sync across environments.

By 
Fabio Serragnoli user avatar
Fabio Serragnoli
·
Updated Jan. 29, 19 · Opinion
Likes (3)
Comment
Save
Tweet
Share
12.9K Views

Join the DZone community and get the full member experience.

Join For Free

Depending on the number of environments in which you have monitoring enabled, it may be cumbersome to keep all your Grafana dashboards synchronized across environments when changes occur.

In this article, I would like to show a Docker image I created to keep Grafana dashboards in sync across environments.

What's in the Image

  • Prometheus.
  • Grafana.
  • Supervisor.

How to Use It

With all options:

docker run --name automated-grafana -d -p 9090:9090 -p 6666:6666 \
       -e "ENVIRONMENT=prod" \
       -e "GF_SERVER_HTTP_PORT=6666" \
       -e "WAITING_TIME=20" \
       -v `pwd`/prometheus-config:/prometheus-config \
       -v `pwd`/dashboards:/dashboards \
       -v `pwd`/users:/users \
       -v `pwd`/sources:/sources \
       serragnoli/automated-grafana-prometheus


  • -p 9090:9090: Exposes the Prometheus default port to the host.

  • -p 6666:6666: Exposes a custom Grafana port that was determined by -e "GF_SERVER_HTTP_PORT=6666"; both of these parameter values need to match.
  • -e "ENVIRONMENT=prod": Determines which Prometheus config to use. Ensure that a prometheus-<env> .yml suffixed with the environment where you'll deploy to exists in the directory. In this example, the value is prod and /prometheus-config/prometheus-prod.yml is expected to exist.
  • -e "WAITING_TIME=20": By default, each JSON file is loaded 10 seconds apart from each other. There may be situations that 10 seconds may be too much or too little time. When that's the case, use this variable to control the interval of loading each JSON file.
  • -v `pwd`/dashboards:/dashboards
    -v `pwd`/users:/users
    -v `pwd`/sources:/sources
    : Map the directories containing the JSON files to be loaded by Grafana in the container. It's worth mentioning that the /dashboards directory must only contain dashboard JSON files and the same applies to the other directories.

After running the above command, you should have Prometheus running on localhost:9090 and Grafana running on localhost:6666.

Advantages

  • You can run the same image everywhere; just use a Prometheus config file that points to /metrics endpoints for the environment you're deploying to.
  • You can load as many dashboards, users, and data-source JSON files as you want by only mapping the directories that contain these files from the host to the container.
  • You get fewer moving parts in your monitoring system. Therefore, there are fewer things to worry about, i.e. lost/slow network connectivity between Prometheus and Grafana.

Disadvantages

  • Difficulty to scale each component individually as they are in the same container;
  • Breaking the Docker rule of thumb one process per Docker container.

Final Considerations

I've added sample JSON files to the image page in DockerHub: dashboard.json, user.json, and data-source.json.

I can't tell if I have tried to reinvent the wheel with this image, but the fact is that I couldn't find anything already automating Grafana dashboards in the same way.

As I mentioned above, this is currently my favorite solution and if I learn a better way of doing it, I'll update this article.

Grafana

Opinions expressed by DZone contributors are their own.

Related

  • Monitoring Spring Boot Applications with Prometheus and Grafana
  • Building a Simple AIOps Monitoring Dashboard With Prometheus and Grafana
  • Grafana Loki Fundamentals and Architecture
  • Operation and Network Administration Management of Telecom 5G Network Functions Using Openshift Kubernetes Tools

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook