add load averages

This commit is contained in:
MCHost
2025-07-14 23:19:28 -04:00
parent 3edb73ca1d
commit 53a4c0829a
2 changed files with 175 additions and 17 deletions

View File

@@ -1,3 +1,4 @@
// server.js
const express = require('express');
const http = require('http');
const WebSocket = require('ws');
@@ -166,7 +167,7 @@ async function getDockerStats() {
async function getNetdataMetrics() {
if (!NETDATA_URL) {
console.error('Cannot fetch Netdata metrics: NETDATA_URL is undefined.');
return { cpu: [], ram: [], net: [], disk: [], disk_space: [], anomaly: [] };
return { cpu: [], ram: [], net: [], disk: [], disk_space: [], anomaly: [], load: [] };
}
try {
@@ -176,7 +177,8 @@ async function getNetdataMetrics() {
{ key: 'net', url: `${NETDATA_URL}/api/v3/data?contexts=system.net&group_by=dimension&group=average&after=-60&points=30&format=json`, map: d => ({ time: d[0], received: d[1], sent: d[2] }) },
{ key: 'disk', url: `${NETDATA_URL}/api/v3/data?contexts=system.io&group_by=dimension&group=average&after=-60&points=30&format=json`, map: d => ({ time: d[0], in: d[1], out: d[2] }) },
{ key: 'disk_space', url: `${NETDATA_URL}/api/v3/data?contexts=disk.space&labels=mount_point:%2F&group_by=dimension&group=average&after=-60&points=30&format=json`, map: d => ({ time: d[0], avail: d[1], used: d[2], reserved: d[3] }) },
{ key: 'anomaly', url: `${NETDATA_URL}/api/v3/data?contexts=anomaly_detection.dimensions&scope_nodes=mchost&group_by=dimension&group=average&after=-60&points=30&format=json`, map: d => ({ time: d[0], anomalous: d[1], normal: d[2] }) }
{ key: 'anomaly', url: `${NETDATA_URL}/api/v3/data?contexts=anomaly_detection.dimensions&scope_nodes=mchost&group_by=dimension&group=average&after=-60&points=30&format=json`, map: d => ({ time: d[0], anomalous: d[1], normal: d[2] }) },
{ key: 'load', url: `${NETDATA_URL}/api/v3/data?contexts=system.load&group_by=dimension&group=average&after=-60&points=30&format=json`, map: d => ({ time: d[0], load1: d[1], load5: d[2], load15: d[3] }) }
];
const results = await Promise.all(
@@ -204,7 +206,7 @@ async function getNetdataMetrics() {
return metrics;
} catch (error) {
console.error('Error fetching Netdata metrics:', error.message);
return { cpu: [], ram: [], net: [], disk: [], disk_space: [], anomaly: [] };
return { cpu: [], ram: [], net: [], disk: [], disk_space: [], anomaly: [], load: [] };
}
}
@@ -212,7 +214,7 @@ async function getNetdataMetrics() {
async function getJumpNodeMetrics() {
if (!NETDATA_JUMP_URL) {
console.error('Cannot fetch Jump Node metrics: NETDATA_JUMP_URL is undefined.');
return { cpu: [], ram: [], net: [], disk: [], anomaly: [], disk_space: [], uptime: [] };
return { cpu: [], ram: [], net: [], disk: [], anomaly: [], disk_space: [], uptime: [], load: [] };
}
try {
@@ -222,7 +224,8 @@ async function getJumpNodeMetrics() {
{ key: 'disk', url: `${NETDATA_JUMP_URL}/api/v3/data?contexts=system.io&group_by=dimension&group=average&after=-60&points=30&format=json`, map: d => ({ time: d[0], in: d[1], out: d[2] }) },
{ key: 'anomaly', url: `${NETDATA_JUMP_URL}/api/v3/data?contexts=anomaly_detection.dimensions&scope_nodes=my-mc-link&group_by=dimension&group=average&after=-60&points=30&format=json`, map: d => ({ time: d[0], anomalous: d[1], normal: d[2] }) },
{ key: 'disk_space', url: `${NETDATA_JUMP_URL}/api/v3/data?contexts=disk.space&labels=mount_point:%2F&group_by=dimension&group=average&after=-60&points=30&format=json`, map: d => ({ time: d[0], avail: d[1], used: d[2], reserved: d[3] }) },
{ key: 'uptime', url: `${NETDATA_JUMP_URL}/api/v3/data?contexts=system.uptime&group_by=dimension&group=average&after=-60&points=30&format=json`, map: d => ({ time: d[0], uptime: d[1] }) }
{ key: 'uptime', url: `${NETDATA_JUMP_URL}/api/v3/data?contexts=system.uptime&group_by=dimension&group=average&after=-60&points=30&format=json`, map: d => ({ time: d[0], uptime: d[1] }) },
{ key: 'load', url: `${NETDATA_JUMP_URL}/api/v3/data?contexts=system.load&group_by=dimension&group=average&after=-60&points=30&format=json`, map: d => ({ time: d[0], load1: d[1], load5: d[2], load15: d[3] }) }
];
const results = await Promise.all(
@@ -255,11 +258,12 @@ async function getJumpNodeMetrics() {
disk: metrics.disk || [],
anomaly: metrics.anomaly || [],
disk_space: metrics.disk_space || [],
uptime: metrics.uptime || []
uptime: metrics.uptime || [],
load: metrics.load || []
};
} catch (error) {
console.error('Error fetching Jump Node metrics:', error.message);
return { cpu: [], ram: [], net: [], disk: [], anomaly: [], disk_space: [], uptime: [] };
return { cpu: [], ram: [], net: [], disk: [], anomaly: [], disk_space: [], uptime: [], load: [] };
}
}
@@ -274,8 +278,8 @@ wss.on('connection', (ws) => {
// Send updates every 1 second
const interval = setInterval(async () => {
let dockerStats = {};
let netdataMetrics = { cpu: [], ram: [], net: [], disk: [], disk_space: [], anomaly: [] };
let jumpNodeMetrics = { cpu: [], ram: [], net: [], disk: [], anomaly: [], disk_space: [], uptime: [] };
let netdataMetrics = { cpu: [], ram: [], net: [], disk: [], disk_space: [], anomaly: [], load: [] };
let jumpNodeMetrics = { cpu: [], ram: [], net: [], disk: [], anomaly: [], disk_space: [], uptime: [], load: [] };
let holesailProcessCount = 0;
try {