@leyyo/common 1.3.13 → 1.3.15
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.
|
@@ -50,6 +50,8 @@ export declare class ErrorCommon implements ErrorCommonLike {
|
|
|
50
50
|
/** @inheritDoc */
|
|
51
51
|
addStat(p1: Error | ErrorCtor): number;
|
|
52
52
|
/** @inheritDoc */
|
|
53
|
+
getStat(p1: Error | ErrorCtor): number;
|
|
54
|
+
/** @inheritDoc */
|
|
53
55
|
clearStats(): void;
|
|
54
56
|
/** @inheritDoc */
|
|
55
57
|
listStats(): Record<string, number>;
|
|
@@ -324,6 +324,29 @@ export class ErrorCommon {
|
|
|
324
324
|
return num;
|
|
325
325
|
}
|
|
326
326
|
/** @inheritDoc */
|
|
327
|
+
getStat(p1) {
|
|
328
|
+
try {
|
|
329
|
+
let clazz;
|
|
330
|
+
if (isObj(p1)) {
|
|
331
|
+
clazz = p1.constructor;
|
|
332
|
+
}
|
|
333
|
+
else if (typeof p1 === 'function') {
|
|
334
|
+
clazz = p1;
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
return 0;
|
|
338
|
+
}
|
|
339
|
+
if (!this._stats) {
|
|
340
|
+
return 0;
|
|
341
|
+
}
|
|
342
|
+
return this._stats.get(clazz) ?? 0;
|
|
343
|
+
}
|
|
344
|
+
catch (e) {
|
|
345
|
+
// nothing
|
|
346
|
+
}
|
|
347
|
+
return 0;
|
|
348
|
+
}
|
|
349
|
+
/** @inheritDoc */
|
|
327
350
|
clearStats() {
|
|
328
351
|
if (!this._stats) {
|
|
329
352
|
return;
|
|
@@ -259,6 +259,20 @@ export interface ErrorCommonLike {
|
|
|
259
259
|
* @return {number} - total raised count
|
|
260
260
|
* */
|
|
261
261
|
addStat(clazz: ErrorCtor): number;
|
|
262
|
+
/**
|
|
263
|
+
* Get error statistics with instance
|
|
264
|
+
*
|
|
265
|
+
* @param {Error} error
|
|
266
|
+
* @return {number} - total raised count
|
|
267
|
+
* */
|
|
268
|
+
getStat(error: Error): number;
|
|
269
|
+
/**
|
|
270
|
+
* Get error statistics
|
|
271
|
+
*
|
|
272
|
+
* @param {ErrorCtor} clazz
|
|
273
|
+
* @return {number} - total raised count
|
|
274
|
+
* */
|
|
275
|
+
getStat(clazz: ErrorCtor): number;
|
|
262
276
|
/**
|
|
263
277
|
* Clear statistics
|
|
264
278
|
* */
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export declare function sysStat(): SysStat;
|
|
2
|
+
export interface SysStat {
|
|
3
|
+
cpu: SysStatCpu;
|
|
4
|
+
memory: SysStatMemory;
|
|
5
|
+
time: SysStatTime;
|
|
6
|
+
npm: SysStatNpm;
|
|
7
|
+
node: SysStatNode;
|
|
8
|
+
project: SysStatProject;
|
|
9
|
+
os: SysStatOs;
|
|
10
|
+
}
|
|
11
|
+
export interface SysStatCpu {
|
|
12
|
+
user: number;
|
|
13
|
+
system: number;
|
|
14
|
+
}
|
|
15
|
+
export interface SysStatTime {
|
|
16
|
+
uptime: number;
|
|
17
|
+
startedAt: number;
|
|
18
|
+
}
|
|
19
|
+
export interface SysStatNpm {
|
|
20
|
+
pwd: string;
|
|
21
|
+
version: string;
|
|
22
|
+
}
|
|
23
|
+
export interface SysStatNode {
|
|
24
|
+
type: string;
|
|
25
|
+
version: string;
|
|
26
|
+
}
|
|
27
|
+
export interface SysStatProject {
|
|
28
|
+
name: string;
|
|
29
|
+
version: string;
|
|
30
|
+
environment: string;
|
|
31
|
+
log: string;
|
|
32
|
+
}
|
|
33
|
+
export interface SysStatOs {
|
|
34
|
+
version: string;
|
|
35
|
+
arch: string;
|
|
36
|
+
platform: string;
|
|
37
|
+
machineType: string;
|
|
38
|
+
network: Record<string, unknown>;
|
|
39
|
+
cpu: Array<SysStatCpuInfo>;
|
|
40
|
+
}
|
|
41
|
+
export interface SysStatMemory {
|
|
42
|
+
/**
|
|
43
|
+
* Resident Set Size, is the amount of space occupied in the main memory device (that is a subset of the total allocated memory) for the
|
|
44
|
+
* process, including all C++ and JavaScript objects and code.
|
|
45
|
+
*/
|
|
46
|
+
rss: number;
|
|
47
|
+
/**
|
|
48
|
+
* Refers to V8's memory usage.
|
|
49
|
+
*/
|
|
50
|
+
heapTotal: number;
|
|
51
|
+
/**
|
|
52
|
+
* Refers to V8's memory usage.
|
|
53
|
+
*/
|
|
54
|
+
heapUsed: number;
|
|
55
|
+
external: number;
|
|
56
|
+
/**
|
|
57
|
+
* Refers to memory allocated for `ArrayBuffer`s and `SharedArrayBuffer`s, including all Node.js Buffers. This is also included
|
|
58
|
+
* in the external value. When Node.js is used as an embedded library, this value may be `0` because allocations for `ArrayBuffer`s
|
|
59
|
+
* may not be tracked in that case.
|
|
60
|
+
*/
|
|
61
|
+
arrayBuffers: number;
|
|
62
|
+
}
|
|
63
|
+
export interface SysStatCpuInfo {
|
|
64
|
+
model: string;
|
|
65
|
+
speed: number;
|
|
66
|
+
times: {
|
|
67
|
+
/** The number of milliseconds the CPU has spent in user mode. */
|
|
68
|
+
user: number;
|
|
69
|
+
/** The number of milliseconds the CPU has spent in nice mode. */
|
|
70
|
+
nice: number;
|
|
71
|
+
/** The number of milliseconds the CPU has spent in sys mode. */
|
|
72
|
+
sys: number;
|
|
73
|
+
/** The number of milliseconds the CPU has spent in idle mode. */
|
|
74
|
+
idle: number;
|
|
75
|
+
/** The number of milliseconds the CPU has spent in irq mode. */
|
|
76
|
+
irq: number;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import os from "node:os";
|
|
2
|
+
export function sysStat() {
|
|
3
|
+
const uptime = Math.round(process.uptime() * 1_000);
|
|
4
|
+
return {
|
|
5
|
+
cpu: process.cpuUsage(),
|
|
6
|
+
memory: process.memoryUsage(),
|
|
7
|
+
time: { uptime, startedAt: Date.now() - uptime },
|
|
8
|
+
npm: { pwd: process.env.PWD, version: process.env.npm_config_npm_version },
|
|
9
|
+
node: { type: 'module', version: process.env.npm_config_node_version },
|
|
10
|
+
project: { name: process.env.npm_package_name, version: process.env.npm_package_version, environment: process.env.NODE_ENV, log: process.env.LOG_LEVEL },
|
|
11
|
+
os: {
|
|
12
|
+
version: os.version(),
|
|
13
|
+
arch: os.arch(),
|
|
14
|
+
platform: os.platform(),
|
|
15
|
+
machineType: os.machine(),
|
|
16
|
+
network: os.networkInterfaces(),
|
|
17
|
+
cpu: os.cpus(),
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|