feat: 资源监控信息

This commit is contained in:
TsMask
2023-11-01 17:45:21 +08:00
parent a824e64063
commit dcbd75b8c9
4 changed files with 644 additions and 0 deletions

View File

@@ -91,3 +91,30 @@ export function parseObjLineToHump(obj: any): any {
}
return obj;
}
/**
* 转换磁盘容量
* @param size 数值大小
* @returns
*/
export function parseSizeFromMB(size: number): string {
const num = 1024.0;
if (size < num) return size + ' MB';
if (size < Math.pow(num, 2)) return (size / num).toFixed(2) + ' GB';
return (size / Math.pow(num, 3)).toFixed(2) + ' TB';
}
/**
* 转换网络速率
* @param size 数值大小
* @returns
*/
export function parseSizeFromKBs(size: number): string {
const num = 1024.0;
if (size < num) return size + ' KB/s';
if (size < Math.pow(num, 2)) return (size / num).toFixed(2) + ' MB/s';
if (size < Math.pow(num, 3)) {
return (size / Math.pow(num, 2)).toFixed(2) + ' GB/s';
}
return (size / Math.pow(num, 3)).toFixed(2) + ' TB/s';
}