-
Notifications
You must be signed in to change notification settings - Fork 0
Templating Guide
Garot Conklin edited this page Feb 6, 2025
·
1 revision
Guide to using templates and variables in dashboard configurations.
template_variables:
- name: "env"
prefix: "env"
default: "prod"
- name: "service"
prefix: "service"
default: "web-api"widgets:
- title: "CPU Usage ($env)"
type: "timeseries"
query: "avg:system.cpu.user{env:$env,service:$service}"version: "1.0"
defaults:
layout_type: "ordered"
refresh_interval: 300
tags:
- "team:infrastructure"
- "env:production"
dashboards:
- name: "System Dashboard"
# Inherits defaults
widgets: []widget_templates:
cpu_widget: &cpu_widget
type: "timeseries"
query: "avg:system.cpu.user{$scope}"
visualization:
type: "line"
yaxis:
min: 0
max: 100
dashboards:
- name: "System Dashboard"
widgets:
- title: "Production CPU"
<<: *cpu_widget
query: "avg:system.cpu.user{env:prod}"
- title: "Staging CPU"
<<: *cpu_widget
query: "avg:system.cpu.user{env:staging}"version: "1.0"
dashboards:
- name: "Environment Dashboard"
template_variables:
- name: "env"
prefix: "env"
default: "prod"
widgets:
- title: "Requests ($env)"
type: "timeseries"
query: >
avg:http.requests{env:$env}
{{#if eq env "prod"}}
.rollup(sum, 3600)
{{else}}
.rollup(sum, 300)
{{/if}}components:
monitoring: &monitoring_widgets
- title: "CPU Usage"
type: "timeseries"
query: "avg:system.cpu.user{$scope}"
- title: "Memory Usage"
type: "timeseries"
query: "avg:system.mem.used{$scope}"
dashboards:
- name: "Production Monitoring"
widgets:
<<: *monitoring_widgets
scope: "env:production"
- name: "Staging Monitoring"
widgets:
<<: *monitoring_widgets
scope: "env:staging"- Use descriptive names
- Follow consistent naming conventions
- Document variable purposes
- Always provide sensible defaults
- Consider environment-specific defaults
- Document default behavior
- Group related templates
- Use clear component names
- Maintain template documentation
- Limit template complexity
- Consider query optimization
- Monitor template expansion
version: "1.0"
defaults:
tags:
- "managed-by:datadog-dashboard-deployer"
dashboards:
- name: "$env Application Dashboard"
template_variables:
- name: "env"
prefix: "env"
values: ["prod", "staging", "dev"]
widgets:
- title: "Requests ($env)"
type: "timeseries"
query: "sum:http.requests{env:$env}"templates:
service_monitor: &service_monitor
template_variables:
- name: "service"
prefix: "service"
widgets:
- title: "$service Status"
type: "check_status"
check: "service.up"
group: "cluster"
- title: "$service Errors"
type: "timeseries"
query: "sum:service.errors{service:$service}"
dashboards:
- name: "Web API Monitor"
<<: *service_monitor
service: "web-api"
- name: "Database Monitor"
<<: *service_monitor
service: "database"