算法艺术创作
algorithmic-art
通过代码和可调参数创作生成艺术与交互式视觉效果。
build-grafana-dashboards【设计与创意】Create production-ready Grafana dashboards with reusable panels, template variables, annotations, and provisioning for version-controlled dashboard deployment. Use when creating visual representations of Prometheus, Loki, or other data source metrics, building operational dashboards for SRE teams, migrating from manual dashboard creation to version-c…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
以可維、可復用、版控之最佳實踐設計並部署 Grafana 儀表板。
See Extended Examples for complete configuration files and templates.
建面板前先計儀表板版型與組。
創儀表板規文檔:
# Service Overview Dashboard
## Purpose
Real-time operational view for on-call engineers monitoring the API service.
## Rows
1. High-Level Metrics (collapsed by default)
- Request rate, error rate, latency (RED metrics)
- Service uptime, instance count
2. Detailed Metrics (expanded by default)
- Per-endpoint latency breakdown
- Error rate by status code
- Database connection pool status
3. Resource Utilization
- CPU, memory, disk usage per instance
- Network I/O rates
4. Logs (collapsed by default)
- Recent errors from Loki
- Alert firing history
## Variables
- `environment`: production, staging, development
- `instance`: all instances or specific instance selection
- `interval`: aggregation window (5m, 15m, 1h)
## Annotations
- Deployment events from CI/CD system
- Alert firing/resolving events
要設計原則:
預期: 明之儀表板結構已錄,與用戶(SRE、開發)對齊於指標與版型之先。
失敗時:
以濾用之復變建儀表板基礎。
創儀表板 JSON 結構(或用 UI 後出):
{
"dashboard": {
"title": "API Service Overview",
"uid": "api-service-overview",
"version": 1,
"timezone": "browser",
"editable": true,
"graphTooltip": 1,
"time": {
"from": "now-6h",
"to": "now"
},
"refresh": "30s",
"templating": {
"list": [
{
"name": "environment",
"type": "query",
"datasource": "Prometheus",
"query": "label_values(up{job=\"api-service\"}, environment)",
"multi": false,
"includeAll": false,
"refresh": 1,
"sort": 1,
"current": {
"selected": false,
"text": "production",
"value": "production"
}
},
{
"name": "instance",
"type": "query",
"datasource": "Prometheus",
"query": "label_values(up{job=\"api-service\",environment=\"$environment\"}, instance)",
"multi": true,
"includeAll": true,
"refresh": 1,
"allValue": ".*",
"current": {
"selected": true,
"text": "All",
"value": "$__all"
}
},
{
"name": "interval",
"type": "interval",
"options": [
{"text": "1m", "value": "1m"},
{"text": "5m", "value": "5m"},
{"text": "15m", "value": "15m"},
{"text": "1h", "value": "1h"}
],
"current": {
"text": "5m",
"value": "5m"
},
"auto": false
}
]
},
"annotations": {
"list": [
{
"name": "Deployments",
"datasource": "Prometheus",
"enable": true,
"expr": "changes(app_version{job=\"api-service\",environment=\"$environment\"}[5m]) > 0",
"step": "60s",
"iconColor": "rgba(0, 211, 255, 1)",
"tagKeys": "version"
}
]
}
}
}
變數類與用例:
label_values()、query_result())預期: 變數自數源正填,級聯濾工(環境濾實例),預設擇合。
失敗時:
allValue 中 regex 模式為每指標創合之視覺化類之面板。
時序面板(請率):
{
"type": "timeseries",
"title": "Request Rate",
"gridPos": {"h": 8, "w": 12, "x": 0, "y": 0},
"targets": [
{
"expr": "sum(rate(http_requests_total{job=\"api-service\",environment=\"$environment\",instance=~\"$instance\"}[$interval])) by (method)",
"legendFormat": "{{method}}",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "reqps",
"color": {
"mode": "palette-classic"
},
"custom": {
"drawStyle": "line",
"lineInterpolation": "smooth",
"fillOpacity": 10,
"spanNulls": true
},
"thresholds": {
"mode": "absolute",
"steps": [
{"value": null, "color": "green"},
{"value": 1000, "color": "yellow"},
{"value": 5000, "color": "red"}
]
}
}
},
"options": {
"tooltip": {
"mode": "multi",
"sort": "desc"
},
"legend": {
"displayMode": "table",
"placement": "right",
"calcs": ["mean", "max", "last"]
}
}
}
Stat 面板(錯率):
{
"type": "stat",
"title": "Error Rate",
"gridPos": {"h": 4, "w": 6, "x": 12, "y": 0},
"targets": [
{
# ... (see EXAMPLES.md for complete configuration)
Heatmap 面板(延分佈):
{
"type": "heatmap",
"title": "Request Duration Heatmap",
"gridPos": {"h": 8, "w": 12, "x": 0, "y": 8},
"targets": [
{
# ... (see EXAMPLES.md for complete configuration)
面板擇指南:
預期: 面板以數正渲,視覺化合所意之指標類,圖例描,門檻示題。
失敗時:
組面板入可折行以作邏輯組。
{
"panels": [
{
"type": "row",
"title": "High-Level Metrics",
"collapsed": false,
# ... (see EXAMPLES.md for complete configuration)
版型最佳實踐:
w(寬)與 h(高)預期: 儀表板版型合邏輯,行折/展正確,面板視覺對齊而無隙。
失敗時:
創相關儀表板間之導航路。
JSON 中儀表板級連:
{
"links": [
{
"title": "Service Details",
"type": "link",
"icon": "external link",
# ... (see EXAMPLES.md for complete configuration)
面板級數連:
{
"fieldConfig": {
"defaults": {
"links": [
{
"title": "View Logs for ${__field.labels.instance}",
# ... (see EXAMPLES.md for complete configuration)
連變數:
$service、$environment:儀表板模板變${__field.labels.instance}:所點數點之標值${__from}、${__to}:當前儀表板時段$__url_time_range:URL 編之時段預期: 點面板元或儀表板連至相關視,脈絡保全(時段、變數)。
失敗時:
includeVars 與 keepTime 旗如期工版控儀表板為代碼以可復部。
創配置目錄結構:
mkdir -p /etc/grafana/provisioning/{dashboards,datasources}
數源配置(/etc/grafana/provisioning/datasources/prometheus.yml):
apiVersion: 1
datasources:
- name: Prometheus
type: prometheus
access: proxy
# ... (see EXAMPLES.md for complete configuration)
儀表板配置(/etc/grafana/provisioning/dashboards/default.yml):
apiVersion: 1
providers:
- name: 'default'
orgId: 1
folder: 'Services'
type: file
disableDeletion: false
updateIntervalSeconds: 30
allowUiUpdates: true
options:
path: /var/lib/grafana/dashboards
foldersFromFilesStructure: true
存儀表板 JSON 文件於 /var/lib/grafana/dashboards/:
/var/lib/grafana/dashboards/
├── api-service/
│ ├── overview.json
│ └── details.json
├── database/
│ └── postgres.json
└── infrastructure/
├── nodes.json
└── kubernetes.json
用 Docker Compose:
version: '3.8'
services:
grafana:
image: grafana/grafana:10.2.0
ports:
- "3000:3000"
volumes:
- ./grafana/provisioning:/etc/grafana/provisioning
- ./grafana/dashboards:/var/lib/grafana/dashboards
environment:
- GF_SECURITY_ADMIN_PASSWORD=admin
- GF_USERS_ALLOW_SIGN_UP=false
- GF_AUTH_ANONYMOUS_ENABLED=true
- GF_AUTH_ANONYMOUS_ORG_ROLE=Viewer
預期: 儀表板於 Grafana 啟時自動載,JSON 文件之變於更間後反映,版控追儀表板變。
失敗時:
docker logs grafana | grep -i provisioningpython -m json.tool dashboard.jsonchmod 644 *.jsonallowUiUpdates: false 測以止 UI 修curl http://localhost:3000/api/admin/provisioning/dashboards/reload -X POST -H "Authorization: Bearer $GRAFANA_API_KEY"$variable 語法,非硬編值。查變刷新設。legendFormat 顯相關標,非全指標名。例:{{method}} - {{status}} 代預設。allowUiUpdates: false。${__field.labels.labelname} 慎用,驗標存於查詢果。setup-prometheus-monitoring - 配 Grafana 儀表板所食之 Prometheus 數源configure-log-aggregation - 立 Loki 以供日誌面板查詢與基日誌之註釋define-slo-sli-sla - 以 Grafana 之 stat 與 gauge 面板視覺化 SLO 合規與錯預算instrument-distributed-tracing - 自指標面板加軌 ID 連至 Tempo 軌視