Skip to content

Commit

Permalink
Refactor net.html to update interval calculation for network speed chart
Browse files Browse the repository at this point in the history
  • Loading branch information
arloor committed Oct 25, 2024
1 parent 041bcf8 commit af86c28
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
13 changes: 12 additions & 1 deletion rust_http_proxy/html/net.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@
},
},
];
let max = series.map(s => s.data).flat().reduce((a, b) => Math.max(a, b));
let interval = 0;
if (max > 1024 * 1024 * 8) {
interval = 1024 * 1024 * 8
} else {
interval = 1024 * 1024
};
if (max / interval > 10) {
interval = (max / interval / 10) * interval;
}
console.log("interval is", interval);
// 指定图表的配置项和数据
var option = {
title: {
Expand Down Expand Up @@ -118,7 +129,7 @@
interval = Math.pow(k, c);
return Math.ceil(value.max / interval) * interval;
},
interval: {{ interval }},
interval: interval,
axisLabel: {
formatter: (value, index) => formatDataRateIEC(value)
},
Expand Down
17 changes: 1 addition & 16 deletions rust_http_proxy/src/linux_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,30 +99,15 @@ impl NetMonitor {
let mut scales = vec![];
let mut series_up = vec![];
let mut series_down = vec![];
let mut max = 0;
for x in r {
scales.push(x.time);
series_up.push(x.egress);
series_down.push(x.ingress);
if x.egress > max {
max = x.egress;
}
if x.ingress > max {
max = x.ingress;
}
}
let mut interval = if max > 1024 * 1024 * 8 {
1024 * 1024 * 8
} else {
1024 * 1024
};
if max / interval > 10 {
interval = (max / interval / 10) * interval;
}

// 创建上下文并插入数据
let mut context = tera::Context::new();
context.insert("hostname", hostname);
context.insert("interval", &interval);
context.insert("series_up", format!("{:?}", series_up).as_str());
context.insert("series_down", format!("{:?}", series_down).as_str());
context.insert("scales", format!("{:?}", scales).as_str());
Expand Down

0 comments on commit af86c28

Please sign in to comment.