executing-plans
executing-plans
Use when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available
build-grafana-dashboards再利用可能なパネル、テンプレート変数、アノテーション、プロビジョニングを備えた 本番対応のGrafanaダッシュボードを作成し、バージョン管理されたデプロイを実現する。 Prometheus、Loki、その他のデータソースのメトリクスを可視化する場合、 SREチーム向けの運用ダッシュボードを構築する場合、手動のダッシュボード作成から バージョン管理されたプロビジョニングに移行する場合、またはSLOコンプライアンスの エグゼクティブレベルのレポートを確立する場合に使用する。
Independent GitHub snapshot · Automated classification · Original documentation governs
保守性、再利用性、バージョン管理のベストプラクティスに従ってGrafanaダッシュボードを設計・デプロイする。
完全な設定ファイルとテンプレートは拡張例を参照。
パネルを構築する前に、ダッシュボードのレイアウトと構成を計画する。
ダッシュボード仕様書を作成する:
# 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
主要な設計原則:
期待結果: ダッシュボード構造が明確に文書化され、メトリクスとレイアウトの優先順位についてステークホルダーが合意する。
失敗時:
フィルタリング用の再利用可能な変数でダッシュボードの基盤を構築する。
ダッシュボード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フィールドの正規表現パターンを確認する各メトリクスに適した可視化タイプでパネルを作成する。
時系列パネル(リクエストレート):
{
"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)
ヒートマップパネル(レイテンシ分布):
{
"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
/var/lib/grafana/dashboards/にダッシュボードJSONファイルを保存する:
/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でテストする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パネルとゲージパネルでSLOコンプライアンスとエラーバジェットを可視化するinstrument-distributed-tracing - メトリクスパネルからTempoトレースビューへのトレースIDリンクを追加する