[修改]node-exporter特权模式

This commit is contained in:
10908
2024-09-23 14:40:41 +08:00
committed by Coding
parent 0938336791
commit d59cf061ab
4 changed files with 11 additions and 6 deletions

View File

@@ -22,6 +22,9 @@ services:
- prometheus
node-exporter:
build: docker/node_exporter
privileged: true
volumes:
- '/:/host:ro'
opcua-exporter:
build: opcua-exporter
## volumes:

View File

@@ -22,4 +22,6 @@ RUN architecture=$(uname -m); \
exit 1; \
fi
CMD ["node_exporter"]
RUN mkdir /host
CMD ["node_exporter","--path.rootfs=/host"]

View File

@@ -36,7 +36,7 @@ class NetworkMonitor extends ChartWidget
if ($selectedFilter === 'upload') {
// 查询过去 1 分钟内每秒的上传流量
$uploadQuery = 'rate(node_network_transmit_bytes_total[1m])';
$uploadQuery = 'rate(node_network_transmit_bytes_total{device="eth0"}[1m])';
$uploadResult = $prometheus->queryRange(
$uploadQuery,
now()->subMinutes(1)->timestamp,
@@ -55,14 +55,14 @@ class NetworkMonitor extends ChartWidget
foreach ($timestamps as $timestamp) {
$labels[] = date('H:i:s', $timestamp); // 格式化时间戳为小时:分钟:秒
$uploadData[] = round(floatval($uploadValues[$timestamp]) / (1024 * 1024), 2); // 转换为 MB/s
$uploadData[] = round(floatval($uploadValues[$timestamp]) / (1024*1024), 2); // 转换为 MB/s
}
}
}
if ($selectedFilter === 'download') {
// 查询过去 1 分钟内每秒的下载流量
$downloadQuery = 'rate(node_network_receive_bytes_total[1m])';
$downloadQuery = 'rate(node_network_receive_bytes_total{device="eth0"}[1m])';
$downloadResult = $prometheus->queryRange(
$downloadQuery,
now()->subMinutes(1)->timestamp,

View File

@@ -27,14 +27,14 @@ class SystemStats extends BaseWidget
$memoryDisplay = round($memoryUsed / (1024 * 1024 * 1024), 2) . ' GB / ' . round($memoryTotal / (1024 * 1024 * 1024), 2) . ' GB';
// 获取硬盘总量
$diskTotalQuery = 'node_filesystem_size_bytes{fstype!="rootfs",fstype!="tmpfs",fstype!="squashfs"}';
$diskTotalQuery = 'node_filesystem_size_bytes{fstype!="rootfs",fstype!="tmpfs",fstype!="squashfs",mountpoint=~"/|/home|/boot"}';
$diskTotalResult = $prometheus->query($diskTotalQuery);
$diskTotal = array_sum(array_map(function ($item) {
return $item['value'][1] ?? 0;
}, $diskTotalResult['data']['result']));
// 获取已用硬盘
$diskFreeQuery = 'node_filesystem_free_bytes{fstype!="rootfs",fstype!="tmpfs",fstype!="squashfs"}';
$diskFreeQuery = 'node_filesystem_free_bytes{fstype!="rootfs",fstype!="tmpfs",fstype!="squashfs",mountpoint=~"/|/home|/boot"}';
$diskFreeResult = $prometheus->query($diskFreeQuery);
$diskFree = array_sum(array_map(function ($item) {
return $item['value'][1] ?? 0;