Grafana Dashboard 进行监控效果展示

  • 因为 Prometheus 的页面展示效果不是很好,一般就需要配合 Grafana 进行效果展示,Grafana更多地需要在浏览器进行操作
  • Prometheus 监控思科交换机文档完整地址:https://blog.51cto.com/liujingyu/category9.html

  • 整体逻辑效果图
    (三) Prometheus 监控思科交换机---Grafana 进行监控效果展示

Grafana 连接 Prometheus 数据源(Data Source)

  • PS:我部署的 Grafana 是经过汉化的 7.2.0 版本(已上传至阿里云仓库,公开版),对新手来说稍微友好一点,当然各位大神如果觉得不安全,或者喜欢用英文版本的,只需要去 Grafana 的官网下载部署最新版本即可。

(三) Prometheus 监控思科交换机---Grafana 进行监控效果展示
(三) Prometheus 监控思科交换机---Grafana 进行监控效果展示

Grafana 添加可以监控交换机的模板,我个人修改了几个,更贴合现在的使用环境

  • 采用 Job 做的区分,而不是一个 Job 做的多个 target
  • 一个 Job 对应多个 target 会有问题, Prometheus 会触发 400 的访问错误,然后我们的监控项也没办法做更进一步的区分

逻辑解释图
(三) Prometheus 监控思科交换机---Grafana 进行监控效果展示

具体模板:

  • 12492 detail
  • 10523 所有接口
  • 12489 SNMP Device Summary
  • 11169 显示流量,单个交换机

示例图:
(三) Prometheus 监控思科交换机---Grafana 进行监控效果展示
(三) Prometheus 监控思科交换机---Grafana 进行监控效果展示
(三) Prometheus 监控思科交换机---Grafana 进行监控效果展示
(三) Prometheus 监控思科交换机---Grafana 进行监控效果展示

根据 10523 的模板进行的了一下简单修改,可以根据 Job 进行区分

snmp-exporter_rev3.json

{
  "__inputs": [
    {
      "name": "DS_PROMETHEUS",
      "label": "Prometheus",
      "description": "",
      "type": "datasource",
      "pluginId": "prometheus",
      "pluginName": "Prometheus"
    }
  ],
  "__requires": [
    {
      "type": "grafana",
      "id": "grafana",
      "name": "Grafana",
      "version": "6.2.5"
    },
    {
      "type": "panel",
      "id": "graph",
      "name": "Graph",
      "version": ""
    },
    {
      "type": "datasource",
      "id": "prometheus",
      "name": "Prometheus",
      "version": "1.0.0"
    },
    {
      "type": "panel",
      "id": "singlestat",
      "name": "Singlestat",
      "version": ""
    }
  ],
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": "-- Grafana --",
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "limit": 100,
        "name": "Annotations & Alerts",
        "showIn": 0,
        "type": "dashboard"
      }
    ]
  },
  "description": "Bandwidth in and out of each interface of a SNMP device.流量单位bit/sec",
  "editable": true,
  "gnetId": 10523,
  "graphTooltip": 0,
  "id": null,
  "iteration": 1562921841141,
  "links": [],
  "panels": [
    {
      "cacheTimeout": null,
      "colorBackground": false,
      "colorPostfix": true,
      "colorPrefix": false,
      "colorValue": false,
      "colors": [
        "#299c46",
        "rgba(237, 129, 40, 0.89)",
        "#d44a3a"
      ],
      "datasource": "${DS_PROMETHEUS}",
      "decimals": 1,
      "format": "dtdurations",
      "gauge": {
        "maxValue": 100,
        "minValue": 0,
        "show": false,
        "thresholdLabels": false,
        "thresholdMarkers": true
      },
      "gridPos": {
        "h": 3,
        "w": 24,
        "x": 0,
        "y": 0
      },
      "id": 70,
      "interval": null,
      "links": [],
      "mappingType": 1,
      "mappingTypes": [
        {
          "name": "value to text",
          "value": 1
        },
        {
          "name": "range to text",
          "value": 2
        }
      ],
      "maxDataPoints": 100,
      "nullPointMode": "connected",
      "nullText": null,
      "options": {},
      "postfix": "",
      "postfixFontSize": "50%",
      "prefix": "",
      "prefixFontSize": "50%",
      "rangeMaps": [
        {
          "from": "null",
          "text": "N/A",
          "to": "null"
        }
      ],
      "repeat": null,
      "repeatDirection": "h",
      "sparkline": {
        "fillColor": "rgba(31, 118, 189, 0.18)",
        "full": false,
        "lineColor": "rgb(31, 120, 193)",
        "show": false
      },
      "tableColumn": "",
      "targets": [
        {
          "expr": "sysUpTime{instance=\"$Device\",job=\"$Job\"}/100",
          "format": "time_series",
          "instant": true,
          "intervalFactor": 1,
          "refId": "A"
        }
      ],
      "thresholds": "",
      "timeFrom": null,
      "timeShift": null,
      "title": "运行时长",
      "transparent": true,
      "type": "singlestat",
      "valueFontSize": "80%",
      "valueMaps": [
        {
          "op": "=",
          "text": "N/A",
          "value": "null"
        }
      ],
      "valueName": "current"
    },
    {
      "aliasColors": {
        "Out": "#C15C17"
      },
      "bars": false,
      "dashLength": 10,
      "dashes": false,
      "datasource": "${DS_PROMETHEUS}",
      "editable": true,
      "error": false,
      "fill": 1,
      "gridPos": {
        "h": 7,
        "w": 6,
        "x": 0,
        "y": 3
      },
      "id": 1,
      "legend": {
        "alignAsTable": false,
        "avg": false,
        "current": true,
        "max": true,
        "min": false,
        "rightSide": false,
        "show": true,
        "total": false,
        "values": true
      },
      "lines": true,
      "linewidth": 1,
      "links": [],
      "nullPointMode": "connected",
      "options": {},
      "percentage": false,
      "pointradius": 5,
      "points": false,
      "renderer": "flot",
      "repeat": "Interface",
      "seriesOverrides": [
        {
          "alias": "Out",
          "transform": "negative-Y"
        }
      ],
      "spaceLength": 10,
      "stack": false,
      "steppedLine": false,
      "targets": [
        {
          "expr": "irate(ifHCInOctets{job='$Job',instance='$Device',ifName='$Interface'}[5m]) * 8",
          "intervalFactor": 2,
          "legendFormat": "In",
          "refId": "A",
          "step": 60
        },
        {
          "expr": "irate(ifHCOutOctets{job='$Job',instance='$Device',ifName='$Interface'}[5m]) * 8",
          "intervalFactor": 2,
          "legendFormat": "Out",
          "refId": "B",
          "step": 60
        }
      ],
      "thresholds": [],
      "timeFrom": null,
      "timeRegions": [],
      "timeShift": null,
      "title": "$Interface",
      "tooltip": {
        "msResolution": false,
        "shared": true,
        "sort": 0,
        "value_type": "individual"
      },
      "type": "graph",
      "xaxis": {
        "buckets": null,
        "mode": "time",
        "name": null,
        "show": true,
        "values": []
      },
      "yaxes": [
        {
          "format": "bps",
          "label": null,
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        },
        {
          "format": "short",
          "label": null,
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        }
      ],
      "yaxis": {
        "align": false,
        "alignLevel": null
      }
    }
  ],
  "schemaVersion": 18,
  "style": "dark",
  "tags": [
    "$Job",
    "交换机"
  ],
  "templating": {
    "list": [
      {
        "allValue": null,
        "current": {},
        "datasource": "${DS_PROMETHEUS}",
        "definition": "",
        "hide": 0,
        "includeAll": false,
        "label": null,
        "multi": false,
        "name": "Job",
        "options": [],
        "query": "label_values(ifHCInOctets,  job)",
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "sort": 0,
        "tagValuesQuery": null,
        "tags": [],
        "tagsQuery": null,
        "type": "query",
        "useTags": false
      },
      {
        "allValue": null,
        "current": {},
        "datasource": "${DS_PROMETHEUS}",
        "definition": "",
        "hide": 0,
        "includeAll": false,
        "label": null,
        "multi": false,
        "name": "Device",
        "options": [],
        "query": "query_result(sum by (instance)(ifHCInOctets{job=\"$Job\"}))",
        "refresh": 1,
        "regex": ".*instance=\"(.*?)\".*",
        "skipUrlSync": false,
        "sort": 1,
        "tagValuesQuery": null,
        "tags": [],
        "tagsQuery": null,
        "type": "query",
        "useTags": false
      },
      {
        "allValue": null,
        "current": {},
        "datasource": "${DS_PROMETHEUS}",
        "definition": "",
        "hide": 0,
        "includeAll": true,
        "label": null,
        "multi": false,
        "name": "Interface",
        "options": [],
        "query": "query_result(ifHCInOctets{job=\"$Job\",instance=\"$Device\"})",
        "refresh": 1,
        "regex": ".*ifName=\"(.*?)\",.*",
        "skipUrlSync": false,
        "sort": 5,
        "tagValuesQuery": null,
        "tags": [],
        "tagsQuery": null,
        "type": "query",
        "useTags": false
      }
    ]
  },
  "time": {
    "from": "now-6h",
    "to": "now"
  },
  "timepicker": {
    "nowDelay": "",
    "refresh_intervals": [
      "5s",
      "10s",
      "30s",
      "1m",
      "5m",
      "15m",
      "30m",
      "1h",
      "2h",
      "1d"
    ],
    "time_options": [
      "5m",
      "15m",
      "1h",
      "6h",
      "12h",
      "24h",
      "2d",
      "7d",
      "30d"
    ]
  },
  "timezone": "browser",
  "title": "交换机端口详细信息",
  "uid": "design-by-ljy",
  "version": 4
}