Grafana Dashboards

Dashboards are the primary way to visualize your metrics, logs, and traces in Grafana. This guide covers creating dashboards, configuring panels, using variables, and best practices for effective monitoring visualizations.

What are Dashboards?

Dashboards are collections of panels that visualize your data:

  • Organized views - Group related metrics together
  • Interactive - Zoom, pan, refresh, filter
  • Customizable - Full control over layout and styling
  • Shareable - Export/import dashboards as JSON
graph TB A[Dashboard] --> B[Panels] B --> C[Graph] B --> D[Table] B --> E[Stat] B --> F[Gauge] C --> G[PromQL Query] D --> G E --> G F --> G G --> H[Data Source] H --> I[Prometheus] H --> J[Loki] H --> K[Other Sources] A --> L[Variables] A --> M[Annotations] style A fill:#e1f5ff style B fill:#e8f5e9 style G fill:#fff4e1 style L fill:#f3e5f5

Creating a Dashboard

Basic Workflow

  1. Go to Dashboards in Grafana
  2. Click New Dashboard or + New
  3. Click Add visualization or Add panel
  4. Select data source
  5. Write query
  6. Choose visualization type
  7. Configure panel options
  8. Click Apply
  9. Click Save dashboard

Creating Your First Dashboard

Step 1: Create New Dashboard

  • Click DashboardsNew Dashboard
  • Or use shortcut: Ctrl+N (Cmd+N on Mac)

Step 2: Add Panel

  • Click Add visualization
  • Select data source (e.g., Prometheus)

Step 3: Write Query

# Example: CPU usage
100 - (avg(irate(container_cpu_usage_seconds_total[5m])) * 100)

Step 4: Choose Visualization

  • Select Time series or Graph
  • Configure display options

Step 5: Save

  • Click Apply
  • Click Save dashboard
  • Enter dashboard name and folder

Panel Types

Time Series (Graph)

Visualize metrics over time:

# CPU usage over time
rate(container_cpu_usage_seconds_total[5m]) * 100

# Memory usage over time
container_memory_usage_bytes / container_spec_memory_limit_bytes * 100

Configuration:

  • Query: PromQL query
  • Legend: Customize legend display
  • Axes: Configure X and Y axes
  • Display: Line styles, colors, thresholds

Table

Display data in tabular format:

# Pod CPU usage table
sum by (pod) (rate(container_cpu_usage_seconds_total[5m]))

Configuration:

  • Query: PromQL query
  • Column styles: Format columns
  • Sorting: Default sort column
  • Pagination: Rows per page

Stat

Display single value or gauge:

# Total requests
sum(rate(http_requests_total[5m]))

Configuration:

  • Value options: Unit, decimals, thresholds
  • Display: Color mode, graph mode
  • Text size: Font sizes

Gauge

Circular or linear gauge:

# CPU usage percentage
100 - (avg(irate(container_cpu_usage_seconds_total[5m])) * 100)

Configuration:

  • Gauge options: Mode (gauge, threshold)
  • Thresholds: Color zones
  • Value options: Unit, decimals

Other Panel Types

  • Bar chart - Horizontal/vertical bars
  • Heatmap - Color-coded matrix
  • Histogram - Distribution visualization
  • Logs - Log viewer panel
  • Node graph - Service dependency graph
  • Traces - Distributed trace visualization

PromQL Queries in Panels

Basic Queries

# Single metric
http_requests_total

# With label filter
http_requests_total{method="GET"}

# Rate calculation
rate(http_requests_total[5m])

# Aggregation
sum by (pod) (rate(container_cpu_usage_seconds_total[5m]))

Common Query Patterns

# CPU usage percentage
100 - (avg(irate(container_cpu_usage_seconds_total[5m])) * 100)

# Memory usage percentage
(container_memory_usage_bytes / container_spec_memory_limit_bytes) * 100

# Request rate
rate(http_requests_total[5m])

# Error rate
rate(http_requests_total{status=~"5.."}[5m])

# Availability
avg(up) * 100

# Pod restart count
increase(kube_pod_container_status_restarts_total[1h])

Using Variables in Queries

# Using $namespace variable
rate(http_requests_total{namespace="$namespace"}[5m])

# Using $pod variable
rate(http_requests_total{namespace="$namespace", pod="$pod"}[5m])

# Multiple variable selection
rate(http_requests_total{namespace=~"$namespace", pod=~"$pod"}[5m])

Dashboard Variables

Variables make dashboards dynamic and reusable.

Creating Variables

  1. Click Dashboard settings (gear icon)
  2. Go to Variables
  3. Click Add variable
  4. Configure variable:
    • Name: Variable name (used in queries)
    • Type: Query, Custom, etc.
    • Label: Display name
    • Query: Data source query

Variable Types

Query Variable

Populate from data source:

# Namespaces
label_values(kube_pod_info, namespace)

# Pods
label_values(kube_pod_info{namespace="$namespace"}, pod)

# Services
label_values(kube_service_info, service)

Configuration:

  • Data source: Prometheus
  • Query: label_values(metric, label)
  • Multi-value: Allow multiple selections
  • Include all: Add “All” option

Custom Variable

Manual list of values:

production, staging, development

Text Variable

Free text input:

  • Type: Text
  • Default value: Default text
  • Allow custom value: Allow users to enter custom values

Using Variables

In queries:

rate(http_requests_total{namespace="$namespace"}[5m])

In panel titles:

CPU Usage - $namespace

In links:

/dashboard/db/my-dashboard?namespace=$namespace

Example: Namespace Variable

# Variable configuration
name: namespace
type: query
datasource: Prometheus
query: label_values(kube_pod_info, namespace)
multi: false
includeAll: true

Use in query:

sum by (pod) (rate(container_cpu_usage_seconds_total{namespace="$namespace"}[5m]))

Organizing Dashboards

Folders

Organize dashboards in folders:

  1. Create folder: Dashboards → New Folder
  2. Move dashboard: Dashboard settings → General → Move to folder
  3. Permissions: Set folder-level permissions

Example structure:

📁 Production
  ├── Kubernetes Cluster
  ├── Applications
  └── Infrastructure
📁 Staging
  ├── Kubernetes Cluster
  └── Applications

Tags

Tag dashboards for easier discovery:

  • Click Dashboard settingsGeneral
  • Add tags: kubernetes, production, cpu, etc.
  • Search by tags: Use tag filter in dashboard list

Favorites

Mark dashboards as favorites:

  • Click star icon on dashboard
  • Access from Favorites in dashboard list

Importing/Exporting Dashboards

Exporting Dashboards

  1. Open dashboard
  2. Click Dashboard settings (gear icon)
  3. Click JSON Model
  4. Copy JSON or click Save to file

Importing Dashboards

  1. DashboardsImport
  2. Upload JSON file or paste JSON
  3. Configure:
    • Dashboard name
    • Folder
    • Data source mappings
  4. Click Import

Example Dashboard JSON

{
  "dashboard": {
    "title": "Kubernetes Cluster Overview",
    "tags": ["kubernetes", "cluster"],
    "panels": [
      {
        "title": "CPU Usage",
        "type": "graph",
        "targets": [
          {
            "expr": "100 - (avg(irate(container_cpu_usage_seconds_total[5m])) * 100)"
          }
        ]
      }
    ]
  }
}

Basic Kubernetes Dashboard Example

CPU Usage Panel

# CPU usage by pod
sum by (pod) (rate(container_cpu_usage_seconds_total[5m])) * 100

Configuration:

  • Title: CPU Usage by Pod
  • Y-axis: Unit: Percent (0-100)
  • Legend: Show as table
  • Thresholds: Green (0-70), Yellow (70-90), Red (90-100)

Memory Usage Panel

# Memory usage by pod
sum by (pod) (container_memory_usage_bytes) / 1024 / 1024 / 1024

Configuration:

  • Title: Memory Usage by Pod
  • Y-axis: Unit: GB
  • Legend: Show as table

Request Rate Panel

# HTTP requests per second
sum(rate(http_requests_total[5m]))

Configuration:

  • Title: Request Rate
  • Y-axis: Unit: req/s
  • Legend: Total requests

Pod Status Panel

# Pod status
kube_pod_status_phase

Configuration:

  • Title: Pod Status
  • Visualization: Table
  • Columns: Pod, Phase, Ready

Best Practices

1. Organize with Folders and Tags

Use folders to organize by environment, team, or system:

📁 Production
📁 Staging
📁 Development

Use tags for cross-cutting concerns:

  • kubernetes, application, infrastructure
  • team-frontend, team-backend
  • critical, monitoring

2. Use Variables for Reusability

Make dashboards reusable with variables:

  • Namespace selector
  • Pod selector
  • Time range presets
  • Environment selector

3. Set Appropriate Refresh Intervals

Balance between freshness and performance:

  • Real-time: 5s or 10s (for debugging)
  • Standard: 30s or 1m (for monitoring)
  • Long-term: 5m or 15m (for overview)

4. Optimize Queries

  • Use appropriate time ranges
  • Aggregate when possible
  • Avoid high-cardinality metrics
  • Use recording rules for complex queries

5. Dashboard Annotations

Add annotations for context:

  • Deployments
  • Incidents
  • Configuration changes
  • Maintenance windows

6. Use Appropriate Panel Types

  • Time series: For metrics over time
  • Table: For tabular data
  • Stat: For single values
  • Gauge: For threshold-based values

7. Set Thresholds

Configure visual thresholds:

  • Green: Normal range
  • Yellow: Warning
  • Red: Critical

8. Provide Context

  • Clear titles and descriptions
  • Units on axes
  • Legends for multiple series
  • Links to related dashboards

9. Dashboard Provisioning

Store dashboards as code:

  • Use ConfigMaps or Helm charts
  • Version control dashboard JSON
  • Automated deployment

10. Performance

  • Limit number of panels per dashboard
  • Optimize queries
  • Use recording rules for expensive queries
  • Set appropriate refresh intervals

Troubleshooting

No Data Showing

# Check data source connection
# Settings → Data Sources → Test

# Verify query syntax
# Check PromQL in Prometheus directly

# Check time range
# Verify data exists for selected time range

Variable Not Working

# Check variable query syntax
# Verify variable name matches (case-sensitive)
# Check "Multi-value" and "Include all" settings

Slow Dashboard

# Check query complexity
# Reduce number of panels
# Increase refresh interval
# Use recording rules for expensive queries

See Also