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

@@ -72,3 +72,18 @@ export function diffValue(
if (Number.isNaN(value)) return 0;
return value;
}
/**
* 格式时间不带年份
*
* 年-月\n时:分 列如10-13 \n 15:13
* @returns MM-DD\nHH:mm
*/
export function parseDateWithoutYear(date: string | number | Date) {
const day = dayjs(date);
const M: string = `${day.month() + 1}`.padStart(2, '0');
const D: string = `${day.date()}`.padStart(2, '0');
const H: string = `${day.hour()}`.padStart(2, '0');
const m: string = `${day.minute()}`.padStart(2, '0');
return `${M}-${D}\n${H}:${m}`;
}

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';
}