模拟官网编写自定义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"
相关推荐
晴天飛 雪21 小时前
Grafana监控PostgreSQL
数据库·postgresql·grafana
大虾别跑1 天前
docker安装zabbix +grafana
docker·zabbix·grafana
菜鸟挣扎史2 天前
grafana+prometheus+windows_exporter实现windows进程资源占用的监控
windows·grafana·prometheus·进程·process
tester Jeffky2 天前
JMeter监听器与压测监控之Grafana
jmeter·eureka·grafana
DB菜鸟6 天前
Grafana Username password invalid
java·服务器·grafana
让生命变得有价值6 天前
使用 Grafana api 查询 Datasource 数据
grafana·prometheus
赫萝的红苹果6 天前
Springboot整合Prometheus+grafana实现系统监控
spring boot·grafana·prometheus
不会飞的小龙人6 天前
遥测数据采集工具Grafana Alloy
spring boot·grafana·日志采集·链路跟踪·alloy·otel
运维佬6 天前
要卸载 Grafana 或者从 TiDB 集群中删除 Grafana 服务节点,你需要按以下步骤操作
java·tidb·grafana
Heartsuit6 天前
云原生之运维监控实践-使用Prometheus与Grafana实现对Nginx和Nacos服务的监测
nginx·云原生·nacos·grafana·prometheus·运维监控