mirror of
https://github.com/karl0ss/homepage.git
synced 2025-05-20 13:16:19 +01:00
format uptime
This commit is contained in:
parent
25f27dcfdd
commit
300bb3487e
@ -302,6 +302,7 @@
|
||||
"truenas": {
|
||||
"load": "System Load",
|
||||
"uptime": "Uptime",
|
||||
"alerts": "Alerts"
|
||||
"alerts": "Alerts",
|
||||
"time": "{{value, number(style: unit; unitDisplay: long;)}}"
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,35 @@ import Container from "components/services/widget/container";
|
||||
import Block from "components/services/widget/block";
|
||||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||
|
||||
const processUptime = uptime => {
|
||||
|
||||
let seconds = uptime.toFixed(0);
|
||||
|
||||
var levels = [
|
||||
[Math.floor(seconds / 31536000), 'year'],
|
||||
[Math.floor((seconds % 31536000) / 2592000), 'month'],
|
||||
[Math.floor(((seconds % 31536000) % 2592000) / 86400), 'day'],
|
||||
[Math.floor(((seconds % 31536000) % 86400) / 3600), 'hour'],
|
||||
[Math.floor((((seconds % 31536000) % 86400) % 3600) / 60), 'minute'],
|
||||
[(((seconds % 31536000) % 86400) % 3600) % 60, 'second'],
|
||||
];
|
||||
|
||||
for(let i = 0; i< levels.length; i++){
|
||||
let level = levels[i];
|
||||
if(level[0] > 0){
|
||||
return {
|
||||
value: level[0],
|
||||
unit: level[1]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
value: 0,
|
||||
unit: 'second'
|
||||
};
|
||||
}
|
||||
|
||||
export default function Component({ service }) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
@ -25,13 +54,12 @@ export default function Component({ service }) {
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="truenas.load" value={t("common.number", { value: statusData.loadavg[0] })} />
|
||||
<Block label="truenas.uptime" value={statusData.uptime.substring(0,statusData.uptime.length-7)} />
|
||||
<Block label="truenas.uptime" value={t('truenas.time', processUptime(statusData.uptime_seconds))} />
|
||||
<Block label="truenas.alerts" value={t("common.number", { value: alertData.pending })} />
|
||||
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user