Skip to content

Commit 81ba333

Browse files
committed
If uptime is present in stats output, display it for the server; closes pterodactyl#3653
1 parent 63e01f9 commit 81ba333

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

resources/scripts/components/server/ServerDetailsBlock.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ import TitledGreyBox from '@/components/elements/TitledGreyBox';
77
import { ServerContext } from '@/state/server';
88
import CopyOnClick from '@/components/elements/CopyOnClick';
99
import { SocketEvent, SocketRequest } from '@/components/server/events';
10+
import UptimeDuration from '@/components/server/UptimeDuration';
1011

1112
interface Stats {
1213
memory: number;
1314
cpu: number;
1415
disk: number;
16+
uptime: number;
1517
}
1618

17-
function statusToColor (status: string|null, installing: boolean): TwStyle {
19+
function statusToColor (status: string | null, installing: boolean): TwStyle {
1820
if (installing) {
1921
status = '';
2022
}
@@ -30,7 +32,7 @@ function statusToColor (status: string|null, installing: boolean): TwStyle {
3032
}
3133

3234
const ServerDetailsBlock = () => {
33-
const [ stats, setStats ] = useState<Stats>({ memory: 0, cpu: 0, disk: 0 });
35+
const [ stats, setStats ] = useState<Stats>({ memory: 0, cpu: 0, disk: 0, uptime: 0 });
3436

3537
const status = ServerContext.useStoreState(state => state.status.value);
3638
const connected = ServerContext.useStoreState(state => state.socket.connected);
@@ -48,6 +50,7 @@ const ServerDetailsBlock = () => {
4850
memory: stats.memory_bytes,
4951
cpu: stats.cpu_absolute,
5052
disk: stats.disk_bytes,
53+
uptime: stats.uptime || 0,
5154
});
5255
};
5356

@@ -69,7 +72,7 @@ const ServerDetailsBlock = () => {
6972
const isTransferring = ServerContext.useStoreState(state => state.server.data!.isTransferring);
7073
const limits = ServerContext.useStoreState(state => state.server.data!.limits);
7174
const primaryAllocation = ServerContext.useStoreState(state => state.server.data!.allocations.filter(alloc => alloc.isDefault).map(
72-
allocation => (allocation.alias || allocation.ip) + ':' + allocation.port
75+
allocation => (allocation.alias || allocation.ip) + ':' + allocation.port,
7376
)).toString();
7477

7578
const diskLimit = limits.disk ? megabytesToHuman(limits.disk) : 'Unlimited';
@@ -88,6 +91,11 @@ const ServerDetailsBlock = () => {
8891
]}
8992
/>
9093
&nbsp;{!status ? 'Connecting...' : (isInstalling ? 'Installing' : (isTransferring) ? 'Transferring' : status)}
94+
{stats.uptime > 0 &&
95+
<span css={tw`ml-2`}>
96+
(<UptimeDuration uptime={stats.uptime / 1000}/>)
97+
</span>
98+
}
9199
</p>
92100
<CopyOnClick text={primaryAllocation}>
93101
<p css={tw`text-xs mt-2`}>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from 'react';
2+
3+
export default ({ uptime }: { uptime: number }) => {
4+
const hours = Math.floor(Math.floor(uptime) / 60 / 60);
5+
const remainder = Math.floor(uptime - (hours * 60 * 60));
6+
const minutes = Math.floor(remainder / 60);
7+
const seconds = remainder % 60;
8+
9+
return (
10+
<>
11+
{hours.toString().padStart(2, '0')}:{minutes.toString().padStart(2, '0')}:{seconds.toString().padStart(2, '0')}
12+
</>
13+
);
14+
};

0 commit comments

Comments
 (0)