@spinajs/metrics 2.0.180 → 2.0.182

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.
@@ -1,30 +1,30 @@
1
- /**
2
- *
3
- * Configuraiton for prom metrics bundle for express
4
- * https://github.com/jochen-schweizer/express-prom-bundle
5
- *
6
- */
7
- declare const config: {
8
- system: {
9
- dirs: {
10
- controllers: string[];
11
- };
12
- };
13
- metrics: {
14
- auth: {
15
- token: string;
16
- policy: string;
17
- };
18
- /**
19
- * * Configuraiton for prom metrics bundle for express
20
- * https://github.com/jochen-schweizer/express-prom-bundle
21
- */
22
- http: {
23
- includeStatusCode: boolean;
24
- includeMethod: boolean;
25
- includePath: boolean;
26
- };
27
- };
28
- };
29
- export default config;
1
+ /**
2
+ *
3
+ * Configuraiton for prom metrics bundle for express
4
+ * https://github.com/jochen-schweizer/express-prom-bundle
5
+ *
6
+ */
7
+ declare const config: {
8
+ system: {
9
+ dirs: {
10
+ controllers: string[];
11
+ };
12
+ };
13
+ metrics: {
14
+ auth: {
15
+ token: string;
16
+ policy: string;
17
+ };
18
+ /**
19
+ * * Configuraiton for prom metrics bundle for express
20
+ * https://github.com/jochen-schweizer/express-prom-bundle
21
+ */
22
+ http: {
23
+ includeStatusCode: boolean;
24
+ includeMethod: boolean;
25
+ includePath: boolean;
26
+ };
27
+ };
28
+ };
29
+ export default config;
30
30
  //# sourceMappingURL=metrics.d.ts.map
@@ -1,43 +1,43 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const path_1 = require("path");
4
- function dir(path) {
5
- const inCommonJs = typeof module !== 'undefined';
6
- return (0, path_1.resolve)((0, path_1.normalize)((0, path_1.join)(process.cwd(), 'node_modules', '@spinajs', 'metrics', 'lib', inCommonJs ? 'cjs' : 'mjs', path)));
7
- }
8
- /**
9
- *
10
- * Configuraiton for prom metrics bundle for express
11
- * https://github.com/jochen-schweizer/express-prom-bundle
12
- *
13
- */
14
- const config = {
15
- system: {
16
- dirs: {
17
- controllers: [dir('controllers')],
18
- },
19
- },
20
- metrics: {
21
- auth: {
22
- // set this in your project
23
- token: '',
24
- policy: 'DefaultMetricsPolicy',
25
- },
26
- /**
27
- * * Configuraiton for prom metrics bundle for express
28
- * https://github.com/jochen-schweizer/express-prom-bundle
29
- */
30
- http: {
31
- includeStatusCode: true,
32
- includeMethod: true,
33
- includePath: true,
34
- // customLabels: "spinajs",
35
- // includeUp: true,
36
- // metricsPath: "/metrics",
37
- // metricType: "histogram",
38
- // httpDurationMetricName: 60
39
- },
40
- },
41
- };
42
- exports.default = config;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const path_1 = require("path");
4
+ function dir(path) {
5
+ const inCommonJs = typeof module !== 'undefined';
6
+ return (0, path_1.resolve)((0, path_1.normalize)((0, path_1.join)(process.cwd(), 'node_modules', '@spinajs', 'metrics', 'lib', inCommonJs ? 'cjs' : 'mjs', path)));
7
+ }
8
+ /**
9
+ *
10
+ * Configuraiton for prom metrics bundle for express
11
+ * https://github.com/jochen-schweizer/express-prom-bundle
12
+ *
13
+ */
14
+ const config = {
15
+ system: {
16
+ dirs: {
17
+ controllers: [dir('controllers')],
18
+ },
19
+ },
20
+ metrics: {
21
+ auth: {
22
+ // set this in your project
23
+ token: '',
24
+ policy: 'DefaultMetricsPolicy',
25
+ },
26
+ /**
27
+ * * Configuraiton for prom metrics bundle for express
28
+ * https://github.com/jochen-schweizer/express-prom-bundle
29
+ */
30
+ http: {
31
+ includeStatusCode: true,
32
+ includeMethod: true,
33
+ includePath: true,
34
+ // customLabels: "spinajs",
35
+ // includeUp: true,
36
+ // metricsPath: "/metrics",
37
+ // metricType: "histogram",
38
+ // httpDurationMetricName: 60
39
+ },
40
+ },
41
+ };
42
+ exports.default = config;
43
43
  //# sourceMappingURL=metrics.js.map
@@ -1,15 +1,15 @@
1
- import { BaseController, Response } from '@spinajs/http';
2
- import * as express from 'express';
3
- declare class PrometheusResponse extends Response {
4
- constructor();
5
- execute(_req: express.Request, res: express.Response): Promise<void>;
6
- }
7
- /**
8
- * Default controller for serving
9
- * metrics data. Can be protected by access policy from configuration file
10
- */
11
- export declare class Metrics extends BaseController {
12
- getMetrics(): Promise<PrometheusResponse>;
13
- }
14
- export {};
1
+ import { BaseController, Response } from '@spinajs/http';
2
+ import * as express from 'express';
3
+ declare class PrometheusResponse extends Response {
4
+ constructor();
5
+ execute(_req: express.Request, res: express.Response): Promise<void>;
6
+ }
7
+ /**
8
+ * Default controller for serving
9
+ * metrics data. Can be protected by access policy from configuration file
10
+ */
11
+ export declare class Metrics extends BaseController {
12
+ getMetrics(): Promise<PrometheusResponse>;
13
+ }
14
+ export {};
15
15
  //# sourceMappingURL=metrics.d.ts.map
@@ -1,68 +1,68 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
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);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
- 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;
22
- return c > 3 && r && Object.defineProperty(target, key, r), r;
23
- };
24
- var __importStar = (this && this.__importStar) || function (mod) {
25
- if (mod && mod.__esModule) return mod;
26
- var result = {};
27
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
- __setModuleDefault(result, mod);
29
- return result;
30
- };
31
- var __metadata = (this && this.__metadata) || function (k, v) {
32
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
33
- };
34
- Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.Metrics = void 0;
36
- const http_1 = require("@spinajs/http");
37
- const client = __importStar(require("prom-client"));
38
- class PrometheusResponse extends http_1.Response {
39
- constructor() {
40
- super(null);
41
- }
42
- async execute(_req, res) {
43
- const result = await client.register.metrics();
44
- res.contentType(client.register.contentType);
45
- res.end(result);
46
- }
47
- }
48
- /**
49
- * Default controller for serving
50
- * metrics data. Can be protected by access policy from configuration file
51
- */
52
- let Metrics = class Metrics extends http_1.BaseController {
53
- async getMetrics() {
54
- return new PrometheusResponse();
55
- }
56
- };
57
- __decorate([
58
- (0, http_1.Get)('/'),
59
- __metadata("design:type", Function),
60
- __metadata("design:paramtypes", []),
61
- __metadata("design:returntype", Promise)
62
- ], Metrics.prototype, "getMetrics", null);
63
- Metrics = __decorate([
64
- (0, http_1.BasePath)('metrics'),
65
- (0, http_1.Policy)('metrics.auth.policy')
66
- ], Metrics);
67
- exports.Metrics = Metrics;
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
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);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ 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;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ };
24
+ var __importStar = (this && this.__importStar) || function (mod) {
25
+ if (mod && mod.__esModule) return mod;
26
+ var result = {};
27
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
+ __setModuleDefault(result, mod);
29
+ return result;
30
+ };
31
+ var __metadata = (this && this.__metadata) || function (k, v) {
32
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.Metrics = void 0;
36
+ const http_1 = require("@spinajs/http");
37
+ const client = __importStar(require("prom-client"));
38
+ class PrometheusResponse extends http_1.Response {
39
+ constructor() {
40
+ super(null);
41
+ }
42
+ async execute(_req, res) {
43
+ const result = await client.register.metrics();
44
+ res.contentType(client.register.contentType);
45
+ res.end(result);
46
+ }
47
+ }
48
+ /**
49
+ * Default controller for serving
50
+ * metrics data. Can be protected by access policy from configuration file
51
+ */
52
+ let Metrics = class Metrics extends http_1.BaseController {
53
+ async getMetrics() {
54
+ return new PrometheusResponse();
55
+ }
56
+ };
57
+ exports.Metrics = Metrics;
58
+ __decorate([
59
+ (0, http_1.Get)('/'),
60
+ __metadata("design:type", Function),
61
+ __metadata("design:paramtypes", []),
62
+ __metadata("design:returntype", Promise)
63
+ ], Metrics.prototype, "getMetrics", null);
64
+ exports.Metrics = Metrics = __decorate([
65
+ (0, http_1.BasePath)('metrics'),
66
+ (0, http_1.Policy)('metrics.auth.policy')
67
+ ], Metrics);
68
68
  //# sourceMappingURL=metrics.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../../src/controllers/metrics.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wCAAgF;AAChF,oDAAsC;AAGtC,MAAM,kBAAmB,SAAQ,eAAQ;IACvC;QACE,KAAK,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,IAAqB,EAAE,GAAqB;QAE/D,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;QAE/C,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;QAC7C,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAClB,CAAC;CACF;AAED;;;GAGG;AAGI,IAAM,OAAO,GAAb,MAAM,OAAQ,SAAQ,qBAAc;IAE5B,AAAN,KAAK,CAAC,UAAU;QACrB,OAAO,IAAI,kBAAkB,EAAE,CAAC;IAClC,CAAC;CACF,CAAA;AAHc;IADZ,IAAA,UAAG,EAAC,GAAG,CAAC;;;;yCAGR;AAJU,OAAO;IAFnB,IAAA,eAAQ,EAAC,SAAS,CAAC;IACnB,IAAA,aAAM,EAAC,qBAAqB,CAAC;GACjB,OAAO,CAKnB;AALY,0BAAO"}
1
+ {"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../../src/controllers/metrics.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wCAAgF;AAChF,oDAAsC;AAGtC,MAAM,kBAAmB,SAAQ,eAAQ;IACvC;QACE,KAAK,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,IAAqB,EAAE,GAAqB;QAE/D,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;QAE/C,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;QAC7C,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAClB,CAAC;CACF;AAED;;;GAGG;AAGI,IAAM,OAAO,GAAb,MAAM,OAAQ,SAAQ,qBAAc;IAE5B,AAAN,KAAK,CAAC,UAAU;QACrB,OAAO,IAAI,kBAAkB,EAAE,CAAC;IAClC,CAAC;CACF,CAAA;AALY,0BAAO;AAEL;IADZ,IAAA,UAAG,EAAC,GAAG,CAAC;;;;yCAGR;kBAJU,OAAO;IAFnB,IAAA,eAAQ,EAAC,SAAS,CAAC;IACnB,IAAA,aAAM,EAAC,qBAAqB,CAAC;GACjB,OAAO,CAKnB"}
@@ -1,26 +1,26 @@
1
- import { Bootstrapper } from '@spinajs/di';
2
- import * as client from 'prom-client';
3
- export * from "./policies/DefaultMetricsPolicy.js";
4
- export * from "./controllers/metrics.js";
5
- export declare const Gauge: typeof client.Gauge;
6
- export declare const Histogram: typeof client.Histogram;
7
- export declare const Summary: typeof client.Summary;
8
- export declare const Counter: typeof client.Counter;
9
- export declare class MetricsBootstrapper extends Bootstrapper {
10
- bootstrap(): void;
11
- }
12
- /**
13
- * Simple wrapper class for handling prom metrics
14
- */
15
- export declare class Metrics {
16
- protected _histograms: Map<string, client.Histogram>;
17
- protected _gauges: Map<string, client.Gauge>;
18
- protected _counters: Map<string, client.Counter>;
19
- protected _summaries: Map<string, client.Summary>;
20
- constructor();
21
- histogram<T extends string>(name: string, configuration: client.HistogramConfiguration<T>): client.Histogram<string>;
22
- gauge<T extends string>(name: string, configuration: client.GaugeConfiguration<T>): client.Gauge<string>;
23
- counter<T extends string>(name: string, configuration: client.CounterConfiguration<T>): client.Counter<string>;
24
- summary<T extends string>(name: string, configuration: client.SummaryConfiguration<T>): client.Summary<string>;
25
- }
1
+ import { Bootstrapper } from '@spinajs/di';
2
+ import * as client from 'prom-client';
3
+ export * from "./policies/DefaultMetricsPolicy.js";
4
+ export * from "./controllers/metrics.js";
5
+ export declare const Gauge: typeof client.Gauge;
6
+ export declare const Histogram: typeof client.Histogram;
7
+ export declare const Summary: typeof client.Summary;
8
+ export declare const Counter: typeof client.Counter;
9
+ export declare class MetricsBootstrapper extends Bootstrapper {
10
+ bootstrap(): void;
11
+ }
12
+ /**
13
+ * Simple wrapper class for handling prom metrics
14
+ */
15
+ export declare class Metrics {
16
+ protected _histograms: Map<string, client.Histogram>;
17
+ protected _gauges: Map<string, client.Gauge>;
18
+ protected _counters: Map<string, client.Counter>;
19
+ protected _summaries: Map<string, client.Summary>;
20
+ constructor();
21
+ histogram<T extends string>(name: string, configuration: client.HistogramConfiguration<T>): client.Histogram<string>;
22
+ gauge<T extends string>(name: string, configuration: client.GaugeConfiguration<T>): client.Gauge<string>;
23
+ counter<T extends string>(name: string, configuration: client.CounterConfiguration<T>): client.Counter<string>;
24
+ summary<T extends string>(name: string, configuration: client.SummaryConfiguration<T>): client.Summary<string>;
25
+ }
26
26
  //# sourceMappingURL=index.d.ts.map
package/lib/cjs/index.js CHANGED
@@ -1,106 +1,106 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
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);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
- 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;
22
- return c > 3 && r && Object.defineProperty(target, key, r), r;
23
- };
24
- var __importStar = (this && this.__importStar) || function (mod) {
25
- if (mod && mod.__esModule) return mod;
26
- var result = {};
27
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
- __setModuleDefault(result, mod);
29
- return result;
30
- };
31
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
32
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
33
- };
34
- var __importDefault = (this && this.__importDefault) || function (mod) {
35
- return (mod && mod.__esModule) ? mod : { "default": mod };
36
- };
37
- Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.Metrics = exports.MetricsBootstrapper = exports.Counter = exports.Summary = exports.Histogram = exports.Gauge = void 0;
39
- const di_1 = require("@spinajs/di");
40
- const client = __importStar(require("prom-client"));
41
- const express_prom_bundle_1 = __importDefault(require("express-prom-bundle"));
42
- const configuration_1 = require("@spinajs/configuration");
43
- __exportStar(require("./policies/DefaultMetricsPolicy.js"), exports);
44
- __exportStar(require("./controllers/metrics.js"), exports);
45
- exports.Gauge = client.Gauge;
46
- exports.Histogram = client.Histogram;
47
- exports.Summary = client.Summary;
48
- exports.Counter = client.Counter;
49
- let MetricsBootstrapper = class MetricsBootstrapper extends di_1.Bootstrapper {
50
- bootstrap() {
51
- client.collectDefaultMetrics({
52
- labels: { NODE_APP_INSTANCE: process.env.NODE_APP_INSTANCE },
53
- });
54
- di_1.DI.on('di.resolved.HttpServer', (_, server) => {
55
- const cfg = _.get(configuration_1.Configuration);
56
- const promCfg = cfg.get('metrics.http');
57
- server.use((0, express_prom_bundle_1.default)({
58
- ...promCfg,
59
- // disable default autoregister
60
- // we do this by controller with proper auth handling
61
- autoregister: false,
62
- }));
63
- });
64
- }
65
- };
66
- MetricsBootstrapper = __decorate([
67
- (0, di_1.Injectable)(di_1.Bootstrapper)
68
- ], MetricsBootstrapper);
69
- exports.MetricsBootstrapper = MetricsBootstrapper;
70
- /**
71
- * Simple wrapper class for handling prom metrics
72
- */
73
- class Metrics {
74
- constructor() {
75
- this._histograms = new Map();
76
- this._gauges = new Map();
77
- this._counters = new Map();
78
- this._summaries = new Map();
79
- }
80
- histogram(name, configuration) {
81
- if (!this._histograms.has(name)) {
82
- this._histograms.set(name, new client.Histogram(configuration));
83
- }
84
- return this._histograms.get(name);
85
- }
86
- gauge(name, configuration) {
87
- if (!this._gauges.has(name)) {
88
- this._gauges.set(name, new client.Gauge(configuration));
89
- }
90
- return this._gauges.get(name);
91
- }
92
- counter(name, configuration) {
93
- if (!this._counters.has(name)) {
94
- this._counters.set(name, new client.Gauge(configuration));
95
- }
96
- return this._counters.get(name);
97
- }
98
- summary(name, configuration) {
99
- if (!this._summaries.has(name)) {
100
- this._summaries.set(name, new client.Summary(configuration));
101
- }
102
- return this._summaries.get(name);
103
- }
104
- }
105
- exports.Metrics = Metrics;
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
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);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ 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;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ };
24
+ var __importStar = (this && this.__importStar) || function (mod) {
25
+ if (mod && mod.__esModule) return mod;
26
+ var result = {};
27
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
+ __setModuleDefault(result, mod);
29
+ return result;
30
+ };
31
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
32
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.Metrics = exports.MetricsBootstrapper = exports.Counter = exports.Summary = exports.Histogram = exports.Gauge = void 0;
39
+ const di_1 = require("@spinajs/di");
40
+ const client = __importStar(require("prom-client"));
41
+ const express_prom_bundle_1 = __importDefault(require("express-prom-bundle"));
42
+ const configuration_1 = require("@spinajs/configuration");
43
+ __exportStar(require("./policies/DefaultMetricsPolicy.js"), exports);
44
+ __exportStar(require("./controllers/metrics.js"), exports);
45
+ exports.Gauge = client.Gauge;
46
+ exports.Histogram = client.Histogram;
47
+ exports.Summary = client.Summary;
48
+ exports.Counter = client.Counter;
49
+ let MetricsBootstrapper = class MetricsBootstrapper extends di_1.Bootstrapper {
50
+ bootstrap() {
51
+ client.collectDefaultMetrics({
52
+ labels: { NODE_APP_INSTANCE: process.env.NODE_APP_INSTANCE },
53
+ });
54
+ di_1.DI.on('di.resolved.HttpServer', (_, server) => {
55
+ const cfg = _.get(configuration_1.Configuration);
56
+ const promCfg = cfg.get('metrics.http');
57
+ server.use((0, express_prom_bundle_1.default)({
58
+ ...promCfg,
59
+ // disable default autoregister
60
+ // we do this by controller with proper auth handling
61
+ autoregister: false,
62
+ }));
63
+ });
64
+ }
65
+ };
66
+ exports.MetricsBootstrapper = MetricsBootstrapper;
67
+ exports.MetricsBootstrapper = MetricsBootstrapper = __decorate([
68
+ (0, di_1.Injectable)(di_1.Bootstrapper)
69
+ ], MetricsBootstrapper);
70
+ /**
71
+ * Simple wrapper class for handling prom metrics
72
+ */
73
+ class Metrics {
74
+ constructor() {
75
+ this._histograms = new Map();
76
+ this._gauges = new Map();
77
+ this._counters = new Map();
78
+ this._summaries = new Map();
79
+ }
80
+ histogram(name, configuration) {
81
+ if (!this._histograms.has(name)) {
82
+ this._histograms.set(name, new client.Histogram(configuration));
83
+ }
84
+ return this._histograms.get(name);
85
+ }
86
+ gauge(name, configuration) {
87
+ if (!this._gauges.has(name)) {
88
+ this._gauges.set(name, new client.Gauge(configuration));
89
+ }
90
+ return this._gauges.get(name);
91
+ }
92
+ counter(name, configuration) {
93
+ if (!this._counters.has(name)) {
94
+ this._counters.set(name, new client.Gauge(configuration));
95
+ }
96
+ return this._counters.get(name);
97
+ }
98
+ summary(name, configuration) {
99
+ if (!this._summaries.has(name)) {
100
+ this._summaries.set(name, new client.Summary(configuration));
101
+ }
102
+ return this._summaries.get(name);
103
+ }
104
+ }
105
+ exports.Metrics = Metrics;
106
106
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":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E;YAC9B,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;SAC9D;QAED,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;CACF;AA5CD,0BA4CC"}
@@ -1,11 +1,11 @@
1
- import { BasePolicy, IController, IRoute, Request } from '@spinajs/http';
2
- import { Log } from '@spinajs/log';
3
- export declare class DefaultMetricsPolicy extends BasePolicy {
4
- protected Log: Log;
5
- protected Token: string;
6
- protected HEADER_TOKEN_FIELD: string;
7
- protected isDev: boolean;
8
- isEnabled(_action: IRoute, _instance: IController): boolean;
9
- execute(req: Request): Promise<void>;
10
- }
1
+ import { BasePolicy, IController, IRoute, Request } from '@spinajs/http';
2
+ import { Log } from '@spinajs/log';
3
+ export declare class DefaultMetricsPolicy extends BasePolicy {
4
+ protected Log: Log;
5
+ protected Token: string;
6
+ protected HEADER_TOKEN_FIELD: string;
7
+ protected isDev: boolean;
8
+ isEnabled(_action: IRoute, _instance: IController): boolean;
9
+ execute(req: Request): Promise<void>;
10
+ }
11
11
  //# sourceMappingURL=DefaultMetricsPolicy.d.ts.map