feat(detail): last active time info

This commit is contained in:
hamster1963 2024-12-06 10:28:39 +08:00
parent f39f480028
commit b80af34a45
5 changed files with 46 additions and 13 deletions

View File

@ -56,6 +56,7 @@ export default function ServerDetailOverview({
load_15, load_15,
net_out_transfer, net_out_transfer,
net_in_transfer, net_in_transfer,
last_active_time_string,
} = formatNezhaInfo(nezhaWsData.now, server); } = formatNezhaInfo(nezhaWsData.now, server);
return ( return (
@ -88,7 +89,8 @@ export default function ServerDetailOverview({
</section> </section>
</CardContent> </CardContent>
</Card> </Card>
<Card className="rounded-[10px] bg-transparent border-none shadow-none"> {online && (
<Card className="rounded-[10px] bg-transparent border-none shadow-none">
<CardContent className="px-1.5 py-1"> <CardContent className="px-1.5 py-1">
<section className="flex flex-col items-start gap-0.5"> <section className="flex flex-col items-start gap-0.5">
<p className="text-xs text-muted-foreground"> <p className="text-xs text-muted-foreground">
@ -102,6 +104,7 @@ export default function ServerDetailOverview({
</section> </section>
</CardContent> </CardContent>
</Card> </Card>
)}
{version && ( {version && (
<Card className="rounded-[10px] bg-transparent border-none shadow-none"> <Card className="rounded-[10px] bg-transparent border-none shadow-none">
<CardContent className="px-1.5 py-1"> <CardContent className="px-1.5 py-1">
@ -126,7 +129,10 @@ export default function ServerDetailOverview({
</CardContent> </CardContent>
</Card> </Card>
)} )}
<Card className="rounded-[10px] bg-transparent border-none shadow-none">
{mem_total ? (<Card className="rounded-[10px] bg-transparent border-none shadow-none">
<CardContent className="px-1.5 py-1"> <CardContent className="px-1.5 py-1">
<section className="flex flex-col items-start gap-0.5"> <section className="flex flex-col items-start gap-0.5">
<p className="text-xs text-muted-foreground"> <p className="text-xs text-muted-foreground">
@ -135,8 +141,11 @@ export default function ServerDetailOverview({
<div className="text-xs">{formatBytes(mem_total)}</div> <div className="text-xs">{formatBytes(mem_total)}</div>
</section> </section>
</CardContent> </CardContent>
</Card> </Card>) : null}
<Card className="rounded-[10px] bg-transparent border-none shadow-none">
{disk_total ? (<Card className="rounded-[10px] bg-transparent border-none shadow-none">
<CardContent className="px-1.5 py-1"> <CardContent className="px-1.5 py-1">
<section className="flex flex-col items-start gap-0.5"> <section className="flex flex-col items-start gap-0.5">
<p className="text-xs text-muted-foreground"> <p className="text-xs text-muted-foreground">
@ -145,7 +154,10 @@ export default function ServerDetailOverview({
<div className="text-xs">{formatBytes(disk_total)}</div> <div className="text-xs">{formatBytes(disk_total)}</div>
</section> </section>
</CardContent> </CardContent>
</Card> </Card>) : null}
{country_code && ( {country_code && (
<Card className="rounded-[10px] bg-transparent border-none shadow-none"> <Card className="rounded-[10px] bg-transparent border-none shadow-none">
<CardContent className="px-1.5 py-1"> <CardContent className="px-1.5 py-1">
@ -211,14 +223,14 @@ export default function ServerDetailOverview({
<CardContent className="px-1.5 py-1"> <CardContent className="px-1.5 py-1">
<section className="flex flex-col items-start gap-0.5"> <section className="flex flex-col items-start gap-0.5">
<p className="text-xs text-muted-foreground">{"Load"}</p> <p className="text-xs text-muted-foreground">{"Load"}</p>
<div className="text-xs"> <div className="text-xs">
{load_1} / {load_5} / {load_15} {load_1} / {load_5} / {load_15}
</div> </div>
</section> </section>
</CardContent> </CardContent>
</Card> </Card>
<Card className="rounded-[10px] bg-transparent border-none shadow-none"> {net_out_transfer ? (
<Card className="rounded-[10px] bg-transparent border-none shadow-none">
<CardContent className="px-1.5 py-1"> <CardContent className="px-1.5 py-1">
<section className="flex flex-col items-start gap-0.5"> <section className="flex flex-col items-start gap-0.5">
<p className="text-xs text-muted-foreground"> <p className="text-xs text-muted-foreground">
@ -232,7 +244,8 @@ export default function ServerDetailOverview({
</section> </section>
</CardContent> </CardContent>
</Card> </Card>
<Card className="rounded-[10px] bg-transparent border-none shadow-none"> ): null}
{net_in_transfer ? (<Card className="rounded-[10px] bg-transparent border-none shadow-none">
<CardContent className="px-1.5 py-1"> <CardContent className="px-1.5 py-1">
<section className="flex flex-col items-start gap-0.5"> <section className="flex flex-col items-start gap-0.5">
<p className="text-xs text-muted-foreground"> <p className="text-xs text-muted-foreground">
@ -245,7 +258,7 @@ export default function ServerDetailOverview({
)} )}
</section> </section>
</CardContent> </CardContent>
</Card> </Card>): null}
</section> </section>
{server?.state.temperatures && server?.state.temperatures.length > 0 && ( {server?.state.temperatures && server?.state.temperatures.length > 0 && (
<section className="flex flex-wrap gap-2 mt-1"> <section className="flex flex-wrap gap-2 mt-1">
@ -266,6 +279,20 @@ export default function ServerDetailOverview({
</Card> </Card>
</section> </section>
)} )}
<section className="flex flex-wrap gap-2 mt-1">
<Card className="rounded-[10px] bg-transparent border-none shadow-none">
<CardContent className="px-1.5 py-1">
<section className="flex flex-col items-start gap-0.5">
<p className="text-xs text-muted-foreground">
{t("serverDetail.lastActive")}
</p>
<div className="text-xs">
{last_active_time_string ? last_active_time_string : "N/A"}
</div>
</section>
</CardContent>
</Card>
</section>
</div> </div>
); );
} }

View File

@ -7,13 +7,16 @@ export function cn(...inputs: ClassValue[]) {
} }
export function formatNezhaInfo(now: number, serverInfo: NezhaServer) { export function formatNezhaInfo(now: number, serverInfo: NezhaServer) {
const lastActiveTime = parseISOTimestamp(serverInfo.last_active); const lastActiveTime = serverInfo.last_active.startsWith("000") ? 0 : parseISOTimestamp(serverInfo.last_active);
return { return {
...serverInfo, ...serverInfo,
cpu: serverInfo.state.cpu || 0, cpu: serverInfo.state.cpu || 0,
process: serverInfo.state.process_count || 0, process: serverInfo.state.process_count || 0,
up: serverInfo.state.net_out_speed / 1024 / 1024 || 0, up: serverInfo.state.net_out_speed / 1024 / 1024 || 0,
down: serverInfo.state.net_in_speed / 1024 / 1024 || 0, down: serverInfo.state.net_in_speed / 1024 / 1024 || 0,
last_active_time_string: lastActiveTime
? new Date(lastActiveTime).toLocaleString()
: "",
online: now - lastActiveTime <= 30000, online: now - lastActiveTime <= 30000,
uptime: serverInfo.state.uptime || 0, uptime: serverInfo.state.uptime || 0,
version: serverInfo.host.version || null, version: serverInfo.host.version || null,

View File

@ -60,7 +60,8 @@
"region": "Region", "region": "Region",
"system": "System", "system": "System",
"upload": "Upload", "upload": "Upload",
"download": "Download" "download": "Download",
"lastActive": "Last active time"
}, },
"serverDetailChart": { "serverDetailChart": {
"process": "Process", "process": "Process",

View File

@ -60,7 +60,8 @@
"region": "区域", "region": "区域",
"system": "系统", "system": "系统",
"upload": "上传", "upload": "上传",
"download": "下载" "download": "下载",
"lastActive": "最后上报时间"
}, },
"serverDetailChart": { "serverDetailChart": {
"process": "进程数", "process": "进程数",

View File

@ -60,7 +60,8 @@
"region": "地區", "region": "地區",
"system": "系統", "system": "系統",
"upload": "上傳", "upload": "上傳",
"download": "下載" "download": "下載",
"lastActive": "最後上報時間"
}, },
"serverDetailChart": { "serverDetailChart": {
"process": "進程數", "process": "進程數",