Fixes rounding when 0.001% or less on CPU usage. (#4207)
This commit is contained in:
parent
ccea09c9d9
commit
cc06d1faa9
2 changed files with 4 additions and 5 deletions
|
@ -16,7 +16,7 @@ export default () => {
|
||||||
const limits = ServerContext.useStoreState((state) => state.server.data!.limits);
|
const limits = ServerContext.useStoreState((state) => state.server.data!.limits);
|
||||||
const previous = useRef<Record<'tx' | 'rx', number>>({ tx: -1, rx: -1 });
|
const previous = useRef<Record<'tx' | 'rx', number>>({ tx: -1, rx: -1 });
|
||||||
|
|
||||||
const cpu = useChartTickLabel('CPU', limits.cpu, '%');
|
const cpu = useChartTickLabel('CPU', limits.cpu, '%', 2);
|
||||||
const memory = useChartTickLabel('Memory', limits.memory, 'MB');
|
const memory = useChartTickLabel('Memory', limits.memory, 'MB');
|
||||||
const network = useChart('Network', {
|
const network = useChart('Network', {
|
||||||
sets: 2,
|
sets: 2,
|
||||||
|
@ -56,8 +56,7 @@ export default () => {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
cpu.push(values.cpu_absolute);
|
||||||
cpu.push(values.cpu_absolute.toFixed(2));
|
|
||||||
memory.push(Math.floor(values.memory_bytes / 1024 / 1024));
|
memory.push(Math.floor(values.memory_bytes / 1024 / 1024));
|
||||||
network.push([
|
network.push([
|
||||||
previous.current.tx < 0 ? 0 : Math.max(0, values.network.tx_bytes - previous.current.tx),
|
previous.current.tx < 0 ? 0 : Math.max(0, values.network.tx_bytes - previous.current.tx),
|
||||||
|
|
|
@ -139,7 +139,7 @@ function useChart(label: string, opts?: UseChartOptions) {
|
||||||
return { props: { data, options }, push, clear };
|
return { props: { data, options }, push, clear };
|
||||||
}
|
}
|
||||||
|
|
||||||
function useChartTickLabel(label: string, max: number, tickLabel: string) {
|
function useChartTickLabel(label: string, max: number, tickLabel: string, roundTo?: number) {
|
||||||
return useChart(label, {
|
return useChart(label, {
|
||||||
sets: 1,
|
sets: 1,
|
||||||
options: {
|
options: {
|
||||||
|
@ -148,7 +148,7 @@ function useChartTickLabel(label: string, max: number, tickLabel: string) {
|
||||||
suggestedMax: max,
|
suggestedMax: max,
|
||||||
ticks: {
|
ticks: {
|
||||||
callback(value) {
|
callback(value) {
|
||||||
return `${value}${tickLabel}`;
|
return `${roundTo ? Number(value).toFixed(roundTo) : value}${tickLabel}`;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue