@midwayjs/prometheus 3.6.1-beta.0 → 3.7.0
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 +80 -0
- package/dist/index.js +5 -1
- package/dist/service/dataService.js +3 -1
- package/package.json +7 -7
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2013 - Now midwayjs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
### 自定义方法
|
|
2
|
+
|
|
3
|
+
定义 Histogram 方法:
|
|
4
|
+
```
|
|
5
|
+
@Configuration({
|
|
6
|
+
imports: [
|
|
7
|
+
koa,
|
|
8
|
+
validate,
|
|
9
|
+
prometheus,
|
|
10
|
+
{
|
|
11
|
+
component: info,
|
|
12
|
+
enabledEnvironment: ['local'],
|
|
13
|
+
},
|
|
14
|
+
],
|
|
15
|
+
importConfigs: [join(__dirname, './config')],
|
|
16
|
+
})
|
|
17
|
+
export class ContainerLifeCycle {
|
|
18
|
+
@App()
|
|
19
|
+
app: koa.Application;
|
|
20
|
+
|
|
21
|
+
async onReady() {
|
|
22
|
+
const result = await this.app.getApplicationContext().getAsync(DataService);
|
|
23
|
+
// 此处定义了一个名字叫 test_histogram 的 Histogram
|
|
24
|
+
result.define('test_histogram', 'Histogram', {
|
|
25
|
+
help: '132',
|
|
26
|
+
name: 'test_histogram',
|
|
27
|
+
buckets: [5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000],
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
为了测试这个Histogram,我们在一个接口里面:
|
|
34
|
+
```
|
|
35
|
+
import { Inject, Controller, Get, Query } from '@midwayjs/decorator';
|
|
36
|
+
import { Context } from '@midwayjs/koa';
|
|
37
|
+
import { DataService } from '@midwayjs/prometheus';
|
|
38
|
+
import { UserService } from '../service/user.service';
|
|
39
|
+
|
|
40
|
+
@Controller('/api')
|
|
41
|
+
export class APIController {
|
|
42
|
+
@Inject()
|
|
43
|
+
ctx: Context;
|
|
44
|
+
|
|
45
|
+
@Inject()
|
|
46
|
+
userService: UserService;
|
|
47
|
+
|
|
48
|
+
@Inject()
|
|
49
|
+
dataService: DataService;
|
|
50
|
+
|
|
51
|
+
@Get('/get_user')
|
|
52
|
+
async getUser(@Query('uid') uid) {
|
|
53
|
+
this.dataService.observe('test_histogram', [], 100); //此处我们observe了这个histogram
|
|
54
|
+
const user = await this.userService.getUser({ uid });
|
|
55
|
+
return { success: true, message: 'OK', data: user };
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
然后访问这个接口,然后我们查看我们 /metrics 的接口返回:
|
|
61
|
+
```
|
|
62
|
+
# HELP test_histogram 132
|
|
63
|
+
# TYPE test_histogram histogram
|
|
64
|
+
test_histogram_bucket{le="5",APP_NAME="default"} 0
|
|
65
|
+
test_histogram_bucket{le="10",APP_NAME="default"} 0
|
|
66
|
+
test_histogram_bucket{le="25",APP_NAME="default"} 0
|
|
67
|
+
test_histogram_bucket{le="50",APP_NAME="default"} 0
|
|
68
|
+
test_histogram_bucket{le="100",APP_NAME="default"} 1
|
|
69
|
+
test_histogram_bucket{le="250",APP_NAME="default"} 1
|
|
70
|
+
test_histogram_bucket{le="500",APP_NAME="default"} 1
|
|
71
|
+
test_histogram_bucket{le="1000",APP_NAME="default"} 1
|
|
72
|
+
test_histogram_bucket{le="2500",APP_NAME="default"} 1
|
|
73
|
+
test_histogram_bucket{le="5000",APP_NAME="default"} 1
|
|
74
|
+
test_histogram_bucket{le="10000",APP_NAME="default"} 1
|
|
75
|
+
test_histogram_bucket{le="+Inf",APP_NAME="default"} 1
|
|
76
|
+
test_histogram_sum{APP_NAME="default"} 100
|
|
77
|
+
test_histogram_count{APP_NAME="default"} 1
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
至此,已经我们想要的自定义 Histogram 了。
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -64,7 +64,9 @@ let DataService = class DataService {
|
|
|
64
64
|
this.userDefinedMetrics[name].inc({ ...labels, ...this.prometheusConfig.labels }, value);
|
|
65
65
|
}
|
|
66
66
|
async observe(name, labels, value) {
|
|
67
|
-
this.userDefinedMetrics[name]
|
|
67
|
+
this.userDefinedMetrics[name]
|
|
68
|
+
.labels(...labels, ...Object.values(this.prometheusConfig.labels))
|
|
69
|
+
.observe(value);
|
|
68
70
|
}
|
|
69
71
|
async set(name, value) {
|
|
70
72
|
this.userDefinedMetrics[name].set({ ...this.prometheusConfig.labels }, value);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/prometheus",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.0",
|
|
4
4
|
"description": "midway component for prometheus",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -23,11 +23,10 @@
|
|
|
23
23
|
],
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@midwayjs/core": "^3.
|
|
27
|
-
"@midwayjs/koa": "^3.
|
|
28
|
-
"@midwayjs/mock": "^3.
|
|
29
|
-
"@types/request": "2.48.8"
|
|
30
|
-
"typescript": "4.5.4"
|
|
26
|
+
"@midwayjs/core": "^3.7.0",
|
|
27
|
+
"@midwayjs/koa": "^3.7.0",
|
|
28
|
+
"@midwayjs/mock": "^3.7.0",
|
|
29
|
+
"@types/request": "2.48.8"
|
|
31
30
|
},
|
|
32
31
|
"dependencies": {
|
|
33
32
|
"prom-client": "^14.0.0",
|
|
@@ -35,5 +34,6 @@
|
|
|
35
34
|
},
|
|
36
35
|
"engines": {
|
|
37
36
|
"node": ">=12"
|
|
38
|
-
}
|
|
37
|
+
},
|
|
38
|
+
"gitHead": "99386083ee26b386fd508b9c892091c914e77535"
|
|
39
39
|
}
|