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