@k03mad/simple-prom 10.1.1 → 11.0.1
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/.editorconfig +1 -4
- package/.github/dependabot.yml +2 -2
- package/.oxfmtrc.json +18 -0
- package/.oxlintrc.json +7 -0
- package/.vscode/settings.json +3 -0
- package/app/lib/register.js +19 -23
- package/app/lib/server.js +17 -6
- package/package.json +12 -11
- package/eslint.config.js +0 -1
package/.editorconfig
CHANGED
package/.github/dependabot.yml
CHANGED
package/.oxfmtrc.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "./node_modules/oxfmt/configuration_schema.json",
|
|
3
|
+
"ignorePatterns": ["node_modules/**"],
|
|
4
|
+
"singleQuote": true,
|
|
5
|
+
"arrowParens": "avoid",
|
|
6
|
+
"bracketSpacing": false,
|
|
7
|
+
"quoteProps": "consistent",
|
|
8
|
+
"experimentalSortImports": {
|
|
9
|
+
"groups": [
|
|
10
|
+
["builtin"],
|
|
11
|
+
["external", "type-external"],
|
|
12
|
+
["internal", "type-internal"],
|
|
13
|
+
["parent", "type-parent"],
|
|
14
|
+
["sibling", "type-sibling"],
|
|
15
|
+
["index", "type-index"]
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
}
|
package/.oxlintrc.json
ADDED
package/app/lib/register.js
CHANGED
|
@@ -12,10 +12,8 @@ import client from 'prom-client';
|
|
|
12
12
|
export const registerMetrics = ({appName, port, metrics, metricsTurnOff = []}) => {
|
|
13
13
|
const filteredMetrics = metrics
|
|
14
14
|
? Object.fromEntries(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
),
|
|
18
|
-
)
|
|
15
|
+
Object.entries(metrics).filter(([key]) => !metricsTurnOff.includes(key)),
|
|
16
|
+
)
|
|
19
17
|
: {};
|
|
20
18
|
|
|
21
19
|
const register = new client.Registry();
|
|
@@ -23,26 +21,24 @@ export const registerMetrics = ({appName, port, metrics, metricsTurnOff = []}) =
|
|
|
23
21
|
client.collectDefaultMetrics({register});
|
|
24
22
|
register.setDefaultLabels({app: appName, port, host: os.hostname});
|
|
25
23
|
|
|
26
|
-
Object
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
register.registerMetric(gauge);
|
|
24
|
+
Object.values(filteredMetrics).forEach(metric => {
|
|
25
|
+
const {collect, name, ...rest} = metric;
|
|
26
|
+
|
|
27
|
+
const gauge = new client.Gauge({
|
|
28
|
+
name,
|
|
29
|
+
...rest,
|
|
30
|
+
async collect() {
|
|
31
|
+
try {
|
|
32
|
+
await collect(this);
|
|
33
|
+
} catch (err) {
|
|
34
|
+
console.error(`>> ${name}`);
|
|
35
|
+
console.error(err);
|
|
36
|
+
}
|
|
37
|
+
},
|
|
45
38
|
});
|
|
46
39
|
|
|
40
|
+
register.registerMetric(gauge);
|
|
41
|
+
});
|
|
42
|
+
|
|
47
43
|
return register;
|
|
48
44
|
};
|
package/app/lib/server.js
CHANGED
|
@@ -16,7 +16,14 @@ import {registerMetrics} from './register.js';
|
|
|
16
16
|
* @param {boolean} opts.debug
|
|
17
17
|
* @param {string} opts.static
|
|
18
18
|
*/
|
|
19
|
-
export const startMetricsServer = ({
|
|
19
|
+
export const startMetricsServer = ({
|
|
20
|
+
appName,
|
|
21
|
+
port,
|
|
22
|
+
metrics,
|
|
23
|
+
metricsTurnOff,
|
|
24
|
+
debug,
|
|
25
|
+
static: staticOpts,
|
|
26
|
+
}) => {
|
|
20
27
|
const register = registerMetrics({appName, port, metrics, metricsTurnOff});
|
|
21
28
|
|
|
22
29
|
const app = express();
|
|
@@ -44,9 +51,13 @@ export const startMetricsServer = ({appName, port, metrics, metricsTurnOff, debu
|
|
|
44
51
|
res.send(data);
|
|
45
52
|
});
|
|
46
53
|
|
|
47
|
-
app.listen(port, () =>
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
54
|
+
app.listen(port, () =>
|
|
55
|
+
console.log(
|
|
56
|
+
[
|
|
57
|
+
`[${String(new Date())}]\n${nameText(appName)}`,
|
|
58
|
+
'started on port',
|
|
59
|
+
numText(port),
|
|
60
|
+
].join(' '),
|
|
61
|
+
),
|
|
62
|
+
);
|
|
52
63
|
};
|
package/package.json
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@k03mad/simple-prom",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.0.1",
|
|
4
4
|
"description": "Simple prom-client library",
|
|
5
|
+
"license": "MIT",
|
|
5
6
|
"maintainers": [
|
|
6
7
|
"Kirill Molchanov <k03.mad@gmail.com"
|
|
7
8
|
],
|
|
8
|
-
"main": "app/index.js",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "git+https://github.com/k03mad/simple-prom.git"
|
|
12
12
|
},
|
|
13
|
-
"license": "MIT",
|
|
14
13
|
"type": "module",
|
|
15
|
-
"
|
|
16
|
-
|
|
14
|
+
"main": "app/index.js",
|
|
15
|
+
"scripts": {
|
|
16
|
+
"lint": "oxlint --report-unused-disable-directives && oxfmt --check",
|
|
17
|
+
"prepare": "husky || true"
|
|
17
18
|
},
|
|
18
19
|
"dependencies": {
|
|
19
20
|
"chalk": "5.6.2",
|
|
@@ -24,12 +25,12 @@
|
|
|
24
25
|
"prom-client": "15.1.3"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
|
-
"@k03mad/
|
|
28
|
-
"
|
|
29
|
-
"
|
|
28
|
+
"@k03mad/oxlint-config": "0.0.10",
|
|
29
|
+
"husky": "9.1.7",
|
|
30
|
+
"oxfmt": "0.34.0",
|
|
31
|
+
"oxlint": "1.49.0"
|
|
30
32
|
},
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"prepare": "husky || true"
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=24"
|
|
34
35
|
}
|
|
35
36
|
}
|
package/eslint.config.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {default} from '@k03mad/eslint-config';
|