@midwayjs/prometheus 3.0.0-beta.9 → 3.0.3

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.default.js","sourceRoot":"","sources":["../../src/config/config.default.ts"],"names":[],"mappings":";;;AAEa,QAAA,UAAU,GAAyC;IAC9D,MAAM,EAAE;QACN,QAAQ,EAAE,SAAS;KACpB;CACF,CAAC","sourcesContent":["import { DefaultMetricsCollectorConfiguration } from 'prom-client';\n\nexport const prometheus: DefaultMetricsCollectorConfiguration = {\n labels: {\n APP_NAME: 'default',\n },\n};\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configuration.js","sourceRoot":"","sources":["../src/configuration.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAM6B;AAC7B,0CAA0C;AAC1C,yCAAoD;AACpD,yBAAyB;AACzB,6BAA6B;AAC7B,yBAAyB;AACzB,6BAA6B;AAC7B,kCAAkC;AAClC,uDAAoD;AACpD,yDAAyD;AAUzD,IAAa,uBAAuB,GAApC,MAAa,uBAAuB;IASlC,KAAK,CAAC,OAAO;QACX,UAAU,CAAC,qBAAqB,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QACxD,MAAM,OAAO,GAAG,IAAA,sBAAU,EAAC,mBAAmB,CAAC,CAAC;QAChD,MAAM,QAAQ,GAAG,EAAE,CAAC;QACpB,IAAI,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,oBAAoB,CAAC,CAAC;QAC5D,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE;YAChC,QAAQ;gBACN,eAAe,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;SACrE;QACD,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC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QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,MAAM;QACV,IAAI,IAAA,gBAAQ,GAAE,EAAE;YACd,IAAA,iBAAS,GAAE,CAAC;YACZ,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;SAC9C;IACH,CAAC;CACF,CAAA;AA3EC;IADC,IAAA,kBAAM,EAAC,YAAY,CAAC;;iEACC;AAGtB;IADC,IAAA,eAAG,GAAE;;oDACF;AALO,uBAAuB;IARnC,IAAA,yBAAa,EAAC;QACb,SAAS,EAAE,YAAY;QACvB,aAAa,EAAE;YACb;gBACE,OAAO,EAAE,aAAa;aACvB;SACF;KACF,CAAC;GACW,uBAAuB,CA6EnC;AA7EY,0DAAuB","sourcesContent":["import {\n App,\n Config,\n Configuration,\n getClassMetadata,\n listModule,\n} from '@midwayjs/decorator';\nimport * as PromClient from 'prom-client';\nimport { isMaster, closeLock } from './utils/utils';\nimport * as os from 'os';\nimport * as path from 'path';\nimport * as fs from 'fs';\nimport * as http from 'http';\nimport * as qs from 'querystring';\nimport { DataService } from './service/dataService';\nimport * as DefaultConfig from './config/config.default';\n\n@Configuration({\n namespace: 'prometheus',\n importConfigs: [\n {\n default: DefaultConfig,\n },\n ],\n})\nexport class PrometheusConfiguration {\n @Config('prometheus')\n prometheusConfig: any;\n\n @App()\n app;\n\n http_server: any;\n\n async onReady() {\n PromClient.collectDefaultMetrics(this.prometheusConfig);\n const modules = listModule('prometheus:master');\n const handlers = {};\n let sockFile = path.join(os.tmpdir(), 'midway-master.sock');\n if (process.platform === 'win32') {\n sockFile =\n '\\\\\\\\.\\\\pipe\\\\' + sockFile.replace(/^\\//, '').replace(/\\//g, '-');\n }\n if (modules.length > 0 && process.platform !== 'win32') {\n if (isMaster()) {\n if (fs.existsSync(sockFile)) {\n fs.unlinkSync(sockFile);\n }\n this.http_server = http\n .createServer((req, res) => {\n const query = qs.parse(req.url.substr('/?'.length));\n const params = JSON.parse(query.params as string);\n handlers[`${query.path}`](...params).then(result => {\n res.end(result);\n });\n })\n .listen(sockFile);\n }\n }\n for (const module of modules) {\n const rules = getClassMetadata('prometheus:master:options', module);\n for (const rule of rules) {\n if (isMaster()) {\n handlers[rule.name] = async (...args) => {\n const service = await this.app\n .createAnonymousContext()\n .requestContext.getAsync(module);\n return rule.value.call(service, ...args);\n };\n }\n }\n }\n this.app.use(async (ctx, next) => {\n const service = await ctx.requestContext.getAsync(DataService);\n const startAt = process.hrtime();\n try {\n if (ctx.path === '/metrics') {\n const result = await service.getData();\n const Register = PromClient.register;\n ctx.set('Content-Type', Register.contentType);\n ctx.body = result;\n } else {\n await next();\n }\n const diff = process.hrtime(startAt);\n const time = diff[0] * 1e3 + diff[1] * 1e-6;\n service.getUser(ctx.method, '200', ctx.path, time);\n } catch (e) {\n const diff = process.hrtime(startAt);\n const time = diff[0] * 1e3 + diff[1] * 1e-6;\n service.getUser(ctx.method, '500', ctx.path, time);\n throw e;\n }\n });\n }\n\n async onStop() {\n if (isMaster()) {\n closeLock();\n this.http_server && this.http_server.close();\n }\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"master.js","sourceRoot":"","sources":["../../src/decorator/master.ts"],"names":[],"mappings":";;;AAAA,mDAAsE;AACtE,mCAAmC;AACnC,6BAA6B;AAC7B,yBAAyB;AACzB,0CAA0C;AAC1C,kCAAkC;AAElC,SAAgB,MAAM;IACpB,OAAO,UACL,MAAW,EACX,WAAmB,EACnB,UAA8B;QAE9B,IAAA,sBAAU,EAAC,mBAAmB,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;QACpD,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,oBAAoB,CAAC,CAAC;QAC9D,IAAI,CAAC,IAAA,gBAAQ,GAAE,EAAE;YACf,UAAU,CAAC,KAAK,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE;gBAC7B,MAAM,MAAM,GAAG;oBACb,IAAI,EAAE,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,IAAI,WAAW,EAAE;oBACjD,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;iBAC7B,CAAC;gBACF,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;oBACrC,OAAO,CACL;wBACE,GAAG,EAAE,eAAe,QAAQ,MAAM,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE;qBACzD,EACD,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;wBACjB,OAAO,CAAC,IAAI,CAAC,CAAC;oBAChB,CAAC,CACF,CAAC;gBACJ,CAAC,CAAC,CAAC;YACL,CAAC,CAAC;SACH;QACD,IAAA,+BAAmB,EACjB,2BAA2B,EAC3B;YACE,IAAI,EAAE,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,IAAI,WAAW,EAAE;YACjD,KAAK,EAAE,UAAU,CAAC,KAAK;SACxB,EACD,MAAM,CAAC,WAAW,CACnB,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAnCD,wBAmCC","sourcesContent":["import { saveModule, attachClassMetadata } from '@midwayjs/decorator';\nimport * as request from 'request';\nimport * as path from 'path';\nimport * as os from 'os';\nimport { isMaster } from '../utils/utils';\nimport * as qs from 'querystring';\n\nexport function Master() {\n return function (\n target: any,\n propertyKey: string,\n descriptor: PropertyDescriptor\n ) {\n saveModule('prometheus:master', target.constructor);\n const sockFile = path.join(os.tmpdir(), 'midway-master.sock');\n if (!isMaster()) {\n descriptor.value = (...args) => {\n const params = {\n path: `${target.constructor.name}_${propertyKey}`,\n params: JSON.stringify(args),\n };\n return new Promise((resolve, reject) => {\n request(\n {\n uri: `http://unix:${sockFile}:/?${qs.stringify(params)}`,\n },\n (err, res, body) => {\n resolve(body);\n }\n );\n });\n };\n }\n attachClassMetadata(\n 'prometheus:master:options',\n {\n name: `${target.constructor.name}_${propertyKey}`,\n value: descriptor.value,\n },\n target.constructor\n );\n };\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iDAA2E;AAAlE,8GAAA,uBAAuB,OAAiB;AACjD,qDAAoD;AAA3C,0GAAA,WAAW,OAAA","sourcesContent":["export { PrometheusConfiguration as Configuration } from './configuration';\nexport { DataService } from './service/dataService';\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dataService.js","sourceRoot":"","sources":["../../src/service/dataService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAAwE;AACxE,sCAAsC;AACtC,gDAA6C;AAC7C,0CAA0C;AAI1C,IAAa,WAAW,GAAxB,MAAa,WAAW;IAAxB;QAKE,uBAAkB,GAAQ,EAAE,CAAC;QAO7B,UAAK,GAAG,KAAK,CAAC;IA2FhB,CAAC;IAzFC,KAAK,CAAC,IAAI;QACR,IAAI,CAAC,eAAe,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC;YACxC,IAAI,EAAE,mCAAmC;YACzC,IAAI,EAAE,yBAAyB;YAC/B,UAAU,EAAE;gBACV,QAAQ;gBACR,QAAQ;gBACR,KAAK;gBACL,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC;aAC7C;SACF,CAAC,CAAC;QACH,IAAI,CAAC,iBAAiB,GAAG,IAAI,MAAM,CAAC,SAAS,CAAC;YAC5C,IAAI,EAAE,oCAAoC;YAC1C,IAAI,EAAE,8CAA8C;YACpD,UAAU,EAAE;gBACV,QAAQ;gBACR,QAAQ;gBACR,KAAK;gBACL,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC;aAC7C;YACD,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE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;GACd,WAAW,CAuGvB;AAvGY,kCAAW","sourcesContent":["import { Config, Provide, Scope, ScopeEnum } from '@midwayjs/decorator';\nimport * as Client from 'prom-client';\nimport { Master } from '../decorator/master';\nimport * as PromClient from 'prom-client';\n\n@Provide()\n@Scope(ScopeEnum.Singleton)\nexport class DataService {\n responseSummary: Client.Summary<any>;\n\n responseHistogram: Client.Histogram<any>;\n\n userDefinedMetrics: any = {};\n\n metrics: any;\n\n @Config('prometheus')\n prometheusConfig;\n\n bInit = false;\n\n async init() {\n this.responseSummary = new Client.Summary({\n name: 'http_request_latency_milliseconds',\n help: 'response time in millis',\n labelNames: [\n 'method',\n 'status',\n 'uri',\n ...Object.keys(this.prometheusConfig.labels),\n ],\n });\n this.responseHistogram = new Client.Histogram({\n name: 'http_request_duration_milliseconds',\n help: 'http_request_duration_milliseconds histogram',\n labelNames: [\n 'method',\n 'status',\n 'uri',\n ...Object.keys(this.prometheusConfig.labels),\n ],\n buckets: [5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000],\n });\n }\n\n @Master()\n async getUser(method, status, path, time) {\n if (!this.bInit) {\n this.init();\n this.bInit = true;\n }\n this.responseSummary\n .labels(\n method,\n status,\n path,\n ...(Object.values(this.prometheusConfig.labels) as string[])\n )\n .observe(time);\n this.responseHistogram\n .labels(\n method,\n status,\n path,\n ...(Object.values(this.prometheusConfig.labels) as string[])\n )\n .observe(time);\n }\n\n define(name, type, options) {\n options.labelNames = options.labelNames\n ? [...options.labelNames, ...Object.keys(this.prometheusConfig.labels)]\n : Object.keys(this.prometheusConfig.labels);\n this.userDefinedMetrics[name] = new Client[type](options);\n }\n\n @Master()\n async inc(name, labels, value = 1) {\n this.userDefinedMetrics[name].inc(\n { ...labels, ...this.prometheusConfig.labels },\n value\n );\n }\n\n @Master()\n async set(name, value) {\n this.userDefinedMetrics[name].set(\n { ...this.prometheusConfig.labels },\n value\n );\n }\n\n @Master()\n async setDiff(name, diff) {\n const current = await this.userDefinedMetrics[name].get();\n let value = diff;\n if (current.values.length !== 0) {\n value = current.values[0].value + diff;\n }\n this.userDefinedMetrics[name].set(\n { ...this.prometheusConfig.labels },\n value\n );\n }\n\n @Master()\n async getData() {\n const Register = PromClient.register;\n return Register.metrics();\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":";;;AAAA,mCAAmC;AACnC,6BAA6B;AAC7B,yBAAyB;AACzB,yBAAyB;AAEzB,IAAI,GAAG,GAAG,IAAI,CAAC;AACf,IAAI,KAAK,GAAG,KAAK,CAAC;AAClB,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;AAC1B,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;AACvB,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CACxB,EAAE,CAAC,MAAM,EAAE,EACX,iBAAiB,GAAG,CAAC,WAAW,EAAE,IAChC,GAAG,CAAC,QAAQ,EAAE,GAAG,CACnB,IAAI,GAAG,CAAC,OAAO,EAAE,IAAI,IAAI,OAAO,CACjC,CAAC;AACF,SAAgB,QAAQ;IACtB,mBAAmB;IACnB,IAAI,OAAO,CAAC,WAAW,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,EAAE;QAC/C,OAAO,IAAI,CAAC;KACb;IAED,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE;QAC/C,0BAA0B;QAC1B,IAAI,KAAK,IAAI,GAAG,EAAE;YAChB,OAAO,IAAI,CAAC;SACb;aAAM,IAAI,KAAK,EAAE;YAChB,OAAO,KAAK,CAAC;SACd;aAAM;YACL,KAAK,GAAG,IAAI,CAAC;YACb,IAAI;gBACF,MAAM,MAAM,GAAG,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;gBAC3C,GAAG,GAAG,MAAM,CAAC;gBACb,OAAO,IAAI,CAAC;aACb;YAAC,OAAO,CAAC,EAAE;gBACV,OAAO,KAAK,CAAC;aACd;SACF;KACF;IAED,IAAI,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE;QACpC,iBAAiB;QACjB,IAAI,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,KAAK,CAAC,EAAE;YACjD,OAAO,IAAI,CAAC;SACb;KACF;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAhCD,4BAgCC;AAED,SAAgB,SAAS;IACvB,IAAI,GAAG,EAAE;QACP,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QAClB,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QACxB,GAAG,GAAG,IAAI,CAAC;KACZ;AACH,CAAC;AAND,8BAMC","sourcesContent":["import * as cluster from 'cluster';\nimport * as path from 'path';\nimport * as os from 'os';\nimport * as fs from 'fs';\n\nlet gfp = null;\nlet bInit = false;\nconst ppid = process.ppid;\nconst now = new Date();\nconst lockFile = path.join(\n os.tmpdir(),\n `midway-master-${now.getFullYear()}-${\n now.getMonth() + 1\n }-${now.getDate()}-${ppid}.lock`\n);\nexport function isMaster() {\n // fix for node v16\n if (cluster['isPrimary'] || cluster['isMaster']) {\n return true;\n }\n\n if (process.argv[1].indexOf('egg-cluster') >= 0) {\n // Is run with egg-scripts\n if (bInit && gfp) {\n return true;\n } else if (bInit) {\n return false;\n } else {\n bInit = true;\n try {\n const result = fs.openSync(lockFile, 'wx');\n gfp = result;\n return true;\n } catch (e) {\n return false;\n }\n }\n }\n\n if (process.env && process.env.pm_id) {\n //Is run with PM2\n if (parseInt(process.env.NODE_APP_INSTANCE) === 0) {\n return true;\n }\n }\n\n return false;\n}\n\nexport function closeLock() {\n if (gfp) {\n fs.closeSync(gfp);\n fs.unlinkSync(lockFile);\n gfp = null;\n }\n}\n"]}
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@midwayjs/prometheus",
3
- "version": "3.0.0-beta.9",
3
+ "version": "3.0.3",
4
4
  "description": "midway component for prometheus",
5
5
  "main": "dist/index.js",
6
6
  "typings": "index.d.ts",
7
7
  "scripts": {
8
8
  "build": "tsc",
9
- "test": "node --require=ts-node/register ../../node_modules/.bin/jest",
10
- "cov": "node --require=ts-node/register ../../node_modules/.bin/jest --coverage --forceExit",
9
+ "test": "node --require=ts-node/register ../../node_modules/.bin/jest --runInBand",
10
+ "cov": "node --require=ts-node/register ../../node_modules/.bin/jest --runInBand --coverage --forceExit",
11
11
  "ci": "npm run cov --ts"
12
12
  },
13
13
  "keywords": [
@@ -19,22 +19,23 @@
19
19
  "files": [
20
20
  "dist/**/*.js",
21
21
  "dist/**/*.d.ts",
22
- "index.d.ts"
22
+ "index.d.ts",
23
+ "dist/**/*.js.map"
23
24
  ],
24
25
  "license": "MIT",
25
26
  "devDependencies": {
26
- "@midwayjs/core": "^3.0.0-beta.9",
27
- "@midwayjs/decorator": "^3.0.0-beta.9",
28
- "@midwayjs/koa": "^3.0.0-beta.9",
29
- "@midwayjs/mock": "^3.0.0-beta.9",
30
- "@types/request": "^2.48.5"
27
+ "@midwayjs/core": "^3.0.2",
28
+ "@midwayjs/decorator": "^3.0.2",
29
+ "@midwayjs/koa": "^3.0.3",
30
+ "@midwayjs/mock": "^3.0.2",
31
+ "@types/request": "2.48.8"
31
32
  },
32
33
  "dependencies": {
33
- "prom-client": "^13.1.0",
34
- "request": "^2.88.2"
34
+ "prom-client": "^14.0.0",
35
+ "request": "2.88.2"
35
36
  },
36
37
  "engines": {
37
38
  "node": ">=12"
38
39
  },
39
- "gitHead": "d23e4a4fee58097b98461625c428a37d55535cec"
40
+ "gitHead": "43a5971b284aa918d22d191236c5664b011f8d87"
40
41
  }
package/CHANGELOG.md DELETED
@@ -1,321 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- # [3.0.0-beta.9](https://github.com/midwayjs/midway/compare/v3.0.0-beta.8...v3.0.0-beta.9) (2021-12-09)
7
-
8
- **Note:** Version bump only for package @midwayjs/prometheus
9
-
10
-
11
-
12
-
13
-
14
- # [3.0.0-beta.8](https://github.com/midwayjs/midway/compare/v3.0.0-beta.7...v3.0.0-beta.8) (2021-12-08)
15
-
16
- **Note:** Version bump only for package @midwayjs/prometheus
17
-
18
-
19
-
20
-
21
-
22
- # [3.0.0-beta.7](https://github.com/midwayjs/midway/compare/v3.0.0-beta.6...v3.0.0-beta.7) (2021-12-03)
23
-
24
-
25
- ### Bug Fixes
26
-
27
- * add app.keys ([#1395](https://github.com/midwayjs/midway/issues/1395)) ([c44afc6](https://github.com/midwayjs/midway/commit/c44afc6cc6764a959d1fa7ae04d60099282d156a))
28
-
29
-
30
-
31
-
32
-
33
- # [3.0.0-beta.6](https://github.com/midwayjs/midway/compare/v3.0.0-beta.5...v3.0.0-beta.6) (2021-11-26)
34
-
35
- **Note:** Version bump only for package @midwayjs/prometheus
36
-
37
-
38
-
39
-
40
-
41
- # [3.0.0-beta.5](https://github.com/midwayjs/midway/compare/v3.0.0-beta.4...v3.0.0-beta.5) (2021-11-25)
42
-
43
- **Note:** Version bump only for package @midwayjs/prometheus
44
-
45
-
46
-
47
-
48
-
49
- # [3.0.0-beta.4](https://github.com/midwayjs/midway/compare/v3.0.0-beta.3...v3.0.0-beta.4) (2021-11-24)
50
-
51
- **Note:** Version bump only for package @midwayjs/prometheus
52
-
53
-
54
-
55
-
56
-
57
- # [3.0.0-beta.3](https://github.com/midwayjs/midway/compare/v3.0.0-beta.2...v3.0.0-beta.3) (2021-11-18)
58
-
59
-
60
- ### Features
61
-
62
- * add component and framework config definition ([#1367](https://github.com/midwayjs/midway/issues/1367)) ([b2fe615](https://github.com/midwayjs/midway/commit/b2fe6157f99659471ff1333eca0b86bb889f61a3))
63
-
64
-
65
-
66
-
67
-
68
- # [3.0.0-beta.2](https://github.com/midwayjs/midway/compare/v3.0.0-beta.1...v3.0.0-beta.2) (2021-11-16)
69
-
70
- **Note:** Version bump only for package @midwayjs/prometheus
71
-
72
-
73
-
74
-
75
-
76
- # [3.0.0-beta.1](https://github.com/midwayjs/midway/compare/v2.12.4...v3.0.0-beta.1) (2021-11-14)
77
-
78
-
79
- ### Bug Fixes
80
-
81
- * node v16 typings ([#1269](https://github.com/midwayjs/midway/issues/1269)) ([e3443b5](https://github.com/midwayjs/midway/commit/e3443b58fc1faddadf1e95dd03a2f319410941bb))
82
-
83
-
84
- ### Features
85
-
86
- * add setDiff ([#1263](https://github.com/midwayjs/midway/issues/1263)) ([9dd1a08](https://github.com/midwayjs/midway/commit/9dd1a08326540da52abf79cf31182d4e63b7f4d9))
87
-
88
-
89
-
90
-
91
-
92
- ## [2.12.3](https://github.com/midwayjs/midway/compare/v2.12.2...v2.12.3) (2021-08-09)
93
-
94
- **Note:** Version bump only for package @midwayjs/prometheus
95
-
96
-
97
-
98
-
99
-
100
- ## [2.12.1](https://github.com/midwayjs/midway/compare/v2.12.0...v2.12.1) (2021-08-01)
101
-
102
- **Note:** Version bump only for package @midwayjs/prometheus
103
-
104
-
105
-
106
-
107
-
108
- # [2.12.0](https://github.com/midwayjs/midway/compare/v2.11.7...v2.12.0) (2021-07-30)
109
-
110
- **Note:** Version bump only for package @midwayjs/prometheus
111
-
112
-
113
-
114
-
115
-
116
- ## [2.11.6](https://github.com/midwayjs/midway/compare/v2.11.5...v2.11.6) (2021-07-16)
117
-
118
- **Note:** Version bump only for package @midwayjs/prometheus
119
-
120
-
121
-
122
-
123
-
124
- ## [2.11.5](https://github.com/midwayjs/midway/compare/v2.11.4...v2.11.5) (2021-07-15)
125
-
126
- **Note:** Version bump only for package @midwayjs/prometheus
127
-
128
-
129
-
130
-
131
-
132
- ## [2.11.4](https://github.com/midwayjs/midway/compare/v2.11.3...v2.11.4) (2021-07-06)
133
-
134
- **Note:** Version bump only for package @midwayjs/prometheus
135
-
136
-
137
-
138
-
139
-
140
- ## [2.11.3](https://github.com/midwayjs/midway/compare/v2.11.2...v2.11.3) (2021-07-02)
141
-
142
-
143
- ### Bug Fixes
144
-
145
- * **prometheus:** this.http_server may undefined onStop ([#1124](https://github.com/midwayjs/midway/issues/1124)) ([300a3ec](https://github.com/midwayjs/midway/commit/300a3ec9d308e4f32b7b266f41370dd920145e0b))
146
-
147
-
148
-
149
-
150
-
151
- ## [2.11.2](https://github.com/midwayjs/midway/compare/v2.11.1...v2.11.2) (2021-06-28)
152
-
153
- **Note:** Version bump only for package @midwayjs/prometheus
154
-
155
-
156
-
157
-
158
-
159
- ## [2.11.1](https://github.com/midwayjs/midway/compare/v2.11.0...v2.11.1) (2021-06-19)
160
-
161
- **Note:** Version bump only for package @midwayjs/prometheus
162
-
163
-
164
-
165
-
166
-
167
- # [2.11.0](https://github.com/midwayjs/midway/compare/v2.10.19...v2.11.0) (2021-06-10)
168
-
169
- **Note:** Version bump only for package @midwayjs/prometheus
170
-
171
-
172
-
173
-
174
-
175
- ## [2.10.18](https://github.com/midwayjs/midway/compare/v2.10.17...v2.10.18) (2021-05-26)
176
-
177
-
178
- ### Features
179
-
180
- * add zlib logger file ([#1038](https://github.com/midwayjs/midway/issues/1038)) ([2ae9131](https://github.com/midwayjs/midway/commit/2ae9131b8c8745d2840c40a5d50aa2d3f73bafbf))
181
-
182
-
183
-
184
-
185
-
186
- ## [2.10.16](https://github.com/midwayjs/midway/compare/v2.10.15...v2.10.16) (2021-05-17)
187
-
188
-
189
- ### Bug Fixes
190
-
191
- * **prometheus:** bootstrap for egg ([#1045](https://github.com/midwayjs/midway/issues/1045)) ([aeb0888](https://github.com/midwayjs/midway/commit/aeb0888930d35a3e13a139f30ce4c39710823cfa))
192
-
193
-
194
-
195
-
196
-
197
- ## [2.10.15](https://github.com/midwayjs/midway/compare/v2.10.14...v2.10.15) (2021-05-12)
198
-
199
-
200
- ### Features
201
-
202
- * prometheus qps rt ([#1039](https://github.com/midwayjs/midway/issues/1039)) ([398203e](https://github.com/midwayjs/midway/commit/398203e8f371e74a8c0aeff476c814e764e2b5df))
203
-
204
-
205
-
206
-
207
-
208
- ## [2.10.14](https://github.com/midwayjs/midway/compare/v2.10.13...v2.10.14) (2021-05-11)
209
-
210
- **Note:** Version bump only for package @midwayjs/prometheus
211
-
212
-
213
-
214
-
215
-
216
- ## [2.10.13](https://github.com/midwayjs/midway/compare/v2.10.12...v2.10.13) (2021-05-08)
217
-
218
- **Note:** Version bump only for package @midwayjs/prometheus
219
-
220
-
221
-
222
-
223
-
224
- ## [2.10.12](https://github.com/midwayjs/midway/compare/v2.10.11...v2.10.12) (2021-05-07)
225
-
226
- **Note:** Version bump only for package @midwayjs/prometheus
227
-
228
-
229
-
230
-
231
-
232
- ## [2.10.11](https://github.com/midwayjs/midway/compare/v2.10.10...v2.10.11) (2021-04-29)
233
-
234
- **Note:** Version bump only for package @midwayjs/prometheus
235
-
236
-
237
-
238
-
239
-
240
- ## [2.10.10](https://github.com/midwayjs/midway/compare/v2.10.9...v2.10.10) (2021-04-24)
241
-
242
- **Note:** Version bump only for package @midwayjs/prometheus
243
-
244
-
245
-
246
-
247
-
248
- ## [2.10.9](https://github.com/midwayjs/midway/compare/v2.10.8...v2.10.9) (2021-04-21)
249
-
250
- **Note:** Version bump only for package @midwayjs/prometheus
251
-
252
-
253
-
254
-
255
-
256
- ## [2.10.8](https://github.com/midwayjs/midway/compare/v2.10.7...v2.10.8) (2021-04-21)
257
-
258
- **Note:** Version bump only for package @midwayjs/prometheus
259
-
260
-
261
-
262
-
263
-
264
- ## [2.10.7](https://github.com/midwayjs/midway/compare/v2.10.6...v2.10.7) (2021-04-17)
265
-
266
-
267
- ### Bug Fixes
268
-
269
- * add event name args ([#986](https://github.com/midwayjs/midway/issues/986)) ([bfd8232](https://github.com/midwayjs/midway/commit/bfd82320aee8600d8fa30bd2821a0e68c80fd755))
270
- * format ([#997](https://github.com/midwayjs/midway/issues/997)) ([456cc14](https://github.com/midwayjs/midway/commit/456cc14513bdb000d1aa3130e9719caf7a8a803f))
271
-
272
-
273
-
274
-
275
-
276
- ## [2.10.6](https://github.com/midwayjs/midway/compare/v2.10.5...v2.10.6) (2021-04-14)
277
-
278
- **Note:** Version bump only for package @midwayjs/prometheus
279
-
280
-
281
-
282
-
283
-
284
- ## [2.10.5](https://github.com/midwayjs/midway/compare/v2.10.4...v2.10.5) (2021-04-13)
285
-
286
- **Note:** Version bump only for package @midwayjs/prometheus
287
-
288
-
289
-
290
-
291
-
292
- ## [2.10.4](https://github.com/midwayjs/midway/compare/v2.10.3...v2.10.4) (2021-04-10)
293
-
294
- **Note:** Version bump only for package @midwayjs/prometheus
295
-
296
-
297
-
298
-
299
-
300
- ## [2.10.3](https://github.com/midwayjs/midway/compare/v2.10.2...v2.10.3) (2021-04-07)
301
-
302
- **Note:** Version bump only for package @midwayjs/prometheus
303
-
304
-
305
-
306
-
307
-
308
- ## [2.10.2](https://github.com/midwayjs/midway/compare/v2.10.1...v2.10.2) (2021-04-05)
309
-
310
- **Note:** Version bump only for package @midwayjs/prometheus
311
-
312
-
313
-
314
-
315
-
316
- # [2.10.0](https://github.com/midwayjs/midway/compare/v2.9.3...v2.10.0) (2021-04-02)
317
-
318
-
319
- ### Features
320
-
321
- * support prometheus client ([#963](https://github.com/midwayjs/midway/issues/963)) ([b0edd42](https://github.com/midwayjs/midway/commit/b0edd428cbda986a472b8fa3055de1bdfb54b146))