nestjs-profiler 1.0.10 → 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/package.json +51 -130
- package/dist/libs/nestjs-profiler/analyzers/explain-analyzer.d.ts +0 -5
- package/dist/libs/nestjs-profiler/analyzers/explain-analyzer.js +0 -39
- package/dist/libs/nestjs-profiler/analyzers/explain-analyzer.js.map +0 -1
- package/dist/libs/nestjs-profiler/collectors/cache-collector.d.ts +0 -18
- package/dist/libs/nestjs-profiler/collectors/cache-collector.js +0 -178
- package/dist/libs/nestjs-profiler/collectors/cache-collector.js.map +0 -1
- package/dist/libs/nestjs-profiler/collectors/log-collector.d.ts +0 -12
- package/dist/libs/nestjs-profiler/collectors/log-collector.js +0 -68
- package/dist/libs/nestjs-profiler/collectors/log-collector.js.map +0 -1
- package/dist/libs/nestjs-profiler/collectors/mongo-collector.d.ts +0 -19
- package/dist/libs/nestjs-profiler/collectors/mongo-collector.js +0 -203
- package/dist/libs/nestjs-profiler/collectors/mongo-collector.js.map +0 -1
- package/dist/libs/nestjs-profiler/collectors/mysql-collector.d.ts +0 -12
- package/dist/libs/nestjs-profiler/collectors/mysql-collector.js +0 -131
- package/dist/libs/nestjs-profiler/collectors/mysql-collector.js.map +0 -1
- package/dist/libs/nestjs-profiler/collectors/postgres-collector.d.ts +0 -15
- package/dist/libs/nestjs-profiler/collectors/postgres-collector.js +0 -205
- package/dist/libs/nestjs-profiler/collectors/postgres-collector.js.map +0 -1
- package/dist/libs/nestjs-profiler/common/profiler-options.interface.d.ts +0 -20
- package/dist/libs/nestjs-profiler/common/profiler-options.interface.js +0 -3
- package/dist/libs/nestjs-profiler/common/profiler-options.interface.js.map +0 -1
- package/dist/libs/nestjs-profiler/common/profiler.model.d.ts +0 -67
- package/dist/libs/nestjs-profiler/common/profiler.model.js +0 -3
- package/dist/libs/nestjs-profiler/common/profiler.model.js.map +0 -1
- package/dist/libs/nestjs-profiler/controllers/profiler.controller.d.ts +0 -34
- package/dist/libs/nestjs-profiler/controllers/profiler.controller.js +0 -259
- package/dist/libs/nestjs-profiler/controllers/profiler.controller.js.map +0 -1
- package/dist/libs/nestjs-profiler/interceptors/request-profiler.interceptor.d.ts +0 -11
- package/dist/libs/nestjs-profiler/interceptors/request-profiler.interceptor.js +0 -104
- package/dist/libs/nestjs-profiler/interceptors/request-profiler.interceptor.js.map +0 -1
- package/dist/libs/nestjs-profiler/middleware/profiler.middleware.d.ts +0 -4
- package/dist/libs/nestjs-profiler/middleware/profiler.middleware.js +0 -21
- package/dist/libs/nestjs-profiler/middleware/profiler.middleware.js.map +0 -1
- package/dist/libs/nestjs-profiler/package.json +0 -38
- package/dist/libs/nestjs-profiler/profiler-logger.d.ts +0 -12
- package/dist/libs/nestjs-profiler/profiler-logger.js +0 -60
- package/dist/libs/nestjs-profiler/profiler-logger.js.map +0 -1
- package/dist/libs/nestjs-profiler/profiler.module.d.ts +0 -7
- package/dist/libs/nestjs-profiler/profiler.module.js +0 -105
- package/dist/libs/nestjs-profiler/profiler.module.js.map +0 -1
- package/dist/libs/nestjs-profiler/services/entity-explorer.service.d.ts +0 -19
- package/dist/libs/nestjs-profiler/services/entity-explorer.service.js +0 -110
- package/dist/libs/nestjs-profiler/services/entity-explorer.service.js.map +0 -1
- package/dist/libs/nestjs-profiler/services/profiler.service.d.ts +0 -31
- package/dist/libs/nestjs-profiler/services/profiler.service.js +0 -218
- package/dist/libs/nestjs-profiler/services/profiler.service.js.map +0 -1
- package/dist/libs/nestjs-profiler/services/route-explorer.service.d.ts +0 -15
- package/dist/libs/nestjs-profiler/services/route-explorer.service.js +0 -93
- package/dist/libs/nestjs-profiler/services/route-explorer.service.js.map +0 -1
- package/dist/libs/nestjs-profiler/services/template-builder.service.d.ts +0 -27
- package/dist/libs/nestjs-profiler/services/template-builder.service.js +0 -349
- package/dist/libs/nestjs-profiler/services/template-builder.service.js.map +0 -1
- package/dist/libs/nestjs-profiler/services/view.service.d.ts +0 -17
- package/dist/libs/nestjs-profiler/services/view.service.js +0 -197
- package/dist/libs/nestjs-profiler/services/view.service.js.map +0 -1
- package/dist/libs/nestjs-profiler/storage/in-memory-profiler-storage.d.ts +0 -9
- package/dist/libs/nestjs-profiler/storage/in-memory-profiler-storage.js +0 -27
- package/dist/libs/nestjs-profiler/storage/in-memory-profiler-storage.js.map +0 -1
- package/dist/libs/nestjs-profiler/storage/profiler-storage.interface.d.ts +0 -6
- package/dist/libs/nestjs-profiler/storage/profiler-storage.interface.js +0 -3
- package/dist/libs/nestjs-profiler/storage/profiler-storage.interface.js.map +0 -1
- /package/{dist/libs/nestjs-profiler/index.d.ts → index.d.ts} +0 -0
- /package/{dist/libs/nestjs-profiler/index.js → index.js} +0 -0
- /package/{dist/libs/nestjs-profiler/index.js.map → index.js.map} +0 -0
- /package/{dist/libs/nestjs-profiler/src → src}/assets/favicon.ico +0 -0
- /package/{dist/libs/nestjs-profiler/src → src}/assets/logo.png +0 -0
- /package/{dist/libs/nestjs-profiler/src → src}/views/cache.html +0 -0
- /package/{dist/libs/nestjs-profiler/src → src}/views/dashboard.html +0 -0
- /package/{dist/libs/nestjs-profiler/src → src}/views/detail.html +0 -0
- /package/{dist/libs/nestjs-profiler/src → src}/views/entities.html +0 -0
- /package/{dist/libs/nestjs-profiler/src → src}/views/js/dashboard.js +0 -0
- /package/{dist/libs/nestjs-profiler/src → src}/views/js/entities.js +0 -0
- /package/{dist/libs/nestjs-profiler/src → src}/views/js/layout-config.js +0 -0
- /package/{dist/libs/nestjs-profiler/src → src}/views/js/layout.js +0 -0
- /package/{dist/libs/nestjs-profiler/src → src}/views/js/queries.js +0 -0
- /package/{dist/libs/nestjs-profiler/src → src}/views/layout.html +0 -0
- /package/{dist/libs/nestjs-profiler/src → src}/views/logs.html +0 -0
- /package/{dist/libs/nestjs-profiler/src → src}/views/not_found.html +0 -0
- /package/{dist/libs/nestjs-profiler/src → src}/views/partials/cache_row.html +0 -0
- /package/{dist/libs/nestjs-profiler/src → src}/views/partials/detail_query_row.html +0 -0
- /package/{dist/libs/nestjs-profiler/src → src}/views/partials/entity_row.html +0 -0
- /package/{dist/libs/nestjs-profiler/src → src}/views/partials/log_row.html +0 -0
- /package/{dist/libs/nestjs-profiler/src → src}/views/partials/metadata_sidebar.html +0 -0
- /package/{dist/libs/nestjs-profiler/src → src}/views/partials/pagination.html +0 -0
- /package/{dist/libs/nestjs-profiler/src → src}/views/partials/query_row.html +0 -0
- /package/{dist/libs/nestjs-profiler/src → src}/views/partials/request_row.html +0 -0
- /package/{dist/libs/nestjs-profiler/src → src}/views/partials/route_row.html +0 -0
- /package/{dist/libs/nestjs-profiler/src → src}/views/queries.html +0 -0
- /package/{dist/libs/nestjs-profiler/src → src}/views/routes.html +0 -0
package/package.json
CHANGED
|
@@ -1,137 +1,58 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
"files": [
|
|
18
|
-
"dist/libs/nestjs-profiler",
|
|
19
|
-
"README.md",
|
|
20
|
-
"LICENSE"
|
|
21
|
-
],
|
|
22
|
-
"sideEffects": false,
|
|
23
|
-
"scripts": {
|
|
24
|
-
"build": "nest build && copyfiles -u 1 libs/nestjs-profiler/src/assets/**/* dist/assets",
|
|
25
|
-
"build:lib": "rm -rf dist/libs/nestjs-profiler && mkdir -p dist/libs/nestjs-profiler && rm -f dist/tsconfig.lib.tsbuildinfo && npx -y tsc -p libs/nestjs-profiler/tsconfig.lib.json && cp -r dist/nestjs-profiler/* dist/libs/nestjs-profiler/ && cp libs/nestjs-profiler/package.json dist/libs/nestjs-profiler/ && mkdir -p dist/libs/nestjs-profiler/src && cp -r libs/nestjs-profiler/src/assets dist/libs/nestjs-profiler/src/ && cp -r libs/nestjs-profiler/src/views dist/libs/nestjs-profiler/src/ && node -e \"const pkg=require('./dist/libs/nestjs-profiler/package.json'); pkg.main='./index.js'; pkg.types='./index.d.ts'; require('fs').writeFileSync('./dist/libs/nestjs-profiler/package.json', JSON.stringify(pkg, null, 2))\" && rm -rf dist/nestjs-profiler",
|
|
26
|
-
"prepublishOnly": "npm run build:lib",
|
|
27
|
-
"format": "prettier --write \"{src,apps,libs,test}/**/*.ts\"",
|
|
28
|
-
"start": "nest start",
|
|
29
|
-
"start:dev": "nest start --watch",
|
|
30
|
-
"start:debug": "nest start --debug --watch",
|
|
31
|
-
"start:prod": "node dist/main",
|
|
32
|
-
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
|
33
|
-
"test": "jest",
|
|
34
|
-
"test:watch": "jest --watch",
|
|
35
|
-
"test:cov": "jest --coverage",
|
|
36
|
-
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
|
37
|
-
"test:e2e": "jest --config ./test/jest-e2e.json"
|
|
38
|
-
},
|
|
39
|
-
"keywords": [
|
|
40
|
-
"nestjs",
|
|
41
|
-
"nestjs-profiler",
|
|
42
|
-
"performance",
|
|
43
|
-
"monitoring",
|
|
44
|
-
"debugging",
|
|
45
|
-
"backend",
|
|
46
|
-
"nodejs",
|
|
47
|
-
"telescope",
|
|
48
|
-
"profiler"
|
|
49
|
-
],
|
|
50
|
-
"dependencies": {
|
|
51
|
-
"reflect-metadata": "^0.2.2"
|
|
52
|
-
},
|
|
53
|
-
"devDependencies": {
|
|
54
|
-
"@eslint/eslintrc": "^3.2.0",
|
|
55
|
-
"@eslint/js": "^9.18.0",
|
|
56
|
-
"@nestjs/cli": "^11.0.0",
|
|
57
|
-
"@nestjs/schematics": "^11.0.0",
|
|
58
|
-
"@nestjs/testing": "^11.0.1",
|
|
59
|
-
"@types/express": "^5.0.0",
|
|
60
|
-
"@types/jest": "^30.0.0",
|
|
61
|
-
"@types/node": "^22.10.7",
|
|
62
|
-
"@types/pg": "^8.16.0",
|
|
63
|
-
"@types/supertest": "^6.0.2",
|
|
64
|
-
"cache-manager": "^7.2.8",
|
|
65
|
-
"copyfiles": "^2.4.1",
|
|
66
|
-
"eslint": "^9.18.0",
|
|
67
|
-
"eslint-config-prettier": "^10.0.1",
|
|
68
|
-
"eslint-plugin-prettier": "^5.2.2",
|
|
69
|
-
"globals": "^16.0.0",
|
|
70
|
-
"jest": "^30.0.0",
|
|
71
|
-
"prettier": "^3.4.2",
|
|
72
|
-
"source-map-support": "^0.5.21",
|
|
73
|
-
"supertest": "^7.0.0",
|
|
74
|
-
"ts-jest": "^29.2.5",
|
|
75
|
-
"ts-loader": "^9.5.2",
|
|
76
|
-
"ts-node": "^10.9.2",
|
|
77
|
-
"tsconfig-paths": "^4.2.0",
|
|
78
|
-
"typescript": "^5.7.3",
|
|
79
|
-
"typescript-eslint": "^8.20.0"
|
|
80
|
-
},
|
|
81
|
-
"jest": {
|
|
82
|
-
"moduleFileExtensions": [
|
|
83
|
-
"js",
|
|
84
|
-
"json",
|
|
85
|
-
"ts"
|
|
86
|
-
],
|
|
87
|
-
"rootDir": ".",
|
|
88
|
-
"testRegex": "(/|^)test/.*\\.spec\\.ts$",
|
|
89
|
-
"transform": {
|
|
90
|
-
"^.+\\.(t|j)s$": "ts-jest"
|
|
2
|
+
"name": "nestjs-profiler",
|
|
3
|
+
"version": "1.0.12",
|
|
4
|
+
"description": "A NestJS module for profiling HTTP requests, database queries, and cache operations. Inspired by Symfony Profiler, it provides a web-based dashboard to inspect request duration, executed queries, log messages, and explain plans for slow queries.",
|
|
5
|
+
"author": "Mohamed Raslan",
|
|
6
|
+
"main": "./index.js",
|
|
7
|
+
"types": "./index.d.ts",
|
|
8
|
+
"dependencies": {},
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./index.d.ts",
|
|
12
|
+
"import": "./index.js",
|
|
13
|
+
"require": "./index.js"
|
|
14
|
+
}
|
|
91
15
|
},
|
|
92
|
-
"
|
|
93
|
-
|
|
94
|
-
"src/**/*.(t|j)s"
|
|
95
|
-
],
|
|
96
|
-
"coverageDirectory": "coverage",
|
|
97
|
-
"testEnvironment": "node"
|
|
98
|
-
},
|
|
99
|
-
"peerDependencies": {
|
|
100
|
-
"@nestjs/cache-manager": ">=2.0.0",
|
|
101
|
-
"@nestjs/common": "^9.0.0 || ^10.0.0 || ^11.0.0",
|
|
102
|
-
"@nestjs/core": "^9.0.0 || ^10.0.0 || ^11.0.0",
|
|
103
|
-
"cache-manager": ">=5.0.0",
|
|
104
|
-
"mongodb": ">=4.0.0",
|
|
105
|
-
"mysql2": ">=2.0.0",
|
|
106
|
-
"pg": ">=8.0.0",
|
|
107
|
-
"rxjs": ">=7.0.0"
|
|
108
|
-
},
|
|
109
|
-
"peerDependenciesMeta": {
|
|
110
|
-
"pg": {
|
|
111
|
-
"optional": true
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
112
18
|
},
|
|
113
|
-
"
|
|
114
|
-
|
|
19
|
+
"files": [
|
|
20
|
+
"index.js",
|
|
21
|
+
"index.d.ts",
|
|
22
|
+
"index.js.map",
|
|
23
|
+
"src/assets",
|
|
24
|
+
"src/views",
|
|
25
|
+
"README.md"
|
|
26
|
+
],
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"@nestjs/common": "^9.0.0 || ^10.0.0 || ^11.0.0",
|
|
29
|
+
"@nestjs/core": "^9.0.0 || ^10.0.0 || ^11.0.0",
|
|
30
|
+
"rxjs": ">=7.0.0",
|
|
31
|
+
"pg": ">=8.0.0",
|
|
32
|
+
"mongodb": ">=4.0.0",
|
|
33
|
+
"mysql2": ">=2.0.0",
|
|
34
|
+
"@nestjs/cache-manager": ">=2.0.0",
|
|
35
|
+
"cache-manager": ">=5.0.0"
|
|
115
36
|
},
|
|
116
|
-
"
|
|
117
|
-
|
|
37
|
+
"peerDependenciesMeta": {
|
|
38
|
+
"mongodb": {
|
|
39
|
+
"optional": true
|
|
40
|
+
},
|
|
41
|
+
"mysql2": {
|
|
42
|
+
"optional": true
|
|
43
|
+
},
|
|
44
|
+
"@nestjs/cache-manager": {
|
|
45
|
+
"optional": true
|
|
46
|
+
},
|
|
47
|
+
"cache-manager": {
|
|
48
|
+
"optional": true
|
|
49
|
+
}
|
|
118
50
|
},
|
|
119
|
-
"
|
|
120
|
-
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"cache-manager": "^5.0.0"
|
|
121
53
|
},
|
|
122
|
-
"
|
|
123
|
-
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@nestjs/cache-manager": "^2.0.0",
|
|
56
|
+
"cache-manager": "^5.0.0"
|
|
124
57
|
}
|
|
125
|
-
|
|
126
|
-
"repository": {
|
|
127
|
-
"type": "git",
|
|
128
|
-
"url": "git+https://github.com/MohammedRaslan/Nest-JS-Profiler.git"
|
|
129
|
-
},
|
|
130
|
-
"bugs": {
|
|
131
|
-
"url": "https://github.com/MohammedRaslan/Nest-JS-Profiler/issues"
|
|
132
|
-
},
|
|
133
|
-
"homepage": "https://github.com/MohammedRaslan/Nest-JS-Profiler#readme",
|
|
134
|
-
"publishConfig": {
|
|
135
|
-
"access": "public"
|
|
136
|
-
}
|
|
137
|
-
}
|
|
58
|
+
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var ExplainAnalyzer_1;
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.ExplainAnalyzer = void 0;
|
|
11
|
-
const common_1 = require("@nestjs/common");
|
|
12
|
-
let ExplainAnalyzer = ExplainAnalyzer_1 = class ExplainAnalyzer {
|
|
13
|
-
logger = new common_1.Logger(ExplainAnalyzer_1.name);
|
|
14
|
-
async analyze(client, query, params, useAnalyze = false) {
|
|
15
|
-
try {
|
|
16
|
-
const cmd = useAnalyze ? 'EXPLAIN (ANALYZE, FORMAT JSON)' : 'EXPLAIN (FORMAT JSON)';
|
|
17
|
-
const explainSql = `${cmd} ${query}`;
|
|
18
|
-
const result = await client.query(explainSql, params);
|
|
19
|
-
if (result.rows && result.rows.length > 0) {
|
|
20
|
-
return result.rows[0]['QUERY PLAN'];
|
|
21
|
-
}
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
catch (e) {
|
|
25
|
-
if (e.message.includes('closed') || e.message.includes('terminated')) {
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
if (process.env.PROFILER_DEBUG) {
|
|
29
|
-
this.logger.warn(`Failed to run EXPLAIN: ${e.message}`);
|
|
30
|
-
}
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
exports.ExplainAnalyzer = ExplainAnalyzer;
|
|
36
|
-
exports.ExplainAnalyzer = ExplainAnalyzer = ExplainAnalyzer_1 = __decorate([
|
|
37
|
-
(0, common_1.Injectable)()
|
|
38
|
-
], ExplainAnalyzer);
|
|
39
|
-
//# sourceMappingURL=explain-analyzer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"explain-analyzer.js","sourceRoot":"","sources":["../../../libs/nestjs-profiler/src/analyzers/explain-analyzer.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAoD;AAI7C,IAAM,eAAe,uBAArB,MAAM,eAAe;IACP,MAAM,GAAG,IAAI,eAAM,CAAC,iBAAe,CAAC,IAAI,CAAC,CAAC;IAE3D,KAAK,CAAC,OAAO,CACT,MAAiC,EACjC,KAAa,EACb,MAAa,EACb,aAAsB,KAAK;QAE3B,IAAI,CAAC;YACD,MAAM,GAAG,GAAG,UAAU,CAAC,CAAC,CAAC,gCAAgC,CAAC,CAAC,CAAC,uBAAuB,CAAC;YACpF,MAAM,UAAU,GAAG,GAAG,GAAG,IAAI,KAAK,EAAE,CAAC;YAErC,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;YACtD,IAAI,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACxC,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;YACxC,CAAC;YACD,OAAO,IAAI,CAAC;QAChB,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YACd,IAAI,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;gBACnE,OAAO,IAAI,CAAC;YAChB,CAAC;YACD,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC;gBAC7B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;YAC5D,CAAC;YACD,OAAO,IAAI,CAAC;QAChB,CAAC;IACL,CAAC;CACJ,CAAA;AA5BY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,GAAE;GACA,eAAe,CA4B3B"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { OnModuleInit } from '@nestjs/common';
|
|
2
|
-
import { ProfilerService } from '../services/profiler.service';
|
|
3
|
-
import type { ProfilerOptions } from '../common/profiler-options.interface';
|
|
4
|
-
import type { Cache } from 'cache-manager';
|
|
5
|
-
export declare class CacheCollector implements OnModuleInit {
|
|
6
|
-
private readonly profiler;
|
|
7
|
-
private readonly options;
|
|
8
|
-
private readonly cacheManager;
|
|
9
|
-
private readonly logger;
|
|
10
|
-
constructor(profiler: ProfilerService, options: ProfilerOptions, cacheManager: Cache);
|
|
11
|
-
onModuleInit(): void;
|
|
12
|
-
private wrapCacheManager;
|
|
13
|
-
private wrapGet;
|
|
14
|
-
private wrapSet;
|
|
15
|
-
private wrapDel;
|
|
16
|
-
private wrapReset;
|
|
17
|
-
private captureOperation;
|
|
18
|
-
}
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
-
};
|
|
14
|
-
var CacheCollector_1;
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.CacheCollector = void 0;
|
|
17
|
-
const common_1 = require("@nestjs/common");
|
|
18
|
-
const profiler_service_1 = require("../services/profiler.service");
|
|
19
|
-
let CacheCollector = CacheCollector_1 = class CacheCollector {
|
|
20
|
-
profiler;
|
|
21
|
-
options;
|
|
22
|
-
cacheManager;
|
|
23
|
-
logger = new common_1.Logger(CacheCollector_1.name);
|
|
24
|
-
constructor(profiler, options, cacheManager) {
|
|
25
|
-
this.profiler = profiler;
|
|
26
|
-
this.options = options;
|
|
27
|
-
this.cacheManager = cacheManager;
|
|
28
|
-
}
|
|
29
|
-
onModuleInit() {
|
|
30
|
-
if (this.options.collectCache === false) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
if (!this.cacheManager) {
|
|
34
|
-
this.logger.warn('No CACHE_MANAGER found, skipping Cache profiling. Ensure CacheModule is imported globally or available to ProfilerModule.');
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
this.logger.log('CacheCollector initialized: Wrapping CACHE_MANAGER');
|
|
38
|
-
this.wrapCacheManager();
|
|
39
|
-
}
|
|
40
|
-
wrapCacheManager() {
|
|
41
|
-
const cm = this.cacheManager;
|
|
42
|
-
this.logger.log(`CacheCollector: Inspecting CacheManager keys: ${Object.keys(cm)}`);
|
|
43
|
-
if (cm.store && cm.store.get) {
|
|
44
|
-
this.logger.log('CacheCollector: Underlying store found: ' + (cm.store.name || cm.store.constructor?.name));
|
|
45
|
-
}
|
|
46
|
-
this.wrapGet(cm);
|
|
47
|
-
this.wrapSet(cm);
|
|
48
|
-
this.wrapDel(cm);
|
|
49
|
-
this.wrapReset(cm);
|
|
50
|
-
}
|
|
51
|
-
wrapGet(cm) {
|
|
52
|
-
const self = this;
|
|
53
|
-
const originalGet = cm.get;
|
|
54
|
-
if (originalGet) {
|
|
55
|
-
this.logger.log('CacheCollector: Wrapping "get" method');
|
|
56
|
-
cm.get = async function (...args) {
|
|
57
|
-
const startTime = Date.now();
|
|
58
|
-
const key = args[0];
|
|
59
|
-
try {
|
|
60
|
-
const result = await originalGet.apply(this, args);
|
|
61
|
-
const endTime = Date.now();
|
|
62
|
-
self.captureOperation('get', key, result !== undefined && result !== null ? 'hit' : 'miss', startTime, endTime);
|
|
63
|
-
return result;
|
|
64
|
-
}
|
|
65
|
-
catch (error) {
|
|
66
|
-
const endTime = Date.now();
|
|
67
|
-
self.captureOperation('get', key, 'fail', startTime, endTime);
|
|
68
|
-
throw error;
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
this.logger.warn('CacheCollector: "get" method not found on CacheManager');
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
wrapSet(cm) {
|
|
77
|
-
const self = this;
|
|
78
|
-
const originalSet = cm.set;
|
|
79
|
-
if (originalSet) {
|
|
80
|
-
this.logger.log('CacheCollector: Wrapping "set" method');
|
|
81
|
-
cm.set = async function (...args) {
|
|
82
|
-
const startTime = Date.now();
|
|
83
|
-
const key = args[0];
|
|
84
|
-
const ttl = args[2];
|
|
85
|
-
try {
|
|
86
|
-
const result = await originalSet.apply(this, args);
|
|
87
|
-
const endTime = Date.now();
|
|
88
|
-
self.captureOperation('set', key, 'success', startTime, endTime, ttl);
|
|
89
|
-
return result;
|
|
90
|
-
}
|
|
91
|
-
catch (error) {
|
|
92
|
-
const endTime = Date.now();
|
|
93
|
-
self.captureOperation('set', key, 'fail', startTime, endTime);
|
|
94
|
-
throw error;
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
this.logger.warn('CacheCollector: "set" method not found on CacheManager');
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
wrapDel(cm) {
|
|
103
|
-
const self = this;
|
|
104
|
-
const originalDel = cm.del;
|
|
105
|
-
if (originalDel) {
|
|
106
|
-
cm.del = async function (...args) {
|
|
107
|
-
const startTime = Date.now();
|
|
108
|
-
const key = args[0];
|
|
109
|
-
try {
|
|
110
|
-
const result = await originalDel.apply(this, args);
|
|
111
|
-
const endTime = Date.now();
|
|
112
|
-
self.captureOperation('del', key, 'success', startTime, endTime);
|
|
113
|
-
return result;
|
|
114
|
-
}
|
|
115
|
-
catch (error) {
|
|
116
|
-
const endTime = Date.now();
|
|
117
|
-
self.captureOperation('del', key, 'fail', startTime, endTime);
|
|
118
|
-
throw error;
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
wrapReset(cm) {
|
|
124
|
-
const self = this;
|
|
125
|
-
const originalReset = cm.reset;
|
|
126
|
-
if (originalReset) {
|
|
127
|
-
cm.reset = async function (...args) {
|
|
128
|
-
const startTime = Date.now();
|
|
129
|
-
try {
|
|
130
|
-
const result = await originalReset.apply(this, args);
|
|
131
|
-
const endTime = Date.now();
|
|
132
|
-
self.captureOperation('reset', '*', 'success', startTime, endTime);
|
|
133
|
-
return result;
|
|
134
|
-
}
|
|
135
|
-
catch (error) {
|
|
136
|
-
const endTime = Date.now();
|
|
137
|
-
self.captureOperation('reset', '*', 'fail', startTime, endTime);
|
|
138
|
-
throw error;
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
captureOperation(operation, key, result, startTime, endTime, ttl) {
|
|
144
|
-
try {
|
|
145
|
-
let storeName = 'unknown';
|
|
146
|
-
const cm = this.cacheManager;
|
|
147
|
-
if (cm.store) {
|
|
148
|
-
if (cm.store.name)
|
|
149
|
-
storeName = cm.store.name;
|
|
150
|
-
else if (cm.store.constructor && cm.store.constructor.name)
|
|
151
|
-
storeName = cm.store.constructor.name;
|
|
152
|
-
}
|
|
153
|
-
const profile = {
|
|
154
|
-
key: String(key),
|
|
155
|
-
store: storeName,
|
|
156
|
-
operation,
|
|
157
|
-
result,
|
|
158
|
-
ttl,
|
|
159
|
-
duration: endTime - startTime,
|
|
160
|
-
startTime,
|
|
161
|
-
};
|
|
162
|
-
this.logger.debug(`CacheCollector: Captured ${operation} on ${key}. Duration: ${profile.duration}ms`);
|
|
163
|
-
this.profiler.addCache(profile);
|
|
164
|
-
}
|
|
165
|
-
catch (e) {
|
|
166
|
-
this.logger.error('Error capturing cache operation', e);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
exports.CacheCollector = CacheCollector;
|
|
171
|
-
exports.CacheCollector = CacheCollector = CacheCollector_1 = __decorate([
|
|
172
|
-
(0, common_1.Injectable)(),
|
|
173
|
-
__param(1, (0, common_1.Inject)('PROFILER_OPTIONS')),
|
|
174
|
-
__param(2, (0, common_1.Optional)()),
|
|
175
|
-
__param(2, (0, common_1.Inject)('CACHE_MANAGER')),
|
|
176
|
-
__metadata("design:paramtypes", [profiler_service_1.ProfilerService, Object, Object])
|
|
177
|
-
], CacheCollector);
|
|
178
|
-
//# sourceMappingURL=cache-collector.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cache-collector.js","sourceRoot":"","sources":["../../../libs/nestjs-profiler/src/collectors/cache-collector.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAoF;AACpF,mEAA+D;AAMxD,IAAM,cAAc,sBAApB,MAAM,cAAc;IAIF;IAC4B;IACS;IALzC,MAAM,GAAG,IAAI,eAAM,CAAC,gBAAc,CAAC,IAAI,CAAC,CAAC;IAE1D,YACqB,QAAyB,EACG,OAAwB,EACf,YAAmB;QAFxD,aAAQ,GAAR,QAAQ,CAAiB;QACG,YAAO,GAAP,OAAO,CAAiB;QACf,iBAAY,GAAZ,YAAY,CAAO;IACzE,CAAC;IAEL,YAAY;QACR,IAAI,IAAI,CAAC,OAAO,CAAC,YAAY,KAAK,KAAK,EAAE,CAAC;YACtC,OAAO;QACX,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;YACrB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,2HAA2H,CAAC,CAAC;YAC9I,OAAO;QACX,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,oDAAoD,CAAC,CAAC;QACtE,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAC5B,CAAC;IAEO,gBAAgB;QACpB,MAAM,EAAE,GAAG,IAAI,CAAC,YAAmB,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G,CAAC;YAED,MAAM,OAAO,GAAiB;gBAC1B,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC;gBAChB,KAAK,EAAE,SAAS;gBAChB,SAAS;gBACT,MAAM;gBACN,GAAG;gBACH,QAAQ,EAAE,OAAO,GAAG,SAAS;gBAC7B,SAAS;aACZ,CAAC;YAEF,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,4BAA4B,SAAS,OAAO,GAAG,eAAe,OAAO,CAAC,QAAQ,IAAI,CAAC,CAAC;YAEtG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QACpC,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACT,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,iCAAiC,EAAE,CAAC,CAAC,CAAC;QAC5D,CAAC;IACL,CAAC;CACJ,CAAA;AA1JY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,mBAAU,GAAE;IAMJ,WAAA,IAAA,eAAM,EAAC,kBAAkB,CAAC,CAAA;IAC1B,WAAA,IAAA,iBAAQ,GAAE,CAAA;IAAE,WAAA,IAAA,eAAM,EAAC,eAAe,CAAC,CAAA;qCAFT,kCAAe;GAJrC,cAAc,CA0J1B"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { OnModuleInit } from '@nestjs/common';
|
|
2
|
-
import { ProfilerService } from '../services/profiler.service';
|
|
3
|
-
import type { ProfilerOptions } from '../common/profiler-options.interface';
|
|
4
|
-
export declare class LogCollector implements OnModuleInit {
|
|
5
|
-
private profiler;
|
|
6
|
-
private options;
|
|
7
|
-
private logger;
|
|
8
|
-
constructor(profiler: ProfilerService, options: ProfilerOptions);
|
|
9
|
-
onModuleInit(): void;
|
|
10
|
-
private patchProcessStream;
|
|
11
|
-
private capture;
|
|
12
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
-
};
|
|
14
|
-
var LogCollector_1;
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.LogCollector = void 0;
|
|
17
|
-
const common_1 = require("@nestjs/common");
|
|
18
|
-
const profiler_service_1 = require("../services/profiler.service");
|
|
19
|
-
let LogCollector = LogCollector_1 = class LogCollector {
|
|
20
|
-
profiler;
|
|
21
|
-
options;
|
|
22
|
-
logger = new common_1.Logger(LogCollector_1.name);
|
|
23
|
-
constructor(profiler, options) {
|
|
24
|
-
this.profiler = profiler;
|
|
25
|
-
this.options = options;
|
|
26
|
-
}
|
|
27
|
-
onModuleInit() {
|
|
28
|
-
if (this.options.collectLogs === false) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
this.patchProcessStream('stdout');
|
|
32
|
-
this.patchProcessStream('stderr');
|
|
33
|
-
this.logger.log('LogCollector initialized: Patching process.stdout/stderr');
|
|
34
|
-
}
|
|
35
|
-
patchProcessStream(streamName) {
|
|
36
|
-
const stream = process[streamName];
|
|
37
|
-
const originalWrite = stream.write;
|
|
38
|
-
const self = this;
|
|
39
|
-
stream.write = function (chunk, encodingOrCb, cb) {
|
|
40
|
-
const result = originalWrite.apply(this, arguments);
|
|
41
|
-
try {
|
|
42
|
-
const msg = chunk.toString();
|
|
43
|
-
if (msg.includes('[LogCollector]'))
|
|
44
|
-
return result;
|
|
45
|
-
self.capture(streamName === 'stderr' ? 'error' : 'log', msg);
|
|
46
|
-
}
|
|
47
|
-
catch (e) {
|
|
48
|
-
}
|
|
49
|
-
return result;
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
capture(level, message) {
|
|
53
|
-
if (!message.trim())
|
|
54
|
-
return;
|
|
55
|
-
this.profiler.addLog({
|
|
56
|
-
level,
|
|
57
|
-
message: message.trim(),
|
|
58
|
-
timestamp: Date.now()
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
exports.LogCollector = LogCollector;
|
|
63
|
-
exports.LogCollector = LogCollector = LogCollector_1 = __decorate([
|
|
64
|
-
(0, common_1.Injectable)(),
|
|
65
|
-
__param(1, (0, common_1.Inject)('PROFILER_OPTIONS')),
|
|
66
|
-
__metadata("design:paramtypes", [profiler_service_1.ProfilerService, Object])
|
|
67
|
-
], LogCollector);
|
|
68
|
-
//# sourceMappingURL=log-collector.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"log-collector.js","sourceRoot":"","sources":["../../../libs/nestjs-profiler/src/collectors/log-collector.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyF;AACzF,mEAA+D;AAIxD,IAAM,YAAY,oBAAlB,MAAM,YAAY;IAIT;IAC4B;IAJhC,MAAM,GAAG,IAAI,eAAM,CAAC,cAAY,CAAC,IAAI,CAAC,CAAC;IAE/C,YACY,QAAyB,EACG,OAAwB;QADpD,aAAQ,GAAR,QAAQ,CAAiB;QACG,YAAO,GAAP,OAAO,CAAiB;IAC5D,CAAC;IAEL,YAAY;QACR,IAAI,IAAI,CAAC,OAAO,CAAC,WAAW,KAAK,KAAK,EAAE,CAAC;YACrC,OAAO;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AAM,EAAC,kBAAkB,CAAC,CAAA;qCADT,kCAAe;GAJ5B,YAAY,CAmDxB"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { OnModuleInit } from '@nestjs/common';
|
|
2
|
-
import { ProfilerService } from '../services/profiler.service';
|
|
3
|
-
import type { ProfilerOptions } from '../common/profiler-options.interface';
|
|
4
|
-
export declare class MongoCollector implements OnModuleInit {
|
|
5
|
-
private profiler;
|
|
6
|
-
private options;
|
|
7
|
-
private logger;
|
|
8
|
-
private mongodb;
|
|
9
|
-
constructor(profiler: ProfilerService, options: ProfilerOptions);
|
|
10
|
-
onModuleInit(): void;
|
|
11
|
-
private patchMongo;
|
|
12
|
-
private handleQueryOperation;
|
|
13
|
-
private handleInsertOperation;
|
|
14
|
-
private handleAggregateOperation;
|
|
15
|
-
private buildFilter;
|
|
16
|
-
private captureQuery;
|
|
17
|
-
private rowCountResolvers;
|
|
18
|
-
private getRowCount;
|
|
19
|
-
}
|