基于飞牛应用商店的Prometheus+容器化的Grafana进行的方案分享
在家用 NAS 上的硬件监控系统,实时监控 CPU、内存、网络和磁盘功耗等数据。整个方案完全基于 应用商店的Prometheus+容器化的Grafana,方便部署和维护。下面给大家分享我的配置和一些说明。
预先安装
优先安装应用商店的Prometheus

安装完成后看下是否正常运行,node_cpu_seconds_total{instance="127.0.0.1:9100"}
下面有返回就是正常在运行

Grafana在docker进行部署
services:
grafana:
image: grafana/grafana:latest
container_name: grafana
restart: always
network_mode: host
user: "472" # 新增这一行,指定以 grafana 用户运行
ports:
- 3000:3000
volumes:
- ./data:/var/lib/grafana
在构建的时候,这个容器会一直在重启,因为data这个文件没有权限导致的,飞牛这个没有办法在页面进行操作的,需要在命令行输入的
cd /vol1/1000/内置文件/容器/Grafana
sudo chown -R 472:472 ./data
这个是我创建的文件地址,没有sudo权限,可临时用最大权限测试:
chmod -R 777 ./data
然后重新启动,就可以正常启动了(这个要看是什么硬盘了,我机械硬盘启动是有点慢的)
默认账号密码:admin / admin(首次登录会要求修改密码),不想修改密码可以点击 Skip 跳过密码修改
Grafana界面修改为中文
看着界面乱,看不懂,修改Grafana为中文


我这边就不切换界面了,位置是在这里,自己可以摸索一下看看
导入仪表盘
我这边是自定义导入的仪表盘,我写的JSON 模型
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "注解与告警",
"target": {
"limit": 100,
"matchAny": false,
"tags": [],
"type": "dashboard"
},
"type": "dashboard"
}
]
},
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 0,
"links": [],
"panels": [
{
"collapsed": false,
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 0
},
"id": 23,
"panels": [],
"title": "系统概览",
"type": "row"
},
{
"datasource": {
"type": "prometheus",
"uid": "cfh7ledolmmf4a"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"mappings": [],
"max": 100,
"min": 0,
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": 0
},
{
"color": "red",
"value": 80
}
]
},
"unit": "percent"
},
"overrides": []
},
"gridPos": {
"h": 4,
"w": 6,
"x": 0,
"y": 1
},
"id": 28,
"maxDataPoints": 100,
"options": {
"colorMode": "value",
"graphMode": "area",
"justifyMode": "auto",
"orientation": "auto",
"percentChangeColorMode": "standard",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"showPercentChange": false,
"textMode": "auto",
"wideLayout": true
},
"pluginVersion": "12.4.1",
"targets": [
{
"expr": "100 - (avg by (instance) (irate(node_cpu_seconds_total{mode=\"idle\",instance=~\"$node\"}[5m])) * 100)",
"interval": "",
"legendFormat": "CPU使用率",
"refId": "A"
}
],
"title": "CPU 使用率",
"type": "stat"
},
{
"datasource": {
"type": "prometheus",
"uid": "cfh7ledolmmf4a"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"mappings": [],
"max": 100,
"min": 0,
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": 0
},
{
"color": "red",
"value": 80
}
]
},
"unit": "percent"
},
"overrides": []
},
"gridPos": {
"h": 4,
"w": 6,
"x": 6,
"y": 1
},
"id": 29,
"maxDataPoints": 100,
"options": {
"colorMode": "value",
"graphMode": "area",
"justifyMode": "auto",
"orientation": "auto",
"percentChangeColorMode": "standard",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"showPercentChange": false,
"textMode": "auto",
"wideLayout": true
},
"pluginVersion": "12.4.1",
"targets": [
{
"expr": "100 - ((node_memory_MemAvailable_bytes{instance=~\"$node\"} * 100) / node_memory_MemTotal_bytes{instance=~\"$node\"})",
"interval": "",
"legendFormat": "内存使用率",
"refId": "A"
}
],
"title": "内存使用率",
"type": "stat"
},
{
"datasource": {
"type": "prometheus",
"uid": "cfh7ledolmmf4a"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"mappings": [],
"max": 100,
"min": 0,
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": 0
},
{
"color": "red",
"value": 80
}
]
},
"unit": "percent"
},
"overrides": []
},
"gridPos": {
"h": 4,
"w": 6,
"x": 12,
"y": 1
},
"id": 30,
"maxDataPoints": 100,
"options": {
"colorMode": "value",
"graphMode": "area",
"justifyMode": "auto",
"orientation": "auto",
"percentChangeColorMode": "standard",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"showPercentChange": false,
"textMode": "auto",
"wideLayout": true
},
"pluginVersion": "12.4.1",
"targets": [
{
"editorMode": "code",
"expr": "100 - ((node_filesystem_avail_bytes{instance=~\"$node\",mountpoint=\"/\",fstype!=\"rootfs\"} * 100) / node_filesystem_size_bytes{instance=~\"$node\",mountpoint=\"/\",fstype!=\"rootfs\"})",
"interval": "",
"legendFormat": "磁盘使用率",
"range": true,
"refId": "A"
}
],
"title": "系统盘使用率",
"type": "stat"
},
{
"datasource": {
"type": "prometheus",
"uid": "cfh7ledolmmf4a"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": 0
},
{
"color": "red",
"value": 80
}
]
},
"unit": "s"
},
"overrides": []
},
"gridPos": {
"h": 4,
"w": 6,
"x": 18,
"y": 1
},
"id": 31,
"maxDataPoints": 100,
"options": {
"colorMode": "value",
"graphMode": "area",
"justifyMode": "auto",
"orientation": "auto",
"percentChangeColorMode": "standard",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"showPercentChange": false,
"textMode": "auto",
"wideLayout": true
},
"pluginVersion": "12.4.1",
"targets": [
{
"editorMode": "code",
"expr": "node_time_seconds{instance=~\"$node\"} - node_boot_time_seconds{instance=~\"$node\"}",
"interval": "",
"legendFormat": "运行时长",
"range": true,
"refId": "A"
}
],
"title": "系统运行时长",
"type": "stat"
},
{
"collapsed": false,
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 5
},
"id": 24,
"panels": [],
"title": "CPU 详细监控",
"type": "row"
},
{
"datasource": {
"type": "prometheus",
"uid": "cfh7ledolmmf4a"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"barWidthFactor": 0.6,
"drawStyle": "line",
"fillOpacity": 10,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"showValues": false,
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "normal"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": 0
}
]
},
"unit": "percent"
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 16,
"x": 0,
"y": 6
},
"id": 32,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"hideZeros": false,
"mode": "single",
"sort": "none"
}
},
"pluginVersion": "12.4.1",
"targets": [
{
"editorMode": "code",
"exemplar": false,
"expr": "sum by (mode) (\r\n label_replace(\r\n label_replace(\r\n label_replace(\r\n label_replace(\r\n label_replace(\r\n label_replace(\r\n label_replace(\r\n label_replace(\r\n irate(node_cpu_seconds_total{instance=~\"$node\"}[5m]),\r\n \"mode\", \"空闲\", \"mode\", \"idle\"\r\n ),\r\n \"mode\", \"I/O等待\", \"mode\", \"iowait\"\r\n ),\r\n \"mode\", \"硬中断\", \"mode\", \"irq\"\r\n ),\r\n \"mode\", \"优先级进程\", \"mode\", \"nice\"\r\n ),\r\n \"mode\", \"软中断\", \"mode\", \"softirq\"\r\n ),\r\n \"mode\", \"虚拟机窃取\", \"mode\", \"steal\"\r\n ),\r\n \"mode\", \"内核态\", \"mode\", \"system\"\r\n ),\r\n \"mode\", \"用户态\", \"mode\", \"user\"\r\n )\r\n) * 100",
"interval": "",
"legendFormat": "{{mode}}",
"range": true,
"refId": "A"
}
],
"title": "CPU 各模式占用率",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "cfh7ledolmmf4a"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"barWidthFactor": 0.6,
"drawStyle": "line",
"fillOpacity": 10,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"showValues": false,
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": 0
}
]
},
"unit": "short"
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 8,
"x": 16,
"y": 6
},
"id": 33,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"hideZeros": false,
"mode": "single",
"sort": "none"
}
},
"pluginVersion": "12.4.1",
"targets": [
{
"editorMode": "code",
"expr": "node_load1{instance=~\"$node\"}",
"interval": "",
"legendFormat": "1分钟系统负载",
"range": true,
"refId": "A"
},
{
"expr": "node_load5{instance=~\"$node\"}",
"interval": "",
"legendFormat": "5分钟系统负载",
"refId": "B"
},
{
"expr": "node_load15{instance=~\"$node\"}",
"interval": "",
"legendFormat": "15分钟系统负载",
"refId": "C"
}
],
"title": "系统负载情况",
"type": "timeseries"
},
{
"collapsed": false,
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 14
},
"id": 25,
"panels": [],
"title": "内存详细监控",
"type": "row"
},
{
"datasource": {
"type": "prometheus",
"uid": "cfh7ledolmmf4a"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"barWidthFactor": 0.6,
"drawStyle": "line",
"fillOpacity": 10,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"showValues": false,
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "normal"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": 0
}
]
},
"unit": "bytes"
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 16,
"x": 0,
"y": 15
},
"id": 34,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"hideZeros": false,
"mode": "single",
"sort": "none"
}
},
"pluginVersion": "12.4.1",
"targets": [
{
"expr": "node_memory_MemTotal_bytes{instance=~\"$node\"} - node_memory_MemAvailable_bytes{instance=~\"$node\"}",
"interval": "",
"legendFormat": "已使用内存",
"refId": "A"
},
{
"expr": "node_memory_MemAvailable_bytes{instance=~\"$node\"}",
"interval": "",
"legendFormat": "可用内存",
"refId": "B"
},
{
"expr": "node_memory_Buffers_bytes{instance=~\"$node\"}",
"interval": "",
"legendFormat": "缓冲区内存",
"refId": "C"
},
{
"expr": "node_memory_Cached_bytes{instance=~\"$node\"}",
"interval": "",
"legendFormat": "缓存内存",
"refId": "D"
}
],
"title": "内存使用分布",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "cfh7ledolmmf4a"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"barWidthFactor": 0.6,
"drawStyle": "line",
"fillOpacity": 10,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"showValues": false,
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": 0
}
]
},
"unit": "bytes"
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 8,
"x": 16,
"y": 15
},
"id": 35,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"hideZeros": false,
"mode": "single",
"sort": "none"
}
},
"pluginVersion": "12.4.1",
"targets": [
{
"expr": "node_memory_SwapTotal_bytes{instance=~\"$node\"} - node_memory_SwapFree_bytes{instance=~\"$node\"}",
"interval": "",
"legendFormat": "已使用交换分区",
"refId": "A"
},
{
"expr": "node_memory_SwapFree_bytes{instance=~\"$node\"}",
"interval": "",
"legendFormat": "空闲交换分区",
"refId": "B"
}
],
"title": "交换分区使用情况",
"type": "timeseries"
},
{
"collapsed": false,
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 23
},
"id": 26,
"panels": [],
"title": "网络详细监控",
"type": "row"
},
{
"datasource": {
"type": "prometheus",
"uid": "cfh7ledolmmf4a"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"barWidthFactor": 0.6,
"drawStyle": "line",
"fillOpacity": 10,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"showValues": false,
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": 0
}
]
},
"unit": "Bps"
},
"overrides": []
},
"gridPos": {
"h": 13,
"w": 24,
"x": 0,
"y": 24
},
"id": 36,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"hideZeros": false,
"mode": "single",
"sort": "none"
}
},
"pluginVersion": "12.4.1",
"targets": [
{
"expr": "irate(node_network_receive_bytes_total{instance=~\"$node\",device!~\"lo\"}[5m])",
"interval": "",
"legendFormat": "{{device}} 下载流量",
"refId": "A"
},
{
"expr": "-irate(node_network_transmit_bytes_total{instance=~\"$node\",device!~\"lo\"}[5m])",
"interval": "",
"legendFormat": "{{device}} 上传流量",
"refId": "B"
}
],
"title": "网络进出流量",
"type": "timeseries"
},
{
"collapsed": false,
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 37
},
"id": 27,
"panels": [],
"title": "磁盘详细监控",
"type": "row"
},
{
"datasource": {
"type": "prometheus",
"uid": "cfh7ledolmmf4a"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"barWidthFactor": 0.6,
"drawStyle": "line",
"fillOpacity": 10,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"showValues": false,
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": 0
}
]
},
"unit": "bytes"
},
"overrides": []
},
"gridPos": {
"h": 10,
"w": 24,
"x": 0,
"y": 38
},
"id": 37,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"hideZeros": false,
"mode": "single",
"sort": "none"
}
},
"pluginVersion": "12.4.1",
"targets": [
{
"expr": "irate(node_disk_read_bytes_total{instance=~\"$node\",device!~\"loop|ram\"}[5m])",
"interval": "",
"legendFormat": "{{device}} 磁盘读取",
"refId": "A"
},
{
"expr": "-irate(node_disk_written_bytes_total{instance=~\"$node\",device!~\"loop|ram\"}[5m])",
"interval": "",
"legendFormat": "{{device}} 磁盘写入",
"refId": "B"
}
],
"title": "磁盘 I/O 流量",
"type": "timeseries"
}
],
"preload": false,
"refresh": "5s",
"schemaVersion": 42,
"tags": [],
"templating": {
"list": [
{
"current": {
"text": "All",
"value": "$__all"
},
"datasource": {
"type": "prometheus",
"uid": "cfh7ledolmmf4a"
},
"definition": "label_values(node_uname_info, instance)",
"description": "选择要监控的主机",
"includeAll": true,
"label": "监控主机",
"name": "node",
"options": [],
"query": {
"query": "label_values(node_uname_info, instance)",
"refId": "StandardVariableQuery"
},
"refresh": 1,
"regex": "",
"regexApplyTo": "value",
"sort": 1,
"type": "query"
}
]
},
"time": {
"from": "now-1h",
"to": "now"
},
"timepicker": {},
"timezone": "browser",
"title": "Node Exporter 主机监控 - 完整汉化版",
"uid": "node-exporter-cn-node",
"version": 7,
"weekStart": ""
}
写的是中文的,导入成功后,需要重新配置运行数据源
后面看到就是这样的

