优化Z轴
This commit is contained in:
@@ -626,8 +626,8 @@ async function recordTrafficStats() {
|
||||
const [rxBytesRes, txBytesRes, rxBWRes, txBWRes] = await Promise.all([
|
||||
prometheusService.query(source.url, 'sum(node_network_receive_bytes_total{device!~"lo|veth.*|docker.*|br-.*"})'),
|
||||
prometheusService.query(source.url, 'sum(node_network_transmit_bytes_total{device!~"lo|veth.*|docker.*|br-.*"})'),
|
||||
prometheusService.query(source.url, 'sum(rate(node_network_receive_bytes_total{device!~"lo|veth.*|docker.*|br-.*"}[5m]))'),
|
||||
prometheusService.query(source.url, 'sum(rate(node_network_transmit_bytes_total{device!~"lo|veth.*|docker.*|br-.*"}[5m]))')
|
||||
prometheusService.query(source.url, 'sum(rate(node_network_receive_bytes_total{device!~"lo|veth.*|docker.*|br-.*"}[1m]))'),
|
||||
prometheusService.query(source.url, 'sum(rate(node_network_transmit_bytes_total{device!~"lo|veth.*|docker.*|br-.*"}[1m]))')
|
||||
]);
|
||||
|
||||
return {
|
||||
@@ -648,15 +648,15 @@ async function recordTrafficStats() {
|
||||
totalTxBandwidth += r.txBW;
|
||||
}
|
||||
|
||||
if (totalRxBytes > 0 || totalTxBytes > 0) {
|
||||
await db.query('INSERT INTO traffic_stats (rx_bytes, tx_bytes, rx_bandwidth, tx_bandwidth) VALUES (?, ?, ?, ?)', [
|
||||
Math.round(totalRxBytes),
|
||||
Math.round(totalTxBytes),
|
||||
totalRxBandwidth,
|
||||
totalTxBandwidth
|
||||
]);
|
||||
console.log(`[Traffic Recorder] Saved stats: BW_RX=${totalRxBandwidth}, BW_TX=${totalTxBandwidth}`);
|
||||
}
|
||||
// Always insert a record if we have sources, so the timeline advances
|
||||
// Even if traffic is 0, we want to see 0 on the chart
|
||||
await db.query('INSERT INTO traffic_stats (rx_bytes, tx_bytes, rx_bandwidth, tx_bandwidth) VALUES (?, ?, ?, ?)', [
|
||||
Math.round(totalRxBytes),
|
||||
Math.round(totalTxBytes),
|
||||
totalRxBandwidth,
|
||||
totalTxBandwidth
|
||||
]);
|
||||
console.log(`[Traffic Recorder] Saved stats: BW_RX=${totalRxBandwidth.toFixed(2)}, BW_TX=${totalTxBandwidth.toFixed(2)}`);
|
||||
} catch (err) {
|
||||
console.error('[Traffic Recorder] Error recording stats:', err);
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ async function getOverviewMetrics(url, sourceName) {
|
||||
upResult
|
||||
] = await Promise.all([
|
||||
// CPU usage per instance: 1 - avg idle
|
||||
query(url, '100 - (avg by (instance, job) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)').catch(() => []),
|
||||
query(url, '100 - (avg by (instance, job) (rate(node_cpu_seconds_total{mode="idle"}[1m])) * 100)').catch(() => []),
|
||||
// CPU count per instance
|
||||
query(url, 'count by (instance, job) (node_cpu_seconds_total{mode="idle"})').catch(() => []),
|
||||
// Memory total per instance
|
||||
@@ -164,9 +164,9 @@ async function getOverviewMetrics(url, sourceName) {
|
||||
// Disk free per instance (root filesystem + /data)
|
||||
query(url, 'sum by (instance, job) (node_filesystem_free_bytes{mountpoint=~"/|/data",fstype!="tmpfs"})').catch(() => []),
|
||||
// Network receive rate (bytes/sec)
|
||||
query(url, 'sum by (instance, job) (rate(node_network_receive_bytes_total{device!~"lo|veth.*|docker.*|br-.*"}[5m]))').catch(() => []),
|
||||
query(url, 'sum by (instance, job) (rate(node_network_receive_bytes_total{device!~"lo|veth.*|docker.*|br-.*"}[1m]))').catch(() => []),
|
||||
// Network transmit rate (bytes/sec)
|
||||
query(url, 'sum by (instance, job) (rate(node_network_transmit_bytes_total{device!~"lo|veth.*|docker.*|br-.*"}[5m]))').catch(() => []),
|
||||
query(url, 'sum by (instance, job) (rate(node_network_transmit_bytes_total{device!~"lo|veth.*|docker.*|br-.*"}[1m]))').catch(() => []),
|
||||
// Total traffic received in last 24h
|
||||
query(url, 'sum by (instance, job) (increase(node_network_receive_bytes_total{device!~"lo|veth.*|docker.*|br-.*"}[24h]))').catch(() => []),
|
||||
// Total traffic transmitted in last 24h
|
||||
@@ -327,11 +327,11 @@ async function getNetworkHistory(url) {
|
||||
|
||||
const [rxResult, txResult] = await Promise.all([
|
||||
queryRange(url,
|
||||
'sum(rate(node_network_receive_bytes_total{device!~"lo|veth.*|docker.*|br-.*"}[5m]))',
|
||||
'sum(rate(node_network_receive_bytes_total{device!~"lo|veth.*|docker.*|br-.*"}[1m]))',
|
||||
start, now, step
|
||||
).catch(() => []),
|
||||
queryRange(url,
|
||||
'sum(rate(node_network_transmit_bytes_total{device!~"lo|veth.*|docker.*|br-.*"}[5m]))',
|
||||
'sum(rate(node_network_transmit_bytes_total{device!~"lo|veth.*|docker.*|br-.*"}[1m]))',
|
||||
start, now, step
|
||||
).catch(() => [])
|
||||
]);
|
||||
@@ -380,7 +380,7 @@ async function getCpuHistory(url) {
|
||||
const step = 60; // 1 minute
|
||||
|
||||
const result = await queryRange(url,
|
||||
'100 - (avg(rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)',
|
||||
'100 - (avg(rate(node_cpu_seconds_total{mode="idle"}[1m])) * 100)',
|
||||
start, now, step
|
||||
).catch(() => []);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user