@axinom/mosaic-service-common 0.56.0-rc.4 → 0.56.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/dist/middleware/monitoring-middleware.d.ts +6 -0
- package/dist/middleware/monitoring-middleware.d.ts.map +1 -1
- package/dist/middleware/monitoring-middleware.js +16 -10
- package/dist/middleware/monitoring-middleware.js.map +1 -1
- package/package.json +2 -2
- package/src/middleware/monitoring-middleware.ts +26 -15
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Metric, Registry } from 'prom-client';
|
|
2
2
|
import { BasicConfig, BasicMetricsConfig, Logger } from '../common';
|
|
3
|
+
import express = require('express');
|
|
3
4
|
/**
|
|
4
5
|
* Options used to set up monitoring middleware.
|
|
5
6
|
*/
|
|
@@ -20,6 +21,11 @@ export interface IMonitoringOptions {
|
|
|
20
21
|
* `metrics`: an array of Metrics to be added to the Registry for metric collection.
|
|
21
22
|
*/
|
|
22
23
|
metrics?: Metric<string>[];
|
|
24
|
+
/**
|
|
25
|
+
* `expressApp`: an express application where the monitoring middleware will be mounted on.
|
|
26
|
+
* if not specified, a new express app will be created listening on the `METRICS_ENDPOINT_PORT` port.
|
|
27
|
+
*/
|
|
28
|
+
expressApp?: express.Application;
|
|
23
29
|
}
|
|
24
30
|
/**
|
|
25
31
|
* Setup a prometheus metric monitoring endpoint using an express application.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"monitoring-middleware.d.ts","sourceRoot":"","sources":["../../src/middleware/monitoring-middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAyB,MAAM,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EACL,WAAW,EACX,kBAAkB,EAElB,MAAM,EACP,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"monitoring-middleware.d.ts","sourceRoot":"","sources":["../../src/middleware/monitoring-middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAyB,MAAM,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EACL,WAAW,EACX,kBAAkB,EAElB,MAAM,EACP,MAAM,WAAW,CAAC;AAEnB,OAAO,OAAO,GAAG,QAAQ,SAAS,CAAC,CAAC;AAEpC;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,cAAc,CAAC,EAAE,QAAQ,CAAC;IAC1B;;OAEG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;IAE3B;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC;CAClC;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,WAClB,WAAW,GAAG,kBAAkB,sBACrB,kBAAkB,WAC5B,MAAM,KACd,QAoGF,CAAC"}
|
|
@@ -17,8 +17,7 @@ const express = require("express");
|
|
|
17
17
|
*/
|
|
18
18
|
const setupMonitoring = (config, monitoringOptions = {}, logger) => {
|
|
19
19
|
const localLogger = logger !== null && logger !== void 0 ? logger : new common_1.Logger({ context: exports.setupMonitoring.name });
|
|
20
|
-
const options = Object.assign({ metricsPath: '/metrics', metricRegistry: new prom_client_1.Registry(), collectDefaultMetrics: true, metrics: [] }, monitoringOptions);
|
|
21
|
-
const app = express().use(mosaic_favicon_1.mosaicFavicon);
|
|
20
|
+
const options = Object.assign({ metricsPath: '/metrics', metricRegistry: new prom_client_1.Registry(), collectDefaultMetrics: true, metrics: [], expressApp: express().use(mosaic_favicon_1.mosaicFavicon) }, monitoringOptions);
|
|
22
21
|
options.metricRegistry.setDefaultLabels({
|
|
23
22
|
serviceId: config.serviceId,
|
|
24
23
|
environment: config.environment,
|
|
@@ -68,16 +67,23 @@ const setupMonitoring = (config, monitoringOptions = {}, logger) => {
|
|
|
68
67
|
if (options.collectDefaultMetrics) {
|
|
69
68
|
(0, prom_client_1.collectDefaultMetrics)({ register: options.metricRegistry });
|
|
70
69
|
}
|
|
71
|
-
|
|
72
|
-
const
|
|
70
|
+
if (monitoringOptions.expressApp === undefined) {
|
|
71
|
+
const server = options.expressApp.listen(config.isDev ? 0 : config.metricsEndpointPort, () => {
|
|
72
|
+
const port = server.address().port;
|
|
73
|
+
localLogger.debug({
|
|
74
|
+
message: `🩻 Metrics app started`,
|
|
75
|
+
details: {
|
|
76
|
+
metrics: `http://localhost:${port}${options.metricsPath}`,
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
73
82
|
localLogger.debug({
|
|
74
|
-
message: `🩻 Metrics
|
|
75
|
-
details: {
|
|
76
|
-
metrics: `http://localhost:${port}${options.metricsPath}`,
|
|
77
|
-
},
|
|
83
|
+
message: `🩻 Metrics endpoint mounted at ${options.metricsPath}`,
|
|
78
84
|
});
|
|
79
|
-
}
|
|
80
|
-
|
|
85
|
+
}
|
|
86
|
+
options.expressApp.use(options.metricsPath, async (_req, res) => {
|
|
81
87
|
try {
|
|
82
88
|
res.setHeader('content-type', options.metricRegistry.contentType);
|
|
83
89
|
res.send(await options.metricRegistry.metrics());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"monitoring-middleware.js","sourceRoot":"","sources":["../../src/middleware/monitoring-middleware.ts"],"names":[],"mappings":";;;AACA,6CAAsE;AACtE,sCAKmB;AACnB,qDAAiD;AACjD,mCAAoC;
|
|
1
|
+
{"version":3,"file":"monitoring-middleware.js","sourceRoot":"","sources":["../../src/middleware/monitoring-middleware.ts"],"names":[],"mappings":";;;AACA,6CAAsE;AACtE,sCAKmB;AACnB,qDAAiD;AACjD,mCAAoC;AA8BpC;;;;;;;;;GASG;AACI,MAAM,eAAe,GAAG,CAC7B,MAAwC,EACxC,oBAAwC,EAAE,EAC1C,MAAe,EACL,EAAE;IACZ,MAAM,WAAW,GAAG,MA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AC,OAAO,CAAC,EAAE;YACV,GAAG,CAAC,IAAI,CACN,0EAA0E,MAAM,CAAC,SAAS,qBAAqB,CAChH,CAAC;YACF,MAAM,KAAK,GAAG,IAAA,oBAAW,EAAC,CAAC,CAAC,CAAC;YAC7B,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;SAC1B;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC,cAAc,CAAC;AAChC,CAAC,CAAC;AAxGW,QAAA,eAAe,mBAwG1B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axinom/mosaic-service-common",
|
|
3
|
-
"version": "0.56.0
|
|
3
|
+
"version": "0.56.0",
|
|
4
4
|
"description": "Common helpers and PostgreSQL-related functionality",
|
|
5
5
|
"author": "Axinom",
|
|
6
6
|
"license": "PROPRIETARY",
|
|
@@ -69,5 +69,5 @@
|
|
|
69
69
|
"publishConfig": {
|
|
70
70
|
"access": "public"
|
|
71
71
|
},
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "27e15aea3d17354183d6ef30855c1293f861fc35"
|
|
73
73
|
}
|
|
@@ -29,6 +29,12 @@ export interface IMonitoringOptions {
|
|
|
29
29
|
* `metrics`: an array of Metrics to be added to the Registry for metric collection.
|
|
30
30
|
*/
|
|
31
31
|
metrics?: Metric<string>[];
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* `expressApp`: an express application where the monitoring middleware will be mounted on.
|
|
35
|
+
* if not specified, a new express app will be created listening on the `METRICS_ENDPOINT_PORT` port.
|
|
36
|
+
*/
|
|
37
|
+
expressApp?: express.Application;
|
|
32
38
|
}
|
|
33
39
|
|
|
34
40
|
/**
|
|
@@ -52,11 +58,10 @@ export const setupMonitoring = (
|
|
|
52
58
|
metricRegistry: new Registry(),
|
|
53
59
|
collectDefaultMetrics: true,
|
|
54
60
|
metrics: [],
|
|
61
|
+
expressApp: express().use(mosaicFavicon),
|
|
55
62
|
...monitoringOptions,
|
|
56
63
|
};
|
|
57
64
|
|
|
58
|
-
const app = express().use(mosaicFavicon);
|
|
59
|
-
|
|
60
65
|
options.metricRegistry.setDefaultLabels({
|
|
61
66
|
serviceId: config.serviceId,
|
|
62
67
|
environment: config.environment,
|
|
@@ -112,21 +117,27 @@ export const setupMonitoring = (
|
|
|
112
117
|
collectDefaultMetrics({ register: options.metricRegistry });
|
|
113
118
|
}
|
|
114
119
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
120
|
+
if (monitoringOptions.expressApp === undefined) {
|
|
121
|
+
const server = options.expressApp.listen(
|
|
122
|
+
config.isDev ? 0 : config.metricsEndpointPort,
|
|
123
|
+
() => {
|
|
124
|
+
const port = (server.address() as AddressInfo).port;
|
|
119
125
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
126
|
+
localLogger.debug({
|
|
127
|
+
message: `🩻 Metrics app started`,
|
|
128
|
+
details: {
|
|
129
|
+
metrics: `http://localhost:${port}${options.metricsPath}`,
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
},
|
|
133
|
+
);
|
|
134
|
+
} else {
|
|
135
|
+
localLogger.debug({
|
|
136
|
+
message: `🩻 Metrics endpoint mounted at ${options.metricsPath}`,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
128
139
|
|
|
129
|
-
|
|
140
|
+
options.expressApp.use(options.metricsPath, async (_req, res) => {
|
|
130
141
|
try {
|
|
131
142
|
res.setHeader('content-type', options.metricRegistry.contentType);
|
|
132
143
|
res.send(await options.metricRegistry.metrics());
|