模拟官网编写自定义Grafana Dashboard

前言

我们想编写自定义的Dashboard,类似于官网那样下载的Dashboard,并且能移值到机器主机,如何实现了?

bash 复制代码
## 官网dashboard
https://grafana.com/grafana/dashboards/

编写

先在虚拟机写好Dashboard 然后下载。json文件如下:

bash 复制代码
{
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": {
          "type": "grafana",
          "uid": "-- Grafana --"
        },
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "type": "dashboard"
      },
      {
        "datasource": {
          "type": "prometheus",
          "uid": "c043a946-45f8-4729-9d1b-0c24ffa095c3"
        },
        "enable": true,
        "iconColor": "red",
        "name": "New annotation"
      }
    ]
  },
  "editable": true,
  "fiscalYearStartMonth": 0,
  "graphTooltip": 0,
  "id": 35,
  "links": [],
  "liveNow": false,
  "panels": [
    {
      "collapsed": false,
      "gridPos": {
        "h": 1,
        "w": 24,
        "x": 0,
        "y": 0
      },
      "id": 8,
      "panels": [],
      "title": "CPU / Mem / Disk ",
      "type": "row"
    },
    {
      "datasource": {
        "type": "prometheus",
        "uid": "c043a946-45f8-4729-9d1b-0c24ffa095c3"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "palette-classic"
          },
          "custom": {
            "axisCenteredZero": false,
            "axisColorMode": "text",
            "axisLabel": "",
            "axisPlacement": "auto",
            "barAlignment": 0,
            "drawStyle": "line",
            "fillOpacity": 0,
            "gradientMode": "none",
            "hideFrom": {
              "legend": false,
              "tooltip": false,
    

.....

参考官方下载的Dashboard改写

在 annotations 上加入:

bash 复制代码
  "__inputs": [
    {
      "name": "DS_PROMETHEUS",
      "label": "Prometheus",
      "description": "",
      "type": "datasource",
      "pluginId": "prometheus",
      "pluginName": "Prometheus"
    }
  ],
  "__requires": [
    {
      "type": "grafana",
      "id": "grafana",
      "name": "Grafana",
      "version": "6.1.6"
    },
    {
      "type": "panel",
      "id": "graph",
      "name": "Graph",
      "version": ""
    },
    {
      "type": "datasource",
      "id": "prometheus",
      "name": "Prometheus",
      "version": "1.0.0"
    },
    {
      "type": "panel",
      "id": "singlestat",
      "name": "Singlestat",
      "version": ""
    },
    {
      "type": "panel",
      "id": "table",
      "name": "Table",
      "version": ""
    }
  ],

同时把数据源改成如下:

bash 复制代码
"datasource": "${DS_PROMETHEUS}"

同时去掉uid:

bash 复制代码
"uid": "c043a946-45f8-4729-9d1b-0c24ffa095c3"
相关推荐
wgc891783 天前
监控系列之-Grafana面板展示及制作
grafana
豆瑞瑞3 天前
压测服务器并使用 Grafana 进行可视化
grafana
Aray12344 天前
Using Prometheus+Grafana+VMware-exporter to monitor VMware EXSi Hosts and VMs
grafana·prometheus
行走的山峰4 天前
在grafana上配置显示全部node资源信息概览
grafana
一瓢一瓢的饮 alanchan4 天前
【运维监控】系列文章汇总索引
java·运维·kafka·grafana·prometheus·influxdb·运维监控
MarkHD5 天前
Prometheus+grafana+kafka_exporter监控kafka运行情况
kafka·grafana·prometheus
MarkHD5 天前
Prometheus+grafana监控flink运行情况
flink·grafana·prometheus
苏坡爱豆的笑容都没你的甜5 天前
grafana升级指南
grafana
MarkHD5 天前
Prometheus+grafana监控spring boot 3运行情况
spring boot·grafana·prometheus
一瓢一瓢的饮 alanchan5 天前
【运维监控】Prometheus+grafana监控zookeeper运行情况
linux·运维·zookeeper·运维开发·grafana·prometheus·运维监控