mcpField
G
grafana-dashboards

grafana-dashboards

github.com/wshobsonクラウド・DevOps41.9k13.3k 回インストール2 週間前に更新
リポジトリ

grafana-dashboards について

アプリケーション、インフラ、ビジネス指標向けにGrafanaダッシュボードを設計・構成するスキルです。一般的なパネル、変数、アラート、ダッシュボードのコード管理を扱います。

主な機能

  1. 01REDとUSEのダッシュボードパターン
  2. 02統計、時系列、テーブル、ヒートマップのパネル
  3. 03柔軟なダッシュボード用クエリ変数
  4. 04ダッシュボードのアラートとプロビジョニング
  5. 05TerraformとAnsibleによるデプロイ例

活用シーン

  1. 01Prometheusメトリクスの可視化
  2. 02APIのリクエスト率、エラー、レイテンシの監視
  3. 03インフラとデータベースの状態把握
  4. 04SLOおよびビジネスKPIダッシュボードの作成

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/wshobson/agents --skill grafana-dashboards

インストール後、Claude Code で/grafana-dashboardsを入力して読み込まれたか確認します。

詳細

Grafana ダッシュボード

包括的なシステム可観測性のための、本番環境で使用可能な Grafana ダッシュボードを作成および管理します。

目的

アプリケーション、インフラストラクチャ、ビジネスメトリクスを監視するための効果的な Grafana ダッシュボードを設計します。

使用するタイミング

  • Prometheus メトリクスを可視化する
  • カスタムダッシュボードを作成する
  • SLO ダッシュボードを実装する
  • インフラストラクチャを監視する
  • ビジネス KPI を追跡する

ダッシュボード設計の原則

1. 情報の階層
┌─────────────────────────────────────┐
│  Critical Metrics (Big Numbers)     │
├─────────────────────────────────────┤
│  Key Trends (Time Series)           │
├─────────────────────────────────────┤
│  Detailed Metrics (Tables/Heatmaps) │
└─────────────────────────────────────┘
2. RED メソッド (サービス)
  • Rate - 1 秒あたりのリクエスト数
  • Errors - エラー率
  • Duration - レイテンシ/応答時間
3. USE メソッド (リソース)
  • Utilization - リソースがビジー状態である時間の割合
  • Saturation - キューの長さ/待機時間
  • Errors - エラー数

ダッシュボードの構造

API 監視ダッシュボード
{
  "dashboard": {
    "title": "API Monitoring",
    "tags": ["api", "production"],
    "timezone": "browser",
    "refresh": "30s",
    "panels": [
      {
        "title": "Request Rate",
        "type": "graph",
        "targets": [
          {
            "expr": "sum(rate(http_requests_total[5m])) by (service)",
            "legendFormat": "{{service}}"
          }
        ],
        "gridPos": { "x": 0, "y": 0, "w": 12, "h": 8 }
      },
      {
        "title": "Error Rate %",
        "type": "graph",
        "targets": [
          {
            "expr": "(sum(rate(http_requests_total{status=~\"5..\"}[5m])) / sum(rate(http_requests_total[5m]))) * 100",
            "legendFormat": "Error Rate"
          }
        ],
        "alert": {
          "conditions": [
            {
              "evaluator": { "params": [5], "type": "gt" },
              "operator": { "type": "and" },
              "query": { "params": ["A", "5m", "now"] },
              "type": "query"
            }
          ]
        },
        "gridPos": { "x": 12, "y": 0, "w": 12, "h": 8 }
      },
      {
        "title": "P95 Latency",
        "type": "graph",
        "targets": [
          {
            "expr": "histogram_quantile(0.95, sum(rate(http_request_duration_seconds_bucket[5m])) by (le, service))",
            "legendFormat": "{{service}}"
          }
        ],
        "gridPos": { "x": 0, "y": 8, "w": 24, "h": 8 }
      }
    ]
  }
}

パネルの種類

1. Stat パネル (単一の値)
{
  "type": "stat",
  "title": "Total Requests",
  "targets": [
    {
      "expr": "sum(http_requests_total)"
    }
  ],
  "options": {
    "reduceOptions": {
      "values": false,
      "calcs": ["lastNotNull"]
    },
    "orientation": "auto",
    "textMode": "auto",
    "colorMode": "value"
  },
  "fieldConfig": {
    "defaults": {
      "thresholds": {
        "mode": "absolute",
        "steps": [
          { "value": 0, "color": "green" },
          { "value": 80, "color": "yellow" },
          { "value": 90, "color": "red" }
        ]
      }
    }
  }
}
2. 時系列グラフ
{
  "type": "graph",
  "title": "CPU Usage",
  "targets": [
    {
      "expr": "100 - (avg by (instance) (rate(node_cpu_seconds_total{mode=\"idle\"}[5m])) * 100)"
    }
  ],
  "yaxes": [
    { "format": "percent", "max": 100, "min": 0 },
    { "format": "short" }
  ]
}
3. テーブルパネル
{
  "type": "table",
  "title": "Service Status",
  "targets": [
    {
      "expr": "up",
      "format": "table",
      "instant": true
    }
  ],
  "transformations": [
    {
      "id": "organize",
      "options": {
        "excludeByName": { "Time": true },
        "indexByName": {},
        "renameByName": {
          "instance": "Instance",
          "job": "Service",
          "Value": "Status"
        }
      }
    }
  ]
}
4. ヒートマップ
{
  "type": "heatmap",
  "title": "Latency Heatmap",
  "targets": [
    {
      "expr": "sum(rate(http_request_duration_seconds_bucket[5m])) by (le)",
      "format": "heatmap"
    }
  ],
  "dataFormat": "tsbuckets",
  "yAxis": {
    "format": "s"
  }
}

変数

クエリ変数
{
  "templating": {
    "list": [
      {
        "name": "namespace",
        "type": "query",
        "datasource": "Prometheus",
        "query": "label_values(kube_pod_info, namespace)",
        "refresh": 1,
        "multi": false
      },
      {
        "name": "service",
        "type": "query",
        "datasource": "Prometheus",
        "query": "label_values(kube_service_info{namespace=\"$namespace\"}, service)",
        "refresh": 1,
        "multi": true
      }
    ]
  }
}
クエリで変数を使用する
sum(rate(http_requests_total{namespace="$namespace", service=~"$service"}[5m]))

ダッシュボード内のアラート

{
  "alert": {
    "name": "High Error Rate",
    "conditions": [
      {
        "evaluator": {
          "params": [5],
          "type": "gt"
        },
        "operator": { "type": "and" },
        "query": {
          "params": ["A", "5m", "now"]
        },
        "reducer": { "type": "avg" },
        "type": "query"
      }
    ],
    "executionErrorState": "alerting",
    "for": "5m",
    "frequency": "1m",
    "message": "Error rate is above 5%",
    "noDataState": "no_data",
    "notifications": [{ "uid": "slack-channel" }]
  }
}

ダッシュボードのプロビジョニング

dashboards.yml:

apiVersion: 1

providers:
  - name: "default"
    orgId: 1
    folder: "General"
    type: file
    disableDeletion: false
    updateIntervalSeconds: 10
    allowUiUpdates: true
    options:
      path: /etc/grafana/dashboards

一般的なダッシュボードパターン

インフラストラクチャダッシュボード

主要なパネル:

  • ノードごとの CPU 使用率
  • ノードごとのメモリ使用量
  • ディスク I/O
  • ネットワークトラフィック
  • 名前空間ごとの Pod 数
  • ノードのステータス
データベースダッシュボード

主要なパネル:

  • 1 秒あたりのクエリ数
  • 接続プールの使用率
  • クエリレイテンシ (P50、P95、P99)
  • アクティブな接続数
  • データベースサイズ
  • レプリケーションの遅延
  • スロークエリ
アプリケーションダッシュボード

主要なパネル:

  • リクエストレート
  • エラー率
  • 応答時間 (パーセンタイル)
  • アクティブユーザー/セッション
  • キャッシュヒット率
  • キューの長さ

ベストプラクティス

  1. テンプレートから始める (Grafana コミュニティダッシュボード)
  2. 一貫した命名をパネルと変数に使用する
  3. 関連するメトリクスをグループ化して行にまとめる
  4. 適切な時間範囲を設定する (デフォルト: 過去 6 時間)
  5. 変数を使用して柔軟性を高める
  6. パネルの説明を追加してコンテキストを補足する
  7. 単位を正しく設定する
  8. 色のしきい値を意味のある値に設定する
  9. ダッシュボード間で一貫した色を使用する
  10. 異なる時間範囲でテストする

コードとしてのダッシュボード

Terraform によるプロビジョニング
resource "grafana_dashboard" "api_monitoring" {
  config_json = file("${path.module}/dashboards/api-monitoring.json")
  folder      = grafana_folder.monitoring.id
}

resource "grafana_folder" "monitoring" {
  title = "Production Monitoring"
}
Ansible によるプロビジョニング
- name: Deploy Grafana dashboards
  copy:
    src: "{{ item }}"
    dest: /etc/grafana/dashboards/
  with_fileglob:
    - "dashboards/*.json"
  notify: restart grafana

関連スキル

  • prometheus-configuration - メトリクス収集用
  • slo-implementation - SLO ダッシュボード用

コメント