mirror of
				https://github.com/pelican-dev/panel.git
				synced 2025-11-04 15:36:52 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			30 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			30 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
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;
 | 
						|
}
 | 
						|
 | 
						|
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,
 | 
						|
            }))
 | 
						|
            .catch(reject);
 | 
						|
    });
 | 
						|
};
 |