@k03mad/simple-prom 1.1.0 → 2.0.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/app/helpers/colors.js +4 -0
- package/app/lib/register.js +3 -3
- package/app/lib/server.js +42 -0
- package/package.json +7 -1
package/app/lib/register.js
CHANGED
|
@@ -5,15 +5,15 @@ import client from 'prom-client';
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @param {object} opts
|
|
8
|
-
* @param {string} opts.
|
|
8
|
+
* @param {string} opts.appName
|
|
9
9
|
* @param {string|number} opts.port
|
|
10
10
|
* @param {object} opts.metrics
|
|
11
11
|
*/
|
|
12
|
-
export const registerMetrics = ({
|
|
12
|
+
export const registerMetrics = ({appName, port, metrics}) => {
|
|
13
13
|
const register = new client.Registry();
|
|
14
14
|
|
|
15
15
|
client.collectDefaultMetrics({register});
|
|
16
|
-
register.setDefaultLabels({app, port, host: os.hostname});
|
|
16
|
+
register.setDefaultLabels({app: appName, port, host: os.hostname});
|
|
17
17
|
|
|
18
18
|
Object
|
|
19
19
|
.values(metrics)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {getDateYMDHMS} from '@k03mad/simple-date';
|
|
2
|
+
import {log} from '@k03mad/simple-log';
|
|
3
|
+
import compression from 'compression';
|
|
4
|
+
import express from 'express';
|
|
5
|
+
import helmet from 'helmet';
|
|
6
|
+
import morgan from 'morgan';
|
|
7
|
+
|
|
8
|
+
import {nameText, numText} from '../helpers/colors.js';
|
|
9
|
+
|
|
10
|
+
import {registerMetrics} from './register.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {object} opts
|
|
14
|
+
* @param {string} opts.appName
|
|
15
|
+
* @param {string|number} opts.port
|
|
16
|
+
* @param {object} opts.metrics
|
|
17
|
+
* @param {boolean} opts.debug
|
|
18
|
+
*/
|
|
19
|
+
export const startMetricsServer = ({appName, port, metrics, debug}) => {
|
|
20
|
+
const register = registerMetrics({appName, port, metrics});
|
|
21
|
+
|
|
22
|
+
const app = express();
|
|
23
|
+
|
|
24
|
+
if (debug) {
|
|
25
|
+
app.use(morgan('combined'));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
app.use(helmet());
|
|
29
|
+
app.use(compression());
|
|
30
|
+
|
|
31
|
+
app.get('/metrics', async (req, res) => {
|
|
32
|
+
const data = await register.metrics();
|
|
33
|
+
res.send(data);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
app.listen(port, () => log([
|
|
37
|
+
`[${getDateYMDHMS()}]`,
|
|
38
|
+
nameText(appName),
|
|
39
|
+
'started on port',
|
|
40
|
+
numText(port),
|
|
41
|
+
].join(' ')));
|
|
42
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@k03mad/simple-prom",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Simple prom-client library",
|
|
5
5
|
"maintainers": [
|
|
6
6
|
"Kirill Molchanov <k03.mad@gmail.com"
|
|
@@ -16,7 +16,13 @@
|
|
|
16
16
|
"node": ">=20"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
+
"@k03mad/simple-date": "1.0.0",
|
|
19
20
|
"@k03mad/simple-log": "2.1.0",
|
|
21
|
+
"chalk": "5.3.0",
|
|
22
|
+
"compression": "1.7.4",
|
|
23
|
+
"express": "4.18.2",
|
|
24
|
+
"helmet": "7.1.0",
|
|
25
|
+
"morgan": "1.10.0",
|
|
20
26
|
"prom-client": "15.1.0"
|
|
21
27
|
},
|
|
22
28
|
"devDependencies": {
|