狂自私

导航

grafana-docker-仪表盘模板

我没有在grafana官网上找到好用的docker监控数据展示模板,无奈自己依葫芦画瓢编写了一个,它完全依赖于docker_stats_exporter采集的指标。

显示如下:

json代码如下:

{
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": {
          "type": "grafana",
          "uid": "-- Grafana --"
        },
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "type": "dashboard"
      }
    ]
  },
  "description": "Docker运行状态仪表盘",
  "editable": true,
  "fiscalYearStartMonth": 0,
  "graphTooltip": 0,
  "id": 105,
  "links": [],
  "panels": [
    {
      "datasource": {
        "type": "prometheus",
        "uid": "cdqpzgggutc00f"
      },
      "description": "",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "custom": {
            "align": "auto",
            "cellOptions": {
              "type": "auto"
            },
            "inspect": false
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": [
          {
            "matcher": {
              "id": "byName",
              "options": "运行状态"
            },
            "properties": [
              {
                "id": "thresholds",
                "value": {
                  "mode": "absolute",
                  "steps": [
                    {
                      "color": "red",
                      "value": null
                    },
                    {
                      "color": "green",
                      "value": 1
                    }
                  ]
                }
              },
              {
                "id": "color",
                "value": {
                  "mode": "thresholds"
                }
              },
              {
                "id": "custom.cellOptions",
                "value": {
                  "applyToRow": false,
                  "mode": "gradient",
                  "type": "color-background"
                }
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "CPU使用率(单核)"
            },
            "properties": [
              {
                "id": "unit",
                "value": "%"
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "内存使用量"
            },
            "properties": [
              {
                "id": "unit",
                "value": "bytes"
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "内存使用率"
            },
            "properties": [
              {
                "id": "unit",
                "value": "percentunit"
              },
              {
                "id": "custom.cellOptions",
                "value": {
                  "mode": "lcd",
                  "type": "gauge",
                  "valueDisplayMode": "color"
                }
              },
              {
                "id": "color",
                "value": {
                  "mode": "continuous-GrYlRd"
                }
              },
              {
                "id": "custom.width",
                "value": 110
              },
              {
                "id": "max",
                "value": 1
              }
            ]
          },
          {
            "matcher": {
              "id": "byRegexp",
              "options": "/.*网速.*/"
            },
            "properties": [
              {
                "id": "unit",
                "value": "binBps"
              }
            ]
          }
        ]
      },
      "gridPos": {
        "h": 5,
        "w": 24,
        "x": 0,
        "y": 0
      },
      "id": 1,
      "interval": "1m",
      "options": {
        "cellHeight": "sm",
        "footer": {
          "countRows": false,
          "fields": "",
          "reducer": [
            "sum"
          ],
          "show": false
        },
        "frameIndex": 1,
        "showHeader": true,
        "sortBy": []
      },
      "pluginVersion": "11.0.0",
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "cdqpzgggutc00f"
          },
          "editorMode": "code",
          "exemplar": false,
          "expr": "docker_stats_up{job=\"docker\",host=~\"$host\"}",
          "format": "table",
          "hide": false,
          "instant": true,
          "legendFormat": "主机名",
          "range": false,
          "refId": "主机名和运行状态"
        },
        {
          "datasource": {
            "type": "prometheus",
            "uid": "cdqpzgggutc00f"
          },
          "editorMode": "code",
          "exemplar": false,
          "expr": "count(docker_container_cpu_number{job=\"docker\",host=~\"$host\"})by (host)",
          "format": "table",
          "hide": false,
          "instant": true,
          "legendFormat": "容器数量",
          "range": false,
          "refId": "容器数量"
        },
        {
          "datasource": {
            "type": "prometheus",
            "uid": "cdqpzgggutc00f"
          },
          "editorMode": "code",
          "exemplar": false,
          "expr": "sum((docker_container_cpu_usage_delta_seconds{job=\"docker\",host=~\"$host\"} / docker_container_cpu_system_usage_delta_seconds{job=\"docker\",host=~\"$host\"}) * docker_container_cpu_number{job=\"docker\",host=~\"$host\"} * 100.0)by(host)",
          "format": "table",
          "hide": false,
          "instant": true,
          "legendFormat": "CPU使用率",
          "range": false,
          "refId": "CPU使用率"
        },
        {
          "datasource": {
            "type": "prometheus",
            "uid": "cdqpzgggutc00f"
          },
          "editorMode": "code",
          "exemplar": false,
          "expr": "sum((docker_container_memory_usage_bytes_total{job=\"docker\",host=~\"$host\"} - docker_container_memory_cached_usage_bytes_total{job=\"docker\",host=~\"$host\"}))by(host)",
          "format": "table",
          "hide": false,
          "instant": true,
          "legendFormat": "内存使用量",
          "range": false,
          "refId": "内存使用量"
        },
        {
          "datasource": {
            "type": "prometheus",
            "uid": "cdqpzgggutc00f"
          },
          "editorMode": "code",
          "exemplar": false,
          "expr": "sum((docker_container_memory_usage_bytes_total{job=\"docker\",host=~\"$host\"} - docker_container_memory_cached_usage_bytes_total{job=\"docker\",host=~\"$host\"}) / docker_container_memory_limit_bytes_total{job=\"docker\",host=~\"$host\"})by(host)",
          "format": "table",
          "hide": false,
          "instant": true,
          "legendFormat": "内存使用率",
          "range": false,
          "refId": "内存使用率"
        },
        {
          "datasource": {
            "type": "prometheus",
            "uid": "cdqpzgggutc00f"
          },
          "editorMode": "code",
          "exemplar": false,
          "expr": "sum(rate(docker_container_network_bytes_received_bytes_total{job=\"docker\",host=~\"$host\"}[$__interval]))by(host)",
          "format": "table",
          "hide": false,
          "instant": true,
          "legendFormat": "网速(接收)",
          "range": false,
          "refId": "网速(接收)"
        },
        {
          "datasource": {
            "type": "prometheus",
            "uid": "cdqpzgggutc00f"
          },
          "editorMode": "code",
          "exemplar": false,
          "expr": "sum(rate(docker_container_network_bytes_sent_bytes_total{job=\"docker\",host=~\"$host\"}[$__interval]))by(host)",
          "format": "table",
          "hide": false,
          "instant": true,
          "legendFormat": "网速(发送)",
          "range": false,
          "refId": "网速(发送)"
        }
      ],
      "title": "容器总览",
      "transformations": [
        {
          "id": "merge",
          "options": {}
        },
        {
          "id": "organize",
          "options": {
            "excludeByName": {
              "Time": true,
              "__name__": true,
              "host": false,
              "instance": true,
              "job": true
            },
            "includeByName": {},
            "indexByName": {},
            "renameByName": {
              "Time": "",
              "Value": "运行状态",
              "Value #CPU使用率": "CPU使用率(单核)",
              "Value #主机名和运行状态": "运行状态",
              "Value #内存使用率": "内存使用率",
              "Value #内存使用量": "内存使用量",
              "Value #内存使用量(GB)": "内存使用量(GB)",
              "Value #容器数量": "容器数量",
              "Value #网速(发送)": "网速(发送)",
              "Value #网速(接收)": "网速(接收)",
              "host": "主机名称",
              "job": ""
            }
          }
        },
        {
          "id": "filterFieldsByName",
          "options": {
            "byVariable": false,
            "include": {
              "names": [
                "主机名称",
                "运行状态",
                "容器数量",
                "CPU使用率(单核)",
                "内存使用量",
                "内存使用率",
                "网速(接收)",
                "网速(发送)"
              ]
            }
          }
        }
      ],
      "type": "table"
    },
    {
      "datasource": {
        "type": "prometheus",
        "uid": "cdqpzgggutc00f"
      },
      "description": "内存使用率计算公式:容器已使用内存/容器内存限制大小",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "custom": {
            "align": "auto",
            "cellOptions": {
              "type": "auto"
            },
            "filterable": true,
            "inspect": false
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": [
          {
            "matcher": {
              "id": "byName",
              "options": "CPU使用率(单核)"
            },
            "properties": [
              {
                "id": "unit",
                "value": "%"
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "内存使用量"
            },
            "properties": [
              {
                "id": "unit",
                "value": "bytes"
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "内存使用率"
            },
            "properties": [
              {
                "id": "unit",
                "value": "percentunit"
              },
              {
                "id": "custom.cellOptions",
                "value": {
                  "mode": "lcd",
                  "type": "gauge",
                  "valueDisplayMode": "color"
                }
              },
              {
                "id": "color",
                "value": {
                  "mode": "continuous-GrYlRd"
                }
              },
              {
                "id": "max",
                "value": 1
              }
            ]
          },
          {
            "matcher": {
              "id": "byRegexp",
              "options": "/.*网速.*/"
            },
            "properties": [
              {
                "id": "unit",
                "value": "binBps"
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "内存限制大小"
            },
            "properties": [
              {
                "id": "unit",
                "value": "bytes"
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "容器id"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 115
              }
            ]
          }
        ]
      },
      "gridPos": {
        "h": 20,
        "w": 24,
        "x": 0,
        "y": 5
      },
      "id": 2,
      "interval": "1m",
      "options": {
        "cellHeight": "sm",
        "footer": {
          "countRows": false,
          "fields": "",
          "reducer": [
            "sum"
          ],
          "show": false
        },
        "showHeader": true,
        "sortBy": [
          {
            "desc": true,
            "displayName": "内存使用率"
          }
        ]
      },
      "pluginVersion": "11.0.0",
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "cdqpzgggutc00f"
          },
          "editorMode": "code",
          "exemplar": false,
          "expr": "docker_container_cpu_number{job=\"docker\",host=~\"$host\",container_name=~\"$container_name\"}",
          "format": "table",
          "hide": false,
          "instant": true,
          "legendFormat": "容器基础信息",
          "range": false,
          "refId": "容器基础信息"
        },
        {
          "datasource": {
            "type": "prometheus",
            "uid": "cdqpzgggutc00f"
          },
          "editorMode": "code",
          "exemplar": false,
          "expr": "sum((docker_container_cpu_usage_delta_seconds{job=\"docker\",host=~\"$host\",container_name=~\"$container_name\"} / docker_container_cpu_system_usage_delta_seconds{job=\"docker\",host=~\"$host\",container_name=~\"$container_name\"}) * docker_container_cpu_number{job=\"docker\",host=~\"$host\",container_name=~\"$container_name\"} * 100.0)by(host,container_name)",
          "format": "table",
          "hide": false,
          "instant": true,
          "legendFormat": "CPU使用率(单核)",
          "range": false,
          "refId": "CPU使用率(单核)"
        },
        {
          "datasource": {
            "type": "prometheus",
            "uid": "cdqpzgggutc00f"
          },
          "editorMode": "code",
          "exemplar": false,
          "expr": "sum((docker_container_memory_usage_bytes_total{job=\"docker\",host=~\"$host\",container_name=~\"$container_name\"} - docker_container_memory_cached_usage_bytes_total{job=\"docker\",host=~\"$host\",container_name=~\"$container_name\"}))by(host,container_name)",
          "format": "table",
          "hide": false,
          "instant": true,
          "legendFormat": "内存使用量",
          "range": false,
          "refId": "内存使用量"
        },
        {
          "datasource": {
            "type": "prometheus",
            "uid": "cdqpzgggutc00f"
          },
          "editorMode": "code",
          "exemplar": false,
          "expr": "sum((docker_container_memory_usage_bytes_total{job=\"docker\",host=~\"$host\",container_name=~\"$container_name\"} - docker_container_memory_cached_usage_bytes_total{job=\"docker\",host=~\"$host\",container_name=~\"$container_name\"}) / docker_container_memory_limit_bytes_total{job=\"docker\",host=~\"$host\",container_name=~\"$container_name\"})by(host,container_name)",
          "format": "table",
          "hide": false,
          "instant": true,
          "legendFormat": "内存使用率",
          "range": false,
          "refId": "内存使用率"
        },
        {
          "datasource": {
            "type": "prometheus",
            "uid": "cdqpzgggutc00f"
          },
          "editorMode": "code",
          "exemplar": false,
          "expr": "sum(rate(docker_container_network_bytes_received_bytes_total{job=\"docker\",host=~\"$host\",container_name=~\"$container_name\"}[$__interval]))by(host,container_name)",
          "format": "table",
          "hide": false,
          "instant": true,
          "legendFormat": "网速(接收)",
          "range": false,
          "refId": "网速(接收)"
        },
        {
          "datasource": {
            "type": "prometheus",
            "uid": "cdqpzgggutc00f"
          },
          "editorMode": "code",
          "exemplar": false,
          "expr": "sum(rate(docker_container_network_bytes_sent_bytes_total{job=\"docker\",host=~\"$host\",container_name=~\"$container_name\"}[$__interval]))by(host,container_name)",
          "format": "table",
          "hide": false,
          "instant": true,
          "legendFormat": "网速(发送)",
          "range": false,
          "refId": "网速(发送)"
        },
        {
          "datasource": {
            "type": "prometheus",
            "uid": "cdqpzgggutc00f"
          },
          "editorMode": "code",
          "exemplar": false,
          "expr": "sum(docker_container_memory_limit_bytes_total{job=\"docker\",host=~\"$host\",container_name=~\"$container_name\"})by(host,container_name)",
          "format": "table",
          "hide": false,
          "instant": true,
          "legendFormat": "内存限制大小",
          "range": false,
          "refId": "内存限制大小"
        }
      ],
      "title": "容器详情",
      "transformations": [
        {
          "id": "merge",
          "options": {}
        },
        {
          "id": "organize",
          "options": {
            "excludeByName": {
              "Time": true,
              "Value": false,
              "Value #CPU使用率": false,
              "Value #容器基础信息": true,
              "__name__": true,
              "container_id": false,
              "image_id": true,
              "instance": true,
              "job": true
            },
            "includeByName": {},
            "indexByName": {},
            "renameByName": {
              "Time": "",
              "Value": "",
              "Value #CPU使用率": "CPU使用率",
              "Value #CPU使用率(单核)": "CPU使用率(单核)",
              "Value #内存使用率": "内存使用率",
              "Value #内存使用量": "内存使用量",
              "Value #内存限制大小": "内存限制大小",
              "Value #容器基础信息": "",
              "Value #网速(发送)": "网速(发送)",
              "Value #网速(接收)": "网速(接收)",
              "container_id": "容器id",
              "container_name": "容器名称",
              "host": "主机名",
              "image_id": "",
              "image_name": "镜像名称",
              "instance": ""
            }
          }
        },
        {
          "id": "filterFieldsByName",
          "options": {
            "include": {
              "names": [
                "容器id",
                "容器名称",
                "主机名",
                "镜像名称",
                "CPU使用率(单核)",
                "内存使用量",
                "内存使用率",
                "网速(接收)",
                "网速(发送)",
                "内存限制大小"
              ]
            }
          }
        }
      ],
      "type": "table"
    }
  ],
  "refresh": "1m",
  "schemaVersion": 39,
  "tags": [],
  "templating": {
    "list": [
      {
        "current": {
          "selected": true,
          "text": [
            "emqx-001",
            "harbor-001"
          ],
          "value": [
            "emqx-001",
            "harbor-001"
          ]
        },
        "datasource": {
          "type": "prometheus",
          "uid": "cdqpzgggutc00f"
        },
        "definition": "label_values(docker_stats_up,host)",
        "description": "docker所在的主机名",
        "hide": 0,
        "includeAll": false,
        "multi": true,
        "name": "host",
        "options": [],
        "query": {
          "qryType": 1,
          "query": "label_values(docker_stats_up,host)",
          "refId": "PrometheusVariableQueryEditor-VariableQuery"
        },
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "sort": 0,
        "type": "query"
      },
      {
        "current": {
          "selected": true,
          "text": [
            "/txbz_server_prod",
            "/txbz_nginx_prod",
            "/txbz_mysql8_prod",
            "/stirling-pdf",
            "/registryctl",
            "/registry",
            "/redisinsight",
            "/redis",
            "/phpmyadmin",
            "/nginx",
            "/jkz_alarm_02017/mysql",
            "/jkz_alarm_02017",
            "/jenkins",
            "/harbor-portal",
            "/harbor-log",
            "/harbor-jobservice",
            "/harbor-db",
            "/harbor-core",
            "/gitlab",
            "/cloudbeaver"
          ],
          "value": [
            "/txbz_server_prod",
            "/txbz_nginx_prod",
            "/txbz_mysql8_prod",
            "/stirling-pdf",
            "/registryctl",
            "/registry",
            "/redisinsight",
            "/redis",
            "/phpmyadmin",
            "/nginx",
            "/jkz_alarm_02017/mysql",
            "/jkz_alarm_02017",
            "/jenkins",
            "/harbor-portal",
            "/harbor-log",
            "/harbor-jobservice",
            "/harbor-db",
            "/harbor-core",
            "/gitlab",
            "/cloudbeaver"
          ]
        },
        "datasource": {
          "type": "prometheus",
          "uid": "cdqpzgggutc00f"
        },
        "definition": "label_values(docker_container_cpu_number,container_name)",
        "description": "容器名称",
        "hide": 0,
        "includeAll": false,
        "multi": true,
        "name": "container_name",
        "options": [],
        "query": {
          "qryType": 1,
          "query": "label_values(docker_container_cpu_number,container_name)",
          "refId": "PrometheusVariableQueryEditor-VariableQuery"
        },
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "sort": 2,
        "type": "query"
      }
    ]
  },
  "time": {
    "from": "now-1h",
    "to": "now"
  },
  "timeRangeUpdatedDuringEditOrView": false,
  "timepicker": {},
  "timezone": "browser",
  "title": "Docker_dashboard",
  "uid": "celul6q4b30g0e",
  "version": 9,
  "weekStart": ""
}

 

posted on 2025-05-16 13:22  狂自私  阅读(171)  评论(0)    收藏  举报