mcpField
G
grafana-dashboards

grafana-dashboards

github.com/sickn33云与 DevOps48.7k276 次安装1 天前更新
代码仓库

关于 grafana-dashboards

用于设计和管理 Grafana 仪表板的 Skill,面向应用、基础设施和业务指标监控。内容涵盖面板布局、常见监控模式、变量与配置部署,并提醒按目标 Grafana 版本验证示例。

主要功能

  1. 01仪表板设计指导
  2. 02RED 和 USE 监控模式
  3. 03面板与变量示例
  4. 04使用 Terraform 或 Ansible 部署
  5. 05验证与发布检查

适用场景

  1. 01可视化 Prometheus 指标
  2. 02构建 SLO 或基础设施仪表板
  3. 03跟踪应用或业务指标

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/sickn33/agentic-awesome-skills --skill grafana-dashboards

安装后在 Claude Code 中输入/grafana-dashboards确认已加载。

附带文件references/dashboard-design.mdresources/implementation-playbook.md

详细介绍

Grafana 仪表板

创建和管理适用于生产环境的 Grafana 仪表板,实现全面的系统可观测性。

不要在以下情况使用此技能

  • 任务与 Grafana 仪表板无关
  • 你需要使用此范围之外的其他领域或工具

说明

  • 明确目标、限制条件和所需输入。
  • 应用相关最佳实践并验证结果。
  • 提供可执行的步骤和验证方法。
  • 如需详细示例,请打开 resources/implementation-playbook.md。

用途

设计有效的 Grafana 仪表板,用于监控应用程序、基础设施和业务指标。

在以下情况使用此技能

  • 可视化 Prometheus 指标
  • 创建自定义仪表板
  • 实现 SLO 仪表板
  • 监控基础设施
  • 跟踪业务 KPI

仪表板设计原则

1. 信息层级
┌─────────────────────────────────────┐
│  Critical Metrics (Big Numbers)     │
├─────────────────────────────────────┤
│  Key Trends (Time Series)           │
├─────────────────────────────────────┤
│  Detailed Metrics (Tables/Heatmaps) │
└─────────────────────────────────────┘
2. RED 方法(服务)
  • 速率 - 每秒请求数
  • 错误 - 错误率
  • 时长 - 延迟/响应时间
3. USE 方法(资源)
  • 利用率 - 资源处于繁忙状态的时间占比
  • 饱和度 - 队列长度/等待时间
  • 错误 - 错误数量

仪表板结构

API 监控仪表板

以下 JSON 使用旧版图表面板和内嵌的告警字段。它展示的是查询意图,并非可移植的当前配置文件。请从目标 Grafana 版本导出受支持的面板 JSON;并通过其支持的告警接口单独配置告警规则。部署前请测试缺失流量或流量为零的情况,并验证数据源 UID。

{
  "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. 统计面板(单值)
{
  "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 数量
  • 节点状态

**参考:**参见内嵌示例

数据库仪表板

关键面板:

  • 每秒查询数
  • 连接池使用情况
  • 查询延迟(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 仪表板

限制

  • 仅当任务明确符合上述范围时才使用此技能。
  • 不要将输出视为针对特定环境进行验证、测试或专家审查的替代品。
  • 如果缺少所需输入、权限、安全边界或成功标准,请停止并请求澄清。

评论

支持 Markdown