@midwayjs/prometheus 3.0.0-alpha.1 → 3.0.0-alpha.36
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/CHANGELOG.md +1 -1
- package/dist/configuration.js +10 -10
- package/dist/decorator/master.js +3 -3
- package/dist/service/dataService.d.ts +1 -0
- package/dist/service/dataService.js +21 -7
- package/dist/utils/utils.js +2 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
## [2.12.3](https://github.com/midwayjs/midway/compare/v2.12.2...v2.12.3) (2021-08-09)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @midwayjs/prometheus
|
|
9
9
|
|
package/dist/configuration.js
CHANGED
|
@@ -23,7 +23,7 @@ const dataService_1 = require("./service/dataService");
|
|
|
23
23
|
let AutoConfiguration = class AutoConfiguration {
|
|
24
24
|
async onReady(contanier) {
|
|
25
25
|
PromClient.collectDefaultMetrics(this.prometheusConfig);
|
|
26
|
-
const modules = decorator_1.listModule('prometheus:master');
|
|
26
|
+
const modules = (0, decorator_1.listModule)('prometheus:master');
|
|
27
27
|
const handlers = {};
|
|
28
28
|
let sockFile = path.join(os.tmpdir(), 'midway-master.sock');
|
|
29
29
|
if (process.platform === 'win32') {
|
|
@@ -31,7 +31,7 @@ let AutoConfiguration = class AutoConfiguration {
|
|
|
31
31
|
'\\\\.\\pipe\\' + sockFile.replace(/^\//, '').replace(/\//g, '-');
|
|
32
32
|
}
|
|
33
33
|
if (modules.length > 0 && process.platform !== 'win32') {
|
|
34
|
-
if (utils_1.isMaster()) {
|
|
34
|
+
if ((0, utils_1.isMaster)()) {
|
|
35
35
|
if (fs.existsSync(sockFile)) {
|
|
36
36
|
fs.unlinkSync(sockFile);
|
|
37
37
|
}
|
|
@@ -47,9 +47,9 @@ let AutoConfiguration = class AutoConfiguration {
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
for (const module of modules) {
|
|
50
|
-
const rules = decorator_1.getClassMetadata('prometheus:master:options', module);
|
|
50
|
+
const rules = (0, decorator_1.getClassMetadata)('prometheus:master:options', module);
|
|
51
51
|
for (const rule of rules) {
|
|
52
|
-
if (utils_1.isMaster()) {
|
|
52
|
+
if ((0, utils_1.isMaster)()) {
|
|
53
53
|
handlers[rule.name] = async (...args) => {
|
|
54
54
|
const service = await this.app
|
|
55
55
|
.createAnonymousContext()
|
|
@@ -85,24 +85,24 @@ let AutoConfiguration = class AutoConfiguration {
|
|
|
85
85
|
});
|
|
86
86
|
}
|
|
87
87
|
async onStop() {
|
|
88
|
-
if (utils_1.isMaster()) {
|
|
89
|
-
utils_1.closeLock();
|
|
88
|
+
if ((0, utils_1.isMaster)()) {
|
|
89
|
+
(0, utils_1.closeLock)();
|
|
90
90
|
this.http_server && this.http_server.close();
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
};
|
|
94
94
|
__decorate([
|
|
95
|
-
decorator_1.Config('prometheus'),
|
|
95
|
+
(0, decorator_1.Config)('prometheus'),
|
|
96
96
|
__metadata("design:type", Object)
|
|
97
97
|
], AutoConfiguration.prototype, "prometheusConfig", void 0);
|
|
98
98
|
__decorate([
|
|
99
|
-
decorator_1.App(),
|
|
99
|
+
(0, decorator_1.App)(),
|
|
100
100
|
__metadata("design:type", Object)
|
|
101
101
|
], AutoConfiguration.prototype, "app", void 0);
|
|
102
102
|
AutoConfiguration = __decorate([
|
|
103
|
-
decorator_1.Configuration({
|
|
103
|
+
(0, decorator_1.Configuration)({
|
|
104
104
|
namespace: 'prometheus',
|
|
105
|
-
importConfigs: [path_1.join(__dirname, 'config')],
|
|
105
|
+
importConfigs: [(0, path_1.join)(__dirname, 'config')],
|
|
106
106
|
})
|
|
107
107
|
], AutoConfiguration);
|
|
108
108
|
exports.AutoConfiguration = AutoConfiguration;
|
package/dist/decorator/master.js
CHANGED
|
@@ -9,9 +9,9 @@ const utils_1 = require("../utils/utils");
|
|
|
9
9
|
const qs = require("querystring");
|
|
10
10
|
function Master() {
|
|
11
11
|
return function (target, propertyKey, descriptor) {
|
|
12
|
-
decorator_1.saveModule('prometheus:master', target.constructor);
|
|
12
|
+
(0, decorator_1.saveModule)('prometheus:master', target.constructor);
|
|
13
13
|
const sockFile = path.join(os.tmpdir(), 'midway-master.sock');
|
|
14
|
-
if (!utils_1.isMaster()) {
|
|
14
|
+
if (!(0, utils_1.isMaster)()) {
|
|
15
15
|
descriptor.value = (...args) => {
|
|
16
16
|
const params = {
|
|
17
17
|
path: `${target.constructor.name}_${propertyKey}`,
|
|
@@ -26,7 +26,7 @@ function Master() {
|
|
|
26
26
|
});
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
|
-
decorator_1.attachClassMetadata('prometheus:master:options', {
|
|
29
|
+
(0, decorator_1.attachClassMetadata)('prometheus:master:options', {
|
|
30
30
|
name: `${target.constructor.name}_${propertyKey}`,
|
|
31
31
|
value: descriptor.value,
|
|
32
32
|
}, target.constructor);
|
|
@@ -11,6 +11,7 @@ export declare class DataService {
|
|
|
11
11
|
define(name: any, type: any, options: any): Promise<void>;
|
|
12
12
|
inc(name: any, labels: any, value?: number): Promise<void>;
|
|
13
13
|
set(name: any, value: any): Promise<void>;
|
|
14
|
+
setDiff(name: any, diff: any): Promise<void>;
|
|
14
15
|
getData(): Promise<string>;
|
|
15
16
|
}
|
|
16
17
|
//# sourceMappingURL=dataService.d.ts.map
|
|
@@ -66,42 +66,56 @@ let DataService = class DataService {
|
|
|
66
66
|
async set(name, value) {
|
|
67
67
|
this.userDefinedMetrics[name].set({ ...this.prometheusConfig.labels }, value);
|
|
68
68
|
}
|
|
69
|
+
async setDiff(name, diff) {
|
|
70
|
+
const current = await this.userDefinedMetrics[name].get();
|
|
71
|
+
let value = diff;
|
|
72
|
+
if (current.values.length !== 0) {
|
|
73
|
+
value = current.values[0].value + diff;
|
|
74
|
+
}
|
|
75
|
+
this.userDefinedMetrics[name].set({ ...this.prometheusConfig.labels }, value);
|
|
76
|
+
}
|
|
69
77
|
async getData() {
|
|
70
78
|
const Register = PromClient.register;
|
|
71
79
|
return Register.metrics();
|
|
72
80
|
}
|
|
73
81
|
};
|
|
74
82
|
__decorate([
|
|
75
|
-
decorator_1.Config('prometheus'),
|
|
83
|
+
(0, decorator_1.Config)('prometheus'),
|
|
76
84
|
__metadata("design:type", Object)
|
|
77
85
|
], DataService.prototype, "prometheusConfig", void 0);
|
|
78
86
|
__decorate([
|
|
79
|
-
master_1.Master(),
|
|
87
|
+
(0, master_1.Master)(),
|
|
80
88
|
__metadata("design:type", Function),
|
|
81
89
|
__metadata("design:paramtypes", [Object, Object, Object, Object]),
|
|
82
90
|
__metadata("design:returntype", Promise)
|
|
83
91
|
], DataService.prototype, "getUser", null);
|
|
84
92
|
__decorate([
|
|
85
|
-
master_1.Master(),
|
|
93
|
+
(0, master_1.Master)(),
|
|
86
94
|
__metadata("design:type", Function),
|
|
87
95
|
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
88
96
|
__metadata("design:returntype", Promise)
|
|
89
97
|
], DataService.prototype, "inc", null);
|
|
90
98
|
__decorate([
|
|
91
|
-
master_1.Master(),
|
|
99
|
+
(0, master_1.Master)(),
|
|
92
100
|
__metadata("design:type", Function),
|
|
93
101
|
__metadata("design:paramtypes", [Object, Object]),
|
|
94
102
|
__metadata("design:returntype", Promise)
|
|
95
103
|
], DataService.prototype, "set", null);
|
|
96
104
|
__decorate([
|
|
97
|
-
master_1.Master(),
|
|
105
|
+
(0, master_1.Master)(),
|
|
106
|
+
__metadata("design:type", Function),
|
|
107
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
108
|
+
__metadata("design:returntype", Promise)
|
|
109
|
+
], DataService.prototype, "setDiff", null);
|
|
110
|
+
__decorate([
|
|
111
|
+
(0, master_1.Master)(),
|
|
98
112
|
__metadata("design:type", Function),
|
|
99
113
|
__metadata("design:paramtypes", []),
|
|
100
114
|
__metadata("design:returntype", Promise)
|
|
101
115
|
], DataService.prototype, "getData", null);
|
|
102
116
|
DataService = __decorate([
|
|
103
|
-
decorator_1.Provide(),
|
|
104
|
-
decorator_1.Scope(decorator_1.ScopeEnum.Singleton)
|
|
117
|
+
(0, decorator_1.Provide)(),
|
|
118
|
+
(0, decorator_1.Scope)(decorator_1.ScopeEnum.Singleton)
|
|
105
119
|
], DataService);
|
|
106
120
|
exports.DataService = DataService;
|
|
107
121
|
//# sourceMappingURL=dataService.js.map
|
package/dist/utils/utils.js
CHANGED
|
@@ -11,7 +11,8 @@ const ppid = process.ppid;
|
|
|
11
11
|
const now = new Date();
|
|
12
12
|
const lockFile = path.join(os.tmpdir(), `midway-master-${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()}-${ppid}.lock`);
|
|
13
13
|
function isMaster() {
|
|
14
|
-
|
|
14
|
+
// fix for node v16
|
|
15
|
+
if (cluster['isPrimary'] || cluster['isMaster']) {
|
|
15
16
|
return true;
|
|
16
17
|
}
|
|
17
18
|
if (process.argv[1].indexOf('egg-cluster') >= 0) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/prometheus",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.36+b2d0a363",
|
|
4
4
|
"description": "midway component for prometheus",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
],
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@midwayjs/core": "^3.0.0-alpha.
|
|
26
|
-
"@midwayjs/decorator": "^3.0.0-alpha.
|
|
27
|
-
"@midwayjs/koa": "^3.0.0-alpha.
|
|
28
|
-
"@midwayjs/mock": "^3.0.0-alpha.
|
|
25
|
+
"@midwayjs/core": "^3.0.0-alpha.36+b2d0a363",
|
|
26
|
+
"@midwayjs/decorator": "^3.0.0-alpha.36+b2d0a363",
|
|
27
|
+
"@midwayjs/koa": "^3.0.0-alpha.36+b2d0a363",
|
|
28
|
+
"@midwayjs/mock": "^3.0.0-alpha.36+b2d0a363",
|
|
29
29
|
"@types/request": "^2.48.5"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"engines": {
|
|
36
36
|
"node": ">= 12.0.0"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "b2d0a363d98302fda64ff47a6d25fca6e003a434"
|
|
39
39
|
}
|