1 | ;
|
2 | /**
|
3 | * This file is part of the @egodigital/egoose distribution.
|
4 | * Copyright (c) e.GO Digital GmbH, Aachen, Germany (https://www.e-go-digital.com/)
|
5 | *
|
6 | * @egodigital/egoose is free software: you can redistribute it and/or modify
|
7 | * it under the terms of the GNU Lesser General Public License as
|
8 | * published by the Free Software Foundation, version 3.
|
9 | *
|
10 | * @egodigital/egoose is distributed in the hope that it will be useful, but
|
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13 | * Lesser General Public License for more details.
|
14 | *
|
15 | * You should have received a copy of the GNU Lesser General Public License
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17 | */
|
18 | Object.defineProperty(exports, "__esModule", { value: true });
|
19 | const diskspace = require('diskspace');
|
20 | const os = require('os-utils');
|
21 | const index_1 = require("../index");
|
22 | /**
|
23 | * Returns the CPU usage in percentage.
|
24 | *
|
25 | * @return {Promise<number>} The promise with the CPU usage.
|
26 | */
|
27 | function getCpuUsage() {
|
28 | return new Promise((resolve, reject) => {
|
29 | try {
|
30 | os.cpuUsage(function (v) {
|
31 | resolve(v);
|
32 | });
|
33 | }
|
34 | catch (e) {
|
35 | reject(e);
|
36 | }
|
37 | });
|
38 | }
|
39 | exports.getCpuUsage = getCpuUsage;
|
40 | /**
|
41 | * Returns the diskspace of a mount point.
|
42 | *
|
43 | * @param {string} [mountPoint] The custom name / path of the endpoint to check.
|
44 | *
|
45 | * @return {Promise<DiskSpaceResult>} The promise with the result.
|
46 | */
|
47 | function getDiskSpace(mountPoint) {
|
48 | mountPoint = index_1.toStringSafe(mountPoint);
|
49 | return new Promise((resolve, reject) => {
|
50 | try {
|
51 | if (index_1.isEmptyString(mountPoint)) {
|
52 | if ('win32' === process.platform) {
|
53 | mountPoint = 'C'; // drive C
|
54 | }
|
55 | else {
|
56 | mountPoint = '/'; // system root
|
57 | }
|
58 | }
|
59 | diskspace.check(mountPoint, function (err, result) {
|
60 | if (err) {
|
61 | reject(err);
|
62 | }
|
63 | else {
|
64 | resolve({
|
65 | free: parseInt(index_1.toStringSafe(result.free).trim()),
|
66 | total: parseInt(index_1.toStringSafe(result.total).trim()),
|
67 | used: parseInt(index_1.toStringSafe(result.used).trim()),
|
68 | });
|
69 | }
|
70 | });
|
71 | }
|
72 | catch (e) {
|
73 | reject(e);
|
74 | }
|
75 | });
|
76 | }
|
77 | exports.getDiskSpace = getDiskSpace;
|
78 | //# sourceMappingURL=index.js.map |
\ | No newline at end of file |