Installation
- apt install grafanaDebian/Ubuntu
- yum install grafanaCentOS/RHEL
- brew install grafanamacOS
- docker run grafanaDocker
- Default: :3000Web UI port
Panel Types
- Time seriesLine/area charts
- StatSingle value
- GaugeRadial gauge
- Bar gaugeHorizontal bars
- TableData table
- HeatmapDensity plot
- LogsLog viewer
Data Sources
- PrometheusMetrics DB
- InfluxDBTime series DB
- ElasticsearchLogs & search
- LokiLog aggregation
- MySQL/PostgreSQLSQL databases
- CloudWatchAWS metrics
Keyboard Shortcuts
- dDashboard settings
- eEdit panel
- vView panel fullscreen
- sSave dashboard
- rRefresh dashboard
- EscExit edit/view mode
PromQL Examples (Prometheus)
# Request rate per second
rate(http_requests_total[5m])
# 95th percentile latency
histogram_quantile(0.95, rate(http_request_duration_seconds_bucket[5m]))
# CPU usage percentage
100 - (avg(irate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)
# Memory usage
node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes
Template Variables
# Query variable (get values from datasource)
label_values(up, job) # Get all job labels
label_values(node_cpu_seconds_total, cpu) # Get CPU cores
# Use in queries with $variable or ${variable}
rate(http_requests_total{job="$job"}[5m])
# Multi-value with regex
{instance=~"$instance"} # Matches selected values
Variable Types
- QueryFrom datasource
- CustomStatic values
- ConstantFixed value
- IntervalTime interval
- Data sourceSelect source
- Text boxFree text input
Alert Rules
- ConditionQuery threshold
- For durationPending time
- LabelsAlert metadata
- AnnotationsAlert details
- Contact pointsNotification dest
HTTP API Examples
# Get all dashboards
curl -H "Authorization: Bearer $TOKEN" http://localhost:3000/api/search
# Get dashboard by UID
curl http://localhost:3000/api/dashboards/uid/my-dashboard
# Create API key
curl -X POST -H "Content-Type: application/json" \
-d '{"name":"mykey","role":"Admin"}' \
http://admin:admin@localhost:3000/api/auth/keys
Config Paths
- /etc/grafana/Config directory
- grafana.iniMain config
- /var/lib/grafana/Data directory
- /var/log/grafana/Log files
Time Range Syntax
- now-5mLast 5 minutes
- now-1hLast hour
- now-24hLast 24 hours
- now-7dLast 7 days
- now/dToday so far