-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.js
37 lines (28 loc) · 946 Bytes
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import os from "os";
import { exec } from "child_process";
import { promisify } from "util";
import logger from "./logger.js";
const execPromise = promisify(exec);
export const getTotalDiskSpace = () => {
const totalDiskSpaceInBytes = os.totalmem();
const totalDiskSpaceInGB = (totalDiskSpaceInBytes / 1024 ** 3).toFixed(2) + " GB";
return totalDiskSpaceInGB;
};
export const getNetworkStats = async () => {
try {
const { stdout } = await execPromise("netstat -e");
const lines = stdout.split("\n");
const networkStats = {
sent: lines[2] ? lines[2].trim().split(/\s+/)[1] : "N/A",
received: lines[2] ? lines[2].trim().split(/\s+/)[0] : "N/A",
};
return networkStats;
} catch (error) {
logger.error("Error fetching network stats: For full log see your log file");
return {
sent: "N/A",
received: "N/A",
};
}
};
logger.info("Utils.js has been initialized successfully");