2019-08-17 23:03:10 +00:00
|
|
|
import http from '@/api/http';
|
|
|
|
|
|
|
|
export type ServerPowerState = 'offline' | 'starting' | 'running' | 'stopping';
|
|
|
|
|
|
|
|
export interface ServerStats {
|
|
|
|
status: ServerPowerState;
|
|
|
|
isSuspended: boolean;
|
|
|
|
memoryUsageInBytes: number;
|
|
|
|
cpuUsagePercent: number;
|
|
|
|
diskUsageInBytes: number;
|
|
|
|
networkRxInBytes: number;
|
|
|
|
networkTxInBytes: number;
|
2021-10-24 17:12:17 +00:00
|
|
|
uptime: number;
|
2019-08-17 23:03:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default (server: string): Promise<ServerStats> => {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
http.get(`/api/client/servers/${server}/resources`)
|
|
|
|
.then(({ data: { attributes } }) => resolve({
|
|
|
|
status: attributes.current_state,
|
|
|
|
isSuspended: attributes.is_suspended,
|
|
|
|
memoryUsageInBytes: attributes.resources.memory_bytes,
|
|
|
|
cpuUsagePercent: attributes.resources.cpu_absolute,
|
|
|
|
diskUsageInBytes: attributes.resources.disk_bytes,
|
|
|
|
networkRxInBytes: attributes.resources.network_rx_bytes,
|
|
|
|
networkTxInBytes: attributes.resources.network_tx_bytes,
|
2021-10-24 17:12:17 +00:00
|
|
|
uptime: attributes.resources.uptime,
|
2019-08-17 23:03:10 +00:00
|
|
|
}))
|
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
};
|