@omnitron-dev/titan-health 0.1.1
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/LICENSE +21 -0
- package/README.md +19 -0
- package/dist/health.indicator.d.ts +29 -0
- package/dist/health.indicator.d.ts.map +1 -0
- package/dist/health.indicator.js +136 -0
- package/dist/health.indicator.js.map +1 -0
- package/dist/health.module.d.ts +9 -0
- package/dist/health.module.d.ts.map +1 -0
- package/dist/health.module.js +302 -0
- package/dist/health.module.js.map +1 -0
- package/dist/health.rpc-service.d.ts +56 -0
- package/dist/health.rpc-service.d.ts.map +1 -0
- package/dist/health.rpc-service.js +138 -0
- package/dist/health.rpc-service.js.map +1 -0
- package/dist/health.service.d.ts +28 -0
- package/dist/health.service.d.ts.map +1 -0
- package/dist/health.service.js +182 -0
- package/dist/health.service.js.map +1 -0
- package/dist/health.tokens.d.ts +12 -0
- package/dist/health.tokens.d.ts.map +1 -0
- package/dist/health.tokens.js +10 -0
- package/dist/health.tokens.js.map +1 -0
- package/dist/health.types.d.ts +103 -0
- package/dist/health.types.d.ts.map +1 -0
- package/dist/health.types.js +2 -0
- package/dist/health.types.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/indicators/database.indicator.d.ts +25 -0
- package/dist/indicators/database.indicator.d.ts.map +1 -0
- package/dist/indicators/database.indicator.js +66 -0
- package/dist/indicators/database.indicator.js.map +1 -0
- package/dist/indicators/disk.indicator.d.ts +16 -0
- package/dist/indicators/disk.indicator.d.ts.map +1 -0
- package/dist/indicators/disk.indicator.js +159 -0
- package/dist/indicators/disk.indicator.js.map +1 -0
- package/dist/indicators/event-loop.indicator.d.ts +27 -0
- package/dist/indicators/event-loop.indicator.d.ts.map +1 -0
- package/dist/indicators/event-loop.indicator.js +150 -0
- package/dist/indicators/event-loop.indicator.js.map +1 -0
- package/dist/indicators/index.d.ts +6 -0
- package/dist/indicators/index.d.ts.map +1 -0
- package/dist/indicators/index.js +6 -0
- package/dist/indicators/index.js.map +1 -0
- package/dist/indicators/memory.indicator.d.ts +13 -0
- package/dist/indicators/memory.indicator.d.ts.map +1 -0
- package/dist/indicators/memory.indicator.js +103 -0
- package/dist/indicators/memory.indicator.js.map +1 -0
- package/dist/indicators/redis.indicator.d.ts +26 -0
- package/dist/indicators/redis.indicator.d.ts.map +1 -0
- package/dist/indicators/redis.indicator.js +101 -0
- package/dist/indicators/redis.indicator.js.map +1 -0
- package/package.json +44 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { HealthIndicator } from '../health.indicator.js';
|
|
2
|
+
const DEFAULT_OPTIONS = {
|
|
3
|
+
latencyDegradedThreshold: 10,
|
|
4
|
+
latencyUnhealthyThreshold: 100,
|
|
5
|
+
timeout: 5000,
|
|
6
|
+
includeMemoryInfo: false,
|
|
7
|
+
memoryDegradedThreshold: 0.8,
|
|
8
|
+
memoryUnhealthyThreshold: 0.95,
|
|
9
|
+
};
|
|
10
|
+
export class RedisHealthIndicator extends HealthIndicator {
|
|
11
|
+
constructor(client, options = {}) {
|
|
12
|
+
super();
|
|
13
|
+
this.name = 'redis';
|
|
14
|
+
this.client = client;
|
|
15
|
+
this.options = {
|
|
16
|
+
...DEFAULT_OPTIONS,
|
|
17
|
+
...options,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
setClient(client) {
|
|
21
|
+
this.client = client;
|
|
22
|
+
}
|
|
23
|
+
async check() {
|
|
24
|
+
if (!this.client) {
|
|
25
|
+
return this.unhealthy('Redis client not configured');
|
|
26
|
+
}
|
|
27
|
+
if (this.client.status && this.client.status !== 'ready') {
|
|
28
|
+
return this.unhealthy(`Redis not ready: ${this.client.status}`, { status: this.client.status });
|
|
29
|
+
}
|
|
30
|
+
if (this.client.isReady === false) {
|
|
31
|
+
return this.unhealthy('Redis not ready');
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
const start = Date.now();
|
|
35
|
+
await this.withTimeout(() => this.client.ping(), this.options.timeout);
|
|
36
|
+
const pingLatency = Date.now() - start;
|
|
37
|
+
const details = {
|
|
38
|
+
latency: pingLatency,
|
|
39
|
+
threshold: {
|
|
40
|
+
degraded: this.options.latencyDegradedThreshold,
|
|
41
|
+
unhealthy: this.options.latencyUnhealthyThreshold,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
let memoryStatus = 'healthy';
|
|
45
|
+
if (this.options.includeMemoryInfo && this.client.info) {
|
|
46
|
+
try {
|
|
47
|
+
const memoryInfo = await this.getMemoryInfo();
|
|
48
|
+
details['memory'] = memoryInfo;
|
|
49
|
+
if (memoryInfo.usedRatio >= this.options.memoryUnhealthyThreshold) {
|
|
50
|
+
memoryStatus = 'unhealthy';
|
|
51
|
+
}
|
|
52
|
+
else if (memoryInfo.usedRatio >= this.options.memoryDegradedThreshold) {
|
|
53
|
+
memoryStatus = 'degraded';
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
details['memory'] = { error: 'Failed to retrieve memory info' };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (pingLatency >= this.options.latencyUnhealthyThreshold || memoryStatus === 'unhealthy') {
|
|
61
|
+
return this.unhealthy(`Redis issues: latency=${pingLatency}ms, memory=${memoryStatus}`, details);
|
|
62
|
+
}
|
|
63
|
+
if (pingLatency >= this.options.latencyDegradedThreshold || memoryStatus === 'degraded') {
|
|
64
|
+
return this.degraded(`Redis degraded: latency=${pingLatency}ms`, details);
|
|
65
|
+
}
|
|
66
|
+
return this.healthy(`Redis responding in ${pingLatency}ms`, details);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
70
|
+
return this.unhealthy(`Redis check failed: ${errorMessage}`, undefined, error instanceof Error ? error : new Error(errorMessage));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async getMemoryInfo() {
|
|
74
|
+
if (!this.client?.info) {
|
|
75
|
+
throw new Error('INFO command not available');
|
|
76
|
+
}
|
|
77
|
+
const infoResult = await this.client.info('memory');
|
|
78
|
+
if (!infoResult) {
|
|
79
|
+
throw new Error('INFO command returned empty result');
|
|
80
|
+
}
|
|
81
|
+
const lines = infoResult.split('\r\n');
|
|
82
|
+
const parseValue = (key) => {
|
|
83
|
+
const line = lines.find((l) => l.startsWith(`${key}:`));
|
|
84
|
+
if (!line)
|
|
85
|
+
return 0;
|
|
86
|
+
const parts = line.split(':');
|
|
87
|
+
const value = parts[1];
|
|
88
|
+
return value ? parseInt(value, 10) || 0 : 0;
|
|
89
|
+
};
|
|
90
|
+
const used = parseValue('used_memory');
|
|
91
|
+
const peak = parseValue('used_memory_peak');
|
|
92
|
+
const maxmemory = parseValue('maxmemory');
|
|
93
|
+
return {
|
|
94
|
+
used,
|
|
95
|
+
peak,
|
|
96
|
+
maxmemory,
|
|
97
|
+
usedRatio: maxmemory > 0 ? used / maxmemory : 0,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=redis.indicator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redis.indicator.js","sourceRoot":"","sources":["../../src/indicators/redis.indicator.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAyEzD,MAAM,eAAe,GAAiC;IACpD,wBAAwB,EAAE,EAAE;IAC5B,yBAAyB,EAAE,GAAG;IAC9B,OAAO,EAAE,IAAI;IACb,iBAAiB,EAAE,KAAK;IACxB,uBAAuB,EAAE,GAAG;IAC5B,wBAAwB,EAAE,IAAI;CAC/B,CAAC;AAsBF,MAAM,OAAO,oBAAqB,SAAQ,eAAe;IAMvD,YAAY,MAAqB,EAAE,UAA8B,EAAE;QACjE,KAAK,EAAE,CAAC;QAND,SAAI,GAAG,OAAO,CAAC;QAOtB,IAAI,CAAC,MAAM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AS,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;QAE1C,OAAO;YACL,IAAI;YACJ,IAAI;YACJ,SAAS;YACT,SAAS,EAAE,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;SAChD,CAAC;IACJ,CAAC;CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@omnitron-dev/titan-health",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Health check module for Titan framework with extensible indicators",
|
|
5
|
+
"author": "LuxQuant",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"ioredis": "^5.8.2",
|
|
21
|
+
"kysely": "0.28.12",
|
|
22
|
+
"@omnitron-dev/titan": "0.1.1"
|
|
23
|
+
},
|
|
24
|
+
"peerDependenciesMeta": {
|
|
25
|
+
"ioredis": {
|
|
26
|
+
"optional": true
|
|
27
|
+
},
|
|
28
|
+
"kysely": {
|
|
29
|
+
"optional": true
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/node": "25.0.3",
|
|
34
|
+
"reflect-metadata": "^0.2.2",
|
|
35
|
+
"typescript": "^5.9.3",
|
|
36
|
+
"vitest": "^4.1.0"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "rm -rf dist node_modules/.tmp && tsc -p ./tsconfig.json",
|
|
40
|
+
"test": "vitest run",
|
|
41
|
+
"clean": "rm -rf dist",
|
|
42
|
+
"typecheck": "tsc --noEmit"
|
|
43
|
+
}
|
|
44
|
+
}
|