@darkpos/utils 1.0.11 → 1.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/localization.js +1 -1
- package/lib/system.js +46 -21
- package/package.json +2 -2
package/lib/localization.js
CHANGED
package/lib/system.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
const os = require('os');
|
|
2
|
-
|
|
3
1
|
const interval = process.env.DRK_LOGGER_INTERVAL || 60 * 60;
|
|
4
|
-
const freeMemory =
|
|
5
|
-
const totalMemory =
|
|
2
|
+
const freeMemory = os => Math.round(os.freemem() / (1024 * 1024));
|
|
3
|
+
const totalMemory = os => Math.round(os.totalmem() / (1024 * 1024));
|
|
6
4
|
const cache = {};
|
|
7
5
|
|
|
8
|
-
const cpuInfo =
|
|
6
|
+
const cpuInfo = os => {
|
|
9
7
|
const cpus = os.cpus();
|
|
10
8
|
let user = 0;
|
|
11
9
|
let nice = 0;
|
|
@@ -30,8 +28,8 @@ const cpuInfo = () => {
|
|
|
30
28
|
};
|
|
31
29
|
};
|
|
32
30
|
|
|
33
|
-
const cpuFree =
|
|
34
|
-
const currCPUs = cpuInfo();
|
|
31
|
+
const cpuFree = os => {
|
|
32
|
+
const currCPUs = cpuInfo(os);
|
|
35
33
|
const idle = (currCPUs.idle - cache.preCPUs.idle) / interval;
|
|
36
34
|
const total = (currCPUs.total - cache.preCPUs.total) / interval;
|
|
37
35
|
const free = Math.round((idle / total) * 100);
|
|
@@ -41,18 +39,37 @@ const cpuFree = () => {
|
|
|
41
39
|
|
|
42
40
|
const getSystemInfo = () => cache.systemInfo;
|
|
43
41
|
|
|
44
|
-
const systemInfo = () =>
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
42
|
+
const systemInfo = () => {
|
|
43
|
+
try {
|
|
44
|
+
const os = require('os');
|
|
45
|
+
return {
|
|
46
|
+
hostname: os.hostname(),
|
|
47
|
+
uptime: os.uptime(),
|
|
48
|
+
os_arch: os.arch(),
|
|
49
|
+
os_platform: os.platform(),
|
|
50
|
+
os_release: os.release(),
|
|
51
|
+
memory_total: totalMemory(os),
|
|
52
|
+
memory_free: freeMemory(os),
|
|
53
|
+
cpu_count: os.cpus().length,
|
|
54
|
+
cpu_free: cpuFree(os),
|
|
55
|
+
node: process.versions && process.versions.node,
|
|
56
|
+
};
|
|
57
|
+
} catch (error) {
|
|
58
|
+
// Return a fallback object if 'os' module is not available (Expo environment)
|
|
59
|
+
return {
|
|
60
|
+
hostname: 'unknown',
|
|
61
|
+
uptime: 0,
|
|
62
|
+
os_arch: 'unknown',
|
|
63
|
+
os_platform: 'unknown',
|
|
64
|
+
os_release: 'unknown',
|
|
65
|
+
memory_total: 0,
|
|
66
|
+
memory_free: 0,
|
|
67
|
+
cpu_count: 0,
|
|
68
|
+
cpu_free: 0,
|
|
69
|
+
node: process.versions && process.versions.node,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
};
|
|
56
73
|
|
|
57
74
|
const invokeSystemInfo = fn => {
|
|
58
75
|
if (fn) {
|
|
@@ -64,7 +81,15 @@ const invokeSystemInfo = fn => {
|
|
|
64
81
|
}, interval * 1000);
|
|
65
82
|
};
|
|
66
83
|
|
|
67
|
-
cache
|
|
68
|
-
|
|
84
|
+
// Initialize cache safely with try/catch to handle environments without 'os'
|
|
85
|
+
try {
|
|
86
|
+
const os = require('os');
|
|
87
|
+
cache.preCPUs = cpuInfo(os);
|
|
88
|
+
cache.systemInfo = systemInfo();
|
|
89
|
+
} catch (error) {
|
|
90
|
+
// Set default values if 'os' is not available
|
|
91
|
+
cache.preCPUs = { idle: 0, total: 0 };
|
|
92
|
+
cache.systemInfo = systemInfo();
|
|
93
|
+
}
|
|
69
94
|
|
|
70
95
|
module.exports = { getSystemInfo, invokeSystemInfo };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@darkpos/utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"description": "General purpose utilities",
|
|
5
5
|
"author": "Dark POS",
|
|
6
6
|
"homepage": "https://gitlab.com/darkpos/packages/dark#readme",
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"eslint-plugin-prettier": "^4.0.0",
|
|
40
40
|
"prettier": "^2.7.0"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "4e966b805abc74cc31cb0b3a0754e71f9bb913e5"
|
|
43
43
|
}
|