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

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Grafana Loki Fundamentals and Architecture
  • Operation and Network Administration Management of Telecom 5G Network Functions Using Openshift Kubernetes Tools
  • OpenTelemetry's Impact on Observability: Insights From Grafana Labs' Juraci Paixão Kröhling
  • Performance Optimization in Agile IoT Cloud Applications: Leveraging Grafana and Similar Tools

Trending

  • Testing SingleStore's MCP Server
  • Integrating Security as Code: A Necessity for DevSecOps
  • Unlocking the Potential of Apache Iceberg: A Comprehensive Analysis
  • Measuring the Impact of AI on Software Engineering Productivity
  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.6K 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

  • Grafana Loki Fundamentals and Architecture
  • Operation and Network Administration Management of Telecom 5G Network Functions Using Openshift Kubernetes Tools
  • OpenTelemetry's Impact on Observability: Insights From Grafana Labs' Juraci Paixão Kröhling
  • Performance Optimization in Agile IoT Cloud Applications: Leveraging Grafana and Similar Tools

Partner Resources

×

Comments

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

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: