@vroskus/library-health 1.0.20 → 1.0.22
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/dist/index.d.ts +21 -0
- package/dist/index.js +48 -12
- package/package.json +10 -9
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,25 @@
|
|
|
1
1
|
import type { Request as $Request, Response as $Response } from 'express';
|
|
2
|
+
export type $SystemValues = {
|
|
3
|
+
disk: null | {
|
|
4
|
+
freeGb: number;
|
|
5
|
+
freePercentage: number;
|
|
6
|
+
totalGb: number;
|
|
7
|
+
usedGb: number;
|
|
8
|
+
usedPercentage: number;
|
|
9
|
+
};
|
|
10
|
+
load: Array<number> | string;
|
|
11
|
+
memory: null | {
|
|
12
|
+
freeMb: number;
|
|
13
|
+
freePercentage: number;
|
|
14
|
+
totalMb: number;
|
|
15
|
+
usedMb: number;
|
|
16
|
+
usedPercentage: number;
|
|
17
|
+
};
|
|
18
|
+
uptime: {
|
|
19
|
+
container: number;
|
|
20
|
+
os: number;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
2
23
|
type $HealthRoute = (req: $Request, res: $Response) => Promise<void>;
|
|
3
24
|
export declare const healthRoute: $HealthRoute;
|
|
4
25
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -14,20 +14,56 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.healthRoute = void 0;
|
|
16
16
|
const os_1 = __importDefault(require("os"));
|
|
17
|
-
const node_os_utils_1 =
|
|
17
|
+
const node_os_utils_1 = require("node-os-utils");
|
|
18
|
+
const fullPercentage = 100;
|
|
19
|
+
const getDiskInfo = (osutils) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
const result = yield osutils.disk.info();
|
|
21
|
+
if (result.success === true && result.data.length) {
|
|
22
|
+
const data = result.data[0];
|
|
23
|
+
const totalGb = data.total.toGB();
|
|
24
|
+
const freeGb = data.available.toGB();
|
|
25
|
+
const usedGb = data.used.toGB();
|
|
26
|
+
const usedPercentage = data.usagePercentage;
|
|
27
|
+
const freePercentage = fullPercentage - usedPercentage;
|
|
28
|
+
return {
|
|
29
|
+
freeGb,
|
|
30
|
+
freePercentage,
|
|
31
|
+
totalGb,
|
|
32
|
+
usedGb,
|
|
33
|
+
usedPercentage,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
});
|
|
38
|
+
const getMemoryInfo = (osutils) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
+
const result = yield osutils.memory.info();
|
|
40
|
+
if (result.success === true && result.data) {
|
|
41
|
+
const { data, } = result;
|
|
42
|
+
const totalMb = data.total.toMB();
|
|
43
|
+
const freeMb = data.available.toMB();
|
|
44
|
+
const usedMb = data.used.toMB();
|
|
45
|
+
const usedPercentage = data.usagePercentage;
|
|
46
|
+
const freePercentage = fullPercentage - usedPercentage;
|
|
47
|
+
return {
|
|
48
|
+
freeMb,
|
|
49
|
+
freePercentage,
|
|
50
|
+
totalMb,
|
|
51
|
+
usedMb,
|
|
52
|
+
usedPercentage,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
});
|
|
18
57
|
const getSystemValues = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
-
const
|
|
20
|
-
const disk = yield node_os_utils_1.default.drive.info();
|
|
21
|
-
const mem = yield node_os_utils_1.default.mem.info();
|
|
22
|
-
const uptime = {
|
|
23
|
-
container: process.uptime(),
|
|
24
|
-
os: os_1.default.uptime(),
|
|
25
|
-
};
|
|
58
|
+
const osutils = new node_os_utils_1.OSUtils();
|
|
26
59
|
return {
|
|
27
|
-
disk,
|
|
28
|
-
load,
|
|
29
|
-
|
|
30
|
-
uptime
|
|
60
|
+
disk: yield getDiskInfo(osutils),
|
|
61
|
+
load: osutils.cpu.loadavg(),
|
|
62
|
+
memory: yield getMemoryInfo(osutils),
|
|
63
|
+
uptime: {
|
|
64
|
+
container: process.uptime(),
|
|
65
|
+
os: os_1.default.uptime(),
|
|
66
|
+
},
|
|
31
67
|
};
|
|
32
68
|
});
|
|
33
69
|
const healthRoute = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vroskus/library-health",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.22",
|
|
4
4
|
"description": "Health",
|
|
5
5
|
"author": "Vilius Roškus <vilius@regattas.eu>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,19 +15,20 @@
|
|
|
15
15
|
],
|
|
16
16
|
"scripts": {
|
|
17
17
|
"build": "tsc",
|
|
18
|
-
"test": "npm run test:eslint && npm run test:e2e",
|
|
18
|
+
"test": "npm run test:eslint && npm run test:type && npm run test:e2e",
|
|
19
19
|
"test:eslint": "eslint src --fix",
|
|
20
|
+
"test:type": "tsc",
|
|
20
21
|
"test:e2e": "echo 'No tests'"
|
|
21
22
|
},
|
|
22
23
|
"dependencies": {
|
|
23
|
-
"@types/express": "^5.0.
|
|
24
|
-
"express": "^
|
|
25
|
-
"node-os-utils": "^
|
|
24
|
+
"@types/express": "^5.0.6",
|
|
25
|
+
"express": "^5.2.1",
|
|
26
|
+
"node-os-utils": "^2.0.1"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
|
-
"@types/jest": "^
|
|
29
|
-
"@types/node": "^
|
|
30
|
-
"@vroskus/eslint-config": "^1.0.
|
|
31
|
-
"typescript": "^5.
|
|
29
|
+
"@types/jest": "^30.0.0",
|
|
30
|
+
"@types/node": "^25.0.9",
|
|
31
|
+
"@vroskus/eslint-config": "^1.0.30",
|
|
32
|
+
"typescript": "^5.9.3"
|
|
32
33
|
}
|
|
33
34
|
}
|