Grafana Node Graph 使用教程

文章介绍了如何利用Grafana7.5.0及以上版本,结合GrafanaNodeGraphAPIPlugin插件,设置数据源并安装插件,通过调用特定的API接口来展示图数据,包括节点和边的关系。用户需提供健康检查、字段信息和数据接口,然后在Grafana中新建Panel以创建和显示图形。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Grafana 可以显示图数据,例:
Graph Example

依赖

  • Grafana >= 7.5.0
    下载地址 https://grafana.com/grafana/download
# 启动 Grafana
$ ./grafana-sever
  • Grafana Node Graph API Plugin
# 安装插件
$ grafana-cli plugins install hamedkarbasi93-nodegraphapi-datasource
# 重新启动 Grafana
$ grafana-server

步骤

(1)Grafana 添加数据源,选择 Node Graph API
Node Graph API Data Source
填写 Node Graph API URL,如 http://localhost:9999
Node Graph API URL
注:$URL 需要提供三个 API

  • $URL/api/heatlh 健康检查接口
    • method: GET
    • 返回 HTTP CODE 200 即可
  • $URL/api/graph/fields 图节点与边涉及的字段接口
    • method: GET
    • content type: application/json
    • response body example:
      {
        "edges_fields": [
          {
            "field_name": "id",
            "type": "string"
          },
          {
            "field_name": "source",
            "type": "string"
          },
          {
            "field_name": "target",
            "type": "string"
          },
          {
            "field_name": "mainStat",
            "type": "number"
          }
        ],
        "nodes_fields": [
          {
            "field_name": "id",
            "type": "string"
          },
          {
            "field_name": "title",
            "type": "string"
          },
          {
            "field_name": "mainStat",
            "type": "string"
          },
          {
            "field_name": "secondaryStat",
            "type": "number"
          },
          {
            "color": "red",
            "field_name": "arc__failed",
            "type": "number"
          },
          {
            "color": "green",
            "field_name": "arc__passed",
            "type": "number"
          },
          {
            "displayName": "Role",
            "field_name": "detail__role",
            "type": "string"
          }
        ]
      }
      
  • $URL/api/graph/data 图节点与与边关系数据接口
    • method: GET
    • content type: application/json
    • response body example:
      {
          "edges": [
              {
                  "id": "1",
                  "mainStat": "53/s",
                  "source": "1",
                  "target": "2"
              }
          ],
          "nodes": [
              {
                  "arc__failed": 0.7,
                  "arc__passed": 0.3,
                  "detail__zone": "load",
                  "id": "1",
                  "subTitle": "instance:#2",
                  "title": "Service1"
              },
              {
                  "arc__failed": 0.5,
                  "arc__passed": 0.5,
                  "detail__zone": "transform",
                  "id": "2",
                  "subTitle": "instance:#3",
                  "title": "Service2"
              }
          ]
      }
      

(2)Grafana 新建 Panel,选择 Node Graph
Node Graph Panel
选择对应的 Data Source 为刚刚添加的数据源
Data Source - Node Graph API
(3)得到图
Node Graph

参考

  • https://grafana.com/docs/grafana/latest/panels-visualizations/visualizations/node-graph/ Grafana Node Graph Panel
  • https://grafana.com/grafana/plugins/hamedkarbasi93-nodegraphapi-datasource/ Grafana Node Graph API
以下是一个简单的中文模板示例,用于在Grafana中监控Node Exporter的指标: ``` { "dashboard": { "id": null, "title": "Node Exporter监控", "panels": [ { "title": "CPU使用率", "type": "graph", "targets": [ { "expr": "100 - (avg by (instance) (irate(node_cpu_seconds_total{mode=\"idle\"}[5m])) * 100)", "legendFormat": "{{instance}}", "intervalFactor": 2 } ], "yaxes": [ { "format": "percent" }, { "format": "short" } ], "gridPos": { "x": 0, "y": 0, "w": 12, "h": 6 } }, { "title": "内存使用率", "type": "graph", "targets": [ { "expr": "(node_memory_MemTotal_bytes - node_memory_MemFree_bytes - node_memory_Buffers_bytes - node_memory_Cached_bytes) / node_memory_MemTotal_bytes * 100", "legendFormat": "{{instance}}", "intervalFactor": 2 } ], "yaxes": [ { "format": "percent" }, { "format": "short" } ], "gridPos": { "x": 0, "y": 6, "w": 12, "h": 6 } }, { "title": "磁盘使用率", "type": "graph", "targets": [ { "expr": "100 - (avg by (instance) (node_filesystem_avail_bytes{fstype!=\"rootfs\"} / node_filesystem_size_bytes{fstype!=\"rootfs\"}) * 100)", "legendFormat": "{{instance}}", "intervalFactor": 2 } ], "yaxes": [ { "format": "percent" }, { "format": "short" } ], "gridPos": { "x": 0, "y": 12, "w": 12, "h": 6 } } ], "time": { "from": "now-1h", "to": "now" }, "timezone": "browser", "schemaVersion": 21, "version": 0 }, "folderId": null, "overwrite": false } ``` 这个示例包括了三个面板,分别是CPU使用率、内存使用率和磁盘使用率。你可以根据需要修改面板的标题、指标和布局。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

陈塘关百姓

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值