@midwayjs/prometheus 3.0.0-alpha.9 → 3.0.0-beta.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/CHANGELOG.md +110 -0
- package/dist/config/config.default.d.ts +2 -2
- package/dist/configuration.d.ts +2 -2
- package/dist/configuration.js +23 -19
- package/dist/decorator/master.js +3 -3
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -1
- package/dist/service/dataService.d.ts +2 -1
- package/dist/service/dataService.js +22 -8
- package/dist/utils/utils.js +2 -1
- package/index.d.ts +9 -0
- package/package.json +10 -9
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,116 @@
|
|
|
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
|
+
# [3.0.0-beta.12](https://github.com/midwayjs/midway/compare/v3.0.0-beta.11...v3.0.0-beta.12) (2021-12-28)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @midwayjs/prometheus
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# [3.0.0-beta.11](https://github.com/midwayjs/midway/compare/v3.0.0-beta.10...v3.0.0-beta.11) (2021-12-21)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @midwayjs/prometheus
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# [3.0.0-beta.10](https://github.com/midwayjs/midway/compare/v3.0.0-beta.9...v3.0.0-beta.10) (2021-12-20)
|
|
23
|
+
|
|
24
|
+
**Note:** Version bump only for package @midwayjs/prometheus
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# [3.0.0-beta.9](https://github.com/midwayjs/midway/compare/v3.0.0-beta.8...v3.0.0-beta.9) (2021-12-09)
|
|
31
|
+
|
|
32
|
+
**Note:** Version bump only for package @midwayjs/prometheus
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# [3.0.0-beta.8](https://github.com/midwayjs/midway/compare/v3.0.0-beta.7...v3.0.0-beta.8) (2021-12-08)
|
|
39
|
+
|
|
40
|
+
**Note:** Version bump only for package @midwayjs/prometheus
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# [3.0.0-beta.7](https://github.com/midwayjs/midway/compare/v3.0.0-beta.6...v3.0.0-beta.7) (2021-12-03)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
### Bug Fixes
|
|
50
|
+
|
|
51
|
+
* add app.keys ([#1395](https://github.com/midwayjs/midway/issues/1395)) ([c44afc6](https://github.com/midwayjs/midway/commit/c44afc6cc6764a959d1fa7ae04d60099282d156a))
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
# [3.0.0-beta.6](https://github.com/midwayjs/midway/compare/v3.0.0-beta.5...v3.0.0-beta.6) (2021-11-26)
|
|
58
|
+
|
|
59
|
+
**Note:** Version bump only for package @midwayjs/prometheus
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
# [3.0.0-beta.5](https://github.com/midwayjs/midway/compare/v3.0.0-beta.4...v3.0.0-beta.5) (2021-11-25)
|
|
66
|
+
|
|
67
|
+
**Note:** Version bump only for package @midwayjs/prometheus
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
# [3.0.0-beta.4](https://github.com/midwayjs/midway/compare/v3.0.0-beta.3...v3.0.0-beta.4) (2021-11-24)
|
|
74
|
+
|
|
75
|
+
**Note:** Version bump only for package @midwayjs/prometheus
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
# [3.0.0-beta.3](https://github.com/midwayjs/midway/compare/v3.0.0-beta.2...v3.0.0-beta.3) (2021-11-18)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
### Features
|
|
85
|
+
|
|
86
|
+
* add component and framework config definition ([#1367](https://github.com/midwayjs/midway/issues/1367)) ([b2fe615](https://github.com/midwayjs/midway/commit/b2fe6157f99659471ff1333eca0b86bb889f61a3))
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
# [3.0.0-beta.2](https://github.com/midwayjs/midway/compare/v3.0.0-beta.1...v3.0.0-beta.2) (2021-11-16)
|
|
93
|
+
|
|
94
|
+
**Note:** Version bump only for package @midwayjs/prometheus
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
# [3.0.0-beta.1](https://github.com/midwayjs/midway/compare/v2.12.4...v3.0.0-beta.1) (2021-11-14)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
### Bug Fixes
|
|
104
|
+
|
|
105
|
+
* node v16 typings ([#1269](https://github.com/midwayjs/midway/issues/1269)) ([e3443b5](https://github.com/midwayjs/midway/commit/e3443b58fc1faddadf1e95dd03a2f319410941bb))
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
### Features
|
|
109
|
+
|
|
110
|
+
* add setDiff ([#1263](https://github.com/midwayjs/midway/issues/1263)) ([9dd1a08](https://github.com/midwayjs/midway/commit/9dd1a08326540da52abf79cf31182d4e63b7f4d9))
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
6
116
|
## [2.12.3](https://github.com/midwayjs/midway/compare/v2.12.2...v2.12.3) (2021-08-09)
|
|
7
117
|
|
|
8
118
|
**Note:** Version bump only for package @midwayjs/prometheus
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { DefaultMetricsCollectorConfiguration
|
|
2
|
-
export declare const prometheus:
|
|
1
|
+
import { DefaultMetricsCollectorConfiguration } from 'prom-client';
|
|
2
|
+
export declare const prometheus: DefaultMetricsCollectorConfiguration;
|
|
3
3
|
//# sourceMappingURL=config.default.d.ts.map
|
package/dist/configuration.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export declare class
|
|
1
|
+
export declare class PrometheusConfiguration {
|
|
2
2
|
prometheusConfig: any;
|
|
3
3
|
app: any;
|
|
4
4
|
http_server: any;
|
|
5
|
-
onReady(
|
|
5
|
+
onReady(): Promise<void>;
|
|
6
6
|
onStop(): Promise<void>;
|
|
7
7
|
}
|
|
8
8
|
//# sourceMappingURL=configuration.d.ts.map
|
package/dist/configuration.js
CHANGED
|
@@ -9,9 +9,8 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.PrometheusConfiguration = void 0;
|
|
13
13
|
const decorator_1 = require("@midwayjs/decorator");
|
|
14
|
-
const path_1 = require("path");
|
|
15
14
|
const PromClient = require("prom-client");
|
|
16
15
|
const utils_1 = require("./utils/utils");
|
|
17
16
|
const os = require("os");
|
|
@@ -20,10 +19,11 @@ const fs = require("fs");
|
|
|
20
19
|
const http = require("http");
|
|
21
20
|
const qs = require("querystring");
|
|
22
21
|
const dataService_1 = require("./service/dataService");
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
const DefaultConfig = require("./config/config.default");
|
|
23
|
+
let PrometheusConfiguration = class PrometheusConfiguration {
|
|
24
|
+
async onReady() {
|
|
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,25 +85,29 @@ 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
|
+
], PrometheusConfiguration.prototype, "prometheusConfig", void 0);
|
|
98
98
|
__decorate([
|
|
99
|
-
decorator_1.App(),
|
|
99
|
+
(0, decorator_1.App)(),
|
|
100
100
|
__metadata("design:type", Object)
|
|
101
|
-
],
|
|
102
|
-
|
|
103
|
-
decorator_1.Configuration({
|
|
101
|
+
], PrometheusConfiguration.prototype, "app", void 0);
|
|
102
|
+
PrometheusConfiguration = __decorate([
|
|
103
|
+
(0, decorator_1.Configuration)({
|
|
104
104
|
namespace: 'prometheus',
|
|
105
|
-
importConfigs: [
|
|
105
|
+
importConfigs: [
|
|
106
|
+
{
|
|
107
|
+
default: DefaultConfig,
|
|
108
|
+
},
|
|
109
|
+
],
|
|
106
110
|
})
|
|
107
|
-
],
|
|
108
|
-
exports.
|
|
111
|
+
], PrometheusConfiguration);
|
|
112
|
+
exports.PrometheusConfiguration = PrometheusConfiguration;
|
|
109
113
|
//# sourceMappingURL=configuration.js.map
|
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);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { DefaultMetricsCollectorConfiguration as DefaultConfig } from 'prom-client';
|
|
1
|
+
export { PrometheusConfiguration as Configuration } from './configuration';
|
|
3
2
|
export { DataService } from './service/dataService';
|
|
4
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DataService = exports.Configuration = void 0;
|
|
4
4
|
var configuration_1 = require("./configuration");
|
|
5
|
-
Object.defineProperty(exports, "Configuration", { enumerable: true, get: function () { return configuration_1.
|
|
5
|
+
Object.defineProperty(exports, "Configuration", { enumerable: true, get: function () { return configuration_1.PrometheusConfiguration; } });
|
|
6
6
|
var dataService_1 = require("./service/dataService");
|
|
7
7
|
Object.defineProperty(exports, "DataService", { enumerable: true, get: function () { return dataService_1.DataService; } });
|
|
8
8
|
//# sourceMappingURL=index.js.map
|
|
@@ -8,9 +8,10 @@ export declare class DataService {
|
|
|
8
8
|
bInit: boolean;
|
|
9
9
|
init(): Promise<void>;
|
|
10
10
|
getUser(method: any, status: any, path: any, time: any): Promise<void>;
|
|
11
|
-
define(name: any, type: any, options: any):
|
|
11
|
+
define(name: any, type: any, options: any): 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
|
|
@@ -54,7 +54,7 @@ let DataService = class DataService {
|
|
|
54
54
|
.labels(method, status, path, ...Object.values(this.prometheusConfig.labels))
|
|
55
55
|
.observe(time);
|
|
56
56
|
}
|
|
57
|
-
|
|
57
|
+
define(name, type, options) {
|
|
58
58
|
options.labelNames = options.labelNames
|
|
59
59
|
? [...options.labelNames, ...Object.keys(this.prometheusConfig.labels)]
|
|
60
60
|
: Object.keys(this.prometheusConfig.labels);
|
|
@@ -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/index.d.ts
ADDED
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/prometheus",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-beta.12",
|
|
4
4
|
"description": "midway component for prometheus",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
-
"typings": "
|
|
6
|
+
"typings": "index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc",
|
|
9
9
|
"test": "node --require=ts-node/register ../../node_modules/.bin/jest",
|
|
@@ -18,14 +18,15 @@
|
|
|
18
18
|
],
|
|
19
19
|
"files": [
|
|
20
20
|
"dist/**/*.js",
|
|
21
|
-
"dist/**/*.d.ts"
|
|
21
|
+
"dist/**/*.d.ts",
|
|
22
|
+
"index.d.ts"
|
|
22
23
|
],
|
|
23
24
|
"license": "MIT",
|
|
24
25
|
"devDependencies": {
|
|
25
|
-
"@midwayjs/core": "^3.0.0-
|
|
26
|
-
"@midwayjs/decorator": "^3.0.0-
|
|
27
|
-
"@midwayjs/koa": "^3.0.0-
|
|
28
|
-
"@midwayjs/mock": "^3.0.0-
|
|
26
|
+
"@midwayjs/core": "^3.0.0-beta.12",
|
|
27
|
+
"@midwayjs/decorator": "^3.0.0-beta.12",
|
|
28
|
+
"@midwayjs/koa": "^3.0.0-beta.12",
|
|
29
|
+
"@midwayjs/mock": "^3.0.0-beta.12",
|
|
29
30
|
"@types/request": "^2.48.5"
|
|
30
31
|
},
|
|
31
32
|
"dependencies": {
|
|
@@ -33,7 +34,7 @@
|
|
|
33
34
|
"request": "^2.88.2"
|
|
34
35
|
},
|
|
35
36
|
"engines": {
|
|
36
|
-
"node": ">=
|
|
37
|
+
"node": ">=12"
|
|
37
38
|
},
|
|
38
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "1c46e53eb934248007eeb7fe3920f5ac24e272c6"
|
|
39
40
|
}
|