Grafana Dashboard Creation
Introduction
Grafana is a powerful open-source visualization tool that pairs perfectly with Prometheus to create interactive, dynamic dashboards for your metrics. While Prometheus provides the data collection and storage, Grafana transforms this data into visually appealing, informative dashboards that make monitoring your systems intuitive and effective.
In this guide, you'll learn how to create Grafana dashboards for visualizing Prometheus metrics. We'll cover everything from setting up your first dashboard to creating complex panels and organizing them effectively.
Prerequisites
Before starting with Grafana dashboard creation, ensure you have:
- A running Prometheus server collecting metrics
- Grafana installed and configured
- Prometheus configured as a data source in Grafana
If you haven't set these up yet, please refer to our previous sections on [Prometheus Installation] and [Grafana Setup].
Basic Dashboard Creation
Accessing the Grafana Interface
First, let's access the Grafana web interface:
- Open your web browser and navigate to your Grafana instance (typically
http://localhost:3000
if running locally) - Log in with your credentials (default: admin/admin)
- You'll be directed to the Grafana home dashboard
Creating Your First Dashboard
Let's create a new dashboard to visualize Prometheus metrics:
- Click the "+" icon in the left sidebar
- Select "Dashboard" from the dropdown menu
- Click "Add new panel"
At this point, you'll see the panel edit view where you can configure your visualization.
Adding Your First Panel
Panels are the building blocks of Grafana dashboards. Here's how to create your first panel:
1. In the query editor, select "Prometheus" as your data source
2. Enter a PromQL query in the query field, for example:
rate(node_cpu_seconds_total{mode="user"}[1m])
3. Select the visualization type from the right side (Graph, Gauge, etc.)
4. Click "Apply" to add the panel to your dashboard
5. Click the disk icon or press Ctrl+S to save your dashboard
Here's an example of a simple CPU usage panel configuration:
Data Source: Prometheus
Query: sum by (instance) (rate(node_cpu_seconds_total{mode!="idle"}[1m])) / count by (instance) (node_cpu_seconds_total{mode="system"})
Legend: {{instance}} - CPU Usage
Visualization: Time series
This query shows the CPU usage percentage across all your monitored instances.
Understanding Panel Types
Grafana offers various visualization types for different use cases:
Time Series
The most common visualization type, perfect for showing how metrics change over time.
Example Query: rate(http_requests_total[5m])
Use Case: Tracking request rates, CPU usage, memory consumption over time
Gauge
Ideal for showing a single value within a range, like percentage of disk used.
Example Query: (node_filesystem_avail_bytes / node_filesystem_size_bytes) * 100
Use Case: Disk space usage, CPU utilization percentage
Stat
Shows a single big number with optional sparkline, perfect for key performance indicators.
Example Query: sum(up)
Use Case: Number of online instances, total error count
Bar Gauge
Displays values as a gradient bar, useful for comparing multiple values.
Example Query: sum by(job) (up)
Use Case: Service health across multiple jobs
Table
Shows raw data in tabular format.
Example Query: topk(10, http_requests_total)
Use Case: Top 10 endpoints by request count
Advanced Dashboard Features
Now let's explore some more advanced features to enhance your dashboards.
Variables and Templates
Variables make your dashboards dynamic and interactive:
- Click the dashboard settings icon (gear) in the top right
- Select "Variables" from the left menu
- Click "Add variable"
Here's an example of setting up an instance variable:
Name: instance
Label: Instance
Type: Query
Data source: Prometheus
Query: label_values(node_exporter_build_info, instance)
You can now use this variable in your queries with $instance
:
node_memory_MemAvailable_bytes{instance="$instance"} / node_memory_MemTotal_bytes{instance="$instance"} * 100
This allows users to switch between different instances from a dropdown menu.
Dashboard Annotations
Annotations allow you to mark points in time on your graphs:
- Go to Dashboard settings > Annotations
- Click "Add Annotation Query"
- Configure a Prometheus query that returns events
Example annotation query:
changes(process_start_time_seconds{job="prometheus"}[1m]) > 0
This will mark points in time when Prometheus was restarted.
Organizing Panels with Rows
For complex dashboards, organize panels into collapsible rows:
- Hover over the dashboard
- Click "Add panel" (+ icon)
- Select "Add a new row"
- Drag panels into the row
- Click the arrow on the row header to collapse/expand
Dashboard Time Range Controls
Grafana provides powerful time range controls:
- Use the time picker in the top right to select predefined ranges
- Drag on a graph to zoom into a specific time period
- Hold Shift and drag to pan through time
Real-World Example: Application Monitoring Dashboard
Let's create a practical dashboard for monitoring a web application:
- Create a new dashboard
- Add a row titled "Application Health"
- Add these panels:
Request Rate Panel:
Query: sum(rate(http_requests_total[5m])) by (route)
Visualization: Time series
Title: HTTP Request Rate
Error Rate Panel:
Query: sum(rate(http_requests_total{status=~"5.."}[5m])) / sum(rate(http_requests_total[5m])) * 100
Visualization: Time series
Title: Error Rate %
Thresholds: 1=yellow, 5=red
Response Time Panel:
Query: histogram_quantile(0.95, sum(rate(http_request_duration_seconds_bucket[5m])) by (le, route))
Visualization: Time series
Title: 95th Percentile Response Time
Active Users Panel:
Query: sum(active_users)
Visualization: Stat
Title: Active Users
- Add another row titled "System Resources"
- Add system resource panels (CPU, Memory, Disk, Network)
This creates a comprehensive dashboard that monitors both application metrics and system resources.
Creating Multi-Service Dashboards
For monitoring multiple services:
- Set up variables for filtering by service:
Name: service
Type: Query
Query: label_values(up, job)
- Create panels using the variable:
Query: sum(rate(http_requests_total{job="$service"}[5m])) by (status)
Title: $service Request Rate by Status
- Duplicate panels for different metrics but the same services
This approach lets you monitor all your services from a single dashboard.
Sharing and Exporting Dashboards
Grafana dashboards can be easily shared and reused:
- To export: Dashboard settings > JSON Model > Copy to clipboard
- To import: + > Import > Paste JSON
- To share: Click "Share" in the top menu for link or snapshot options
Best Practices for Dashboard Design
When creating Grafana dashboards, follow these best practices:
- Keep it simple: Start with essential metrics and add complexity as needed
- Use consistent naming: Maintain a naming convention for panels and dashboards
- Group related metrics: Use rows to organize panels by service or function
- Set appropriate thresholds: Configure alerts and color thresholds to highlight issues
- Add documentation: Include text panels explaining dashboard purpose and panel meanings
- Use templates: Make dashboards reusable with variables instead of hardcoded values
- Consider performance: Too many complex queries can slow down dashboard loading
Troubleshooting Common Issues
No Data Displayed
If your panel shows "No data":
- Check that Prometheus is running and accessible
- Verify your PromQL query in Prometheus' web UI
- Check time range settings in Grafana
- Ensure metric names and label filters are correct
Dashboard is Slow
If your dashboard loads slowly:
- Reduce the number of panels or queries
- Optimize complex PromQL queries
- Increase your browser's memory limits
- Consider using recording rules in Prometheus for complex queries
Summary
In this guide, you've learned how to:
- Create basic Grafana dashboards for Prometheus metrics
- Work with different panel types for various visualization needs
- Use advanced features like variables, annotations, and rows
- Build practical, real-world monitoring dashboards
- Apply best practices for dashboard design
Grafana dashboards are powerful tools for visualizing your Prometheus metrics. With the knowledge from this guide, you can create effective, informative dashboards that help you monitor your systems and applications with ease.
Additional Resources
To continue learning about Grafana dashboards:
- Explore the official Grafana documentation
- Try the Grafana Play site for examples
- Experiment with Grafana dashboard templates
Exercises
- Create a dashboard showing system metrics (CPU, memory, disk, network) for your servers
- Build a dashboard for monitoring a specific application with request rates, errors, and latencies
- Create a variable that allows filtering by environment (prod, staging, dev)
- Set up annotations to mark deployment events on your dashboards
- Export your dashboard and share it with a colleague
Remember, the best way to learn is by doing. Start building your own dashboards, experiment with different visualizations, and discover what works best for your specific monitoring needs.
If you spot any mistakes on this website, please let me know at [email protected]. I’d greatly appreciate your feedback! :)