axios-prometheus-adapter 0.0.6 → 0.0.8
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/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AxiosPrometheusAdapterConfig, createAxiosPrometheusMiddleware } from './lib/AxiosPrometheusAdapter';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAxiosPrometheusMiddleware = void 0;
|
|
4
|
+
var AxiosPrometheusAdapter_1 = require("./lib/AxiosPrometheusAdapter");
|
|
5
|
+
Object.defineProperty(exports, "createAxiosPrometheusMiddleware", { enumerable: true, get: function () { return AxiosPrometheusAdapter_1.createAxiosPrometheusMiddleware; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,uEAA6G;AAAtE,yIAAA,+BAA+B,OAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AxiosInstance } from 'axios';
|
|
2
|
+
import type { Registry } from 'prom-client';
|
|
3
|
+
export type AxiosPrometheusAdapterConfig = {
|
|
4
|
+
name: string;
|
|
5
|
+
help: string;
|
|
6
|
+
labelNames: string[];
|
|
7
|
+
};
|
|
8
|
+
export declare const createAxiosPrometheusMiddleware: (axiosInstance: AxiosInstance, registry: Registry, config?: AxiosPrometheusAdapterConfig) => void;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createAxiosPrometheusMiddleware = void 0;
|
|
7
|
+
const prom_client_1 = __importDefault(require("prom-client"));
|
|
8
|
+
// Path normalizer to prevent unbounded cardinality in metrics
|
|
9
|
+
// Replaces dynamic segments (numbers, UUIDs, etc.) with placeholders
|
|
10
|
+
const normalizePath = (path) => {
|
|
11
|
+
return path
|
|
12
|
+
// Replace UUIDs (8-4-4-4-12 format)
|
|
13
|
+
.replace(/\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi, '/:uuid')
|
|
14
|
+
// Replace any numeric IDs in paths
|
|
15
|
+
.replace(/\/[0-9]+(?=\/|$)/g, '/:id');
|
|
16
|
+
};
|
|
17
|
+
const createAxiosPrometheusMiddleware = (axiosInstance, registry, config) => {
|
|
18
|
+
const clientRequestDuration = new prom_client_1.default.Histogram({
|
|
19
|
+
name: 'http_client_requests_seconds',
|
|
20
|
+
help: 'Outgoing requests metrics',
|
|
21
|
+
labelNames: ['status_code', 'method', 'protocol', 'host', 'path'],
|
|
22
|
+
...config,
|
|
23
|
+
});
|
|
24
|
+
registry.registerMetric(clientRequestDuration);
|
|
25
|
+
axiosInstance.interceptors.request.use((config) => {
|
|
26
|
+
const end = clientRequestDuration.startTimer();
|
|
27
|
+
config.metadata = {
|
|
28
|
+
endTimer: end,
|
|
29
|
+
};
|
|
30
|
+
return config;
|
|
31
|
+
});
|
|
32
|
+
// eslint-disable-next-line complexity
|
|
33
|
+
axiosInstance.interceptors.response.use((response) => {
|
|
34
|
+
var _a, _b;
|
|
35
|
+
const labels = {
|
|
36
|
+
status_code: response.status.toString(),
|
|
37
|
+
method: response.request.method || ((_a = response.config.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || 'UNKNOWN',
|
|
38
|
+
protocol: response.request.protocol || 'https:',
|
|
39
|
+
host: response.request.host || new URL(response.config.url || '').hostname,
|
|
40
|
+
path: normalizePath((_b = response.request.path) === null || _b === void 0 ? void 0 : _b.split('?')[0]),
|
|
41
|
+
};
|
|
42
|
+
response.config.metadata.endTimer(labels);
|
|
43
|
+
return response;
|
|
44
|
+
}, error => {
|
|
45
|
+
let labels;
|
|
46
|
+
if (error.response) {
|
|
47
|
+
labels = {
|
|
48
|
+
status_code: error.response.status.toString(),
|
|
49
|
+
method: error.response.request.method,
|
|
50
|
+
protocol: error.response.request.protocol,
|
|
51
|
+
host: error.response.request.host,
|
|
52
|
+
path: normalizePath(error.response.request.path.split('?')[0]),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
else if (error.request._currentRequest) {
|
|
56
|
+
labels = {
|
|
57
|
+
status_code: error.status.toString(),
|
|
58
|
+
method: error.request._currentRequest.method,
|
|
59
|
+
protocol: error.request._currentRequest.protocol,
|
|
60
|
+
host: error.request._currentRequest.host,
|
|
61
|
+
path: normalizePath(error.request._currentRequest.path.split('?')[0]),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
labels = {
|
|
66
|
+
status_code: 500,
|
|
67
|
+
method: 'UNKNOWN',
|
|
68
|
+
protocol: 'UNKNOWN',
|
|
69
|
+
host: 'UNKNOWN',
|
|
70
|
+
path: 'UNKNOWN',
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
error.config.metadata.endTimer(labels);
|
|
74
|
+
return Promise.reject(error);
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
exports.createAxiosPrometheusMiddleware = createAxiosPrometheusMiddleware;
|
|
78
|
+
//# sourceMappingURL=AxiosPrometheusAdapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AxiosPrometheusAdapter.js","sourceRoot":"","sources":["../../lib/AxiosPrometheusAdapter.ts"],"names":[],"mappings":";;;;;;AAEA,8DAAiC;AAEjC,8DAA8D;AAC9D,qEAAqE;AACrE,MAAM,aAAa,GAAG,CAAC,IAAY,EAAU,EAAE;IAC7C,OAAO,IAAI;QACT,oCAAoC;SACnC,OAAO,CAAC,kEAAkE,EAAE,QAAQ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G;gBAChB,MAAM,EAAE,SAAS;gBACjB,QAAQ,EAAE,SAAS;gBACnB,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE,SAAS;aAChB,CAAC;SACH;QACD,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACvC,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAhEW,QAAA,+BAA+B,mCAgE1C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "axios-prometheus-adapter",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "Provides prometheus metrics for outgoing axios requests",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
],
|
|
12
12
|
"scripts": {
|
|
13
13
|
"build": "tsc -p tsconfig.prod.json",
|
|
14
|
-
"start": "ts-node-dev examples/
|
|
14
|
+
"start": "ts-node-dev examples/axiosRequest.ts",
|
|
15
15
|
"test": "jest"
|
|
16
16
|
},
|
|
17
17
|
"repository": {
|
package/readme.md
CHANGED
|
@@ -63,34 +63,20 @@ Output:
|
|
|
63
63
|
...
|
|
64
64
|
# HELP http_client_requests_seconds_count http_client_requests_seconds_count
|
|
65
65
|
# TYPE http_client_requests_seconds_count histogram
|
|
66
|
-
http_client_requests_seconds_bucket{le="0.005",status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts
|
|
67
|
-
http_client_requests_seconds_bucket{le="0.01",status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts
|
|
68
|
-
http_client_requests_seconds_bucket{le="0.025",status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts
|
|
69
|
-
http_client_requests_seconds_bucket{le="0.05",status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts
|
|
70
|
-
http_client_requests_seconds_bucket{le="0.1",status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts
|
|
71
|
-
http_client_requests_seconds_bucket{le="0.25",status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts
|
|
72
|
-
http_client_requests_seconds_bucket{le="0.5",status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts
|
|
73
|
-
http_client_requests_seconds_bucket{le="1",status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts
|
|
74
|
-
http_client_requests_seconds_bucket{le="2.5",status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts
|
|
75
|
-
http_client_requests_seconds_bucket{le="5",status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts
|
|
76
|
-
http_client_requests_seconds_bucket{le="10",status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts
|
|
77
|
-
http_client_requests_seconds_bucket{le="+Inf",status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts
|
|
78
|
-
http_client_requests_seconds_sum{status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts
|
|
79
|
-
http_client_requests_seconds_count{status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts
|
|
80
|
-
http_client_requests_seconds_bucket{le="0.005",status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts/2"} 0
|
|
81
|
-
http_client_requests_seconds_bucket{le="0.01",status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts/2"} 0
|
|
82
|
-
http_client_requests_seconds_bucket{le="0.025",status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts/2"} 0
|
|
83
|
-
http_client_requests_seconds_bucket{le="0.05",status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts/2"} 0
|
|
84
|
-
http_client_requests_seconds_bucket{le="0.1",status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts/2"} 0
|
|
85
|
-
http_client_requests_seconds_bucket{le="0.25",status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts/2"} 1
|
|
86
|
-
http_client_requests_seconds_bucket{le="0.5",status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts/2"} 1
|
|
87
|
-
http_client_requests_seconds_bucket{le="1",status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts/2"} 1
|
|
88
|
-
http_client_requests_seconds_bucket{le="2.5",status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts/2"} 1
|
|
89
|
-
http_client_requests_seconds_bucket{le="5",status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts/2"} 1
|
|
90
|
-
http_client_requests_seconds_bucket{le="10",status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts/2"} 1
|
|
91
|
-
http_client_requests_seconds_bucket{le="+Inf",status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts/2"} 1
|
|
92
|
-
http_client_requests_seconds_sum{status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts/2"} 0.107517055
|
|
93
|
-
http_client_requests_seconds_count{status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts/2"} 1
|
|
66
|
+
http_client_requests_seconds_bucket{le="0.005",status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts/:id"} 0
|
|
67
|
+
http_client_requests_seconds_bucket{le="0.01",status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts/:id"} 0
|
|
68
|
+
http_client_requests_seconds_bucket{le="0.025",status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts/:id"} 0
|
|
69
|
+
http_client_requests_seconds_bucket{le="0.05",status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts/:id"} 0
|
|
70
|
+
http_client_requests_seconds_bucket{le="0.1",status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts/:id"} 0
|
|
71
|
+
http_client_requests_seconds_bucket{le="0.25",status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts/:id"} 0
|
|
72
|
+
http_client_requests_seconds_bucket{le="0.5",status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts/:id"} 1
|
|
73
|
+
http_client_requests_seconds_bucket{le="1",status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts/:id"} 1
|
|
74
|
+
http_client_requests_seconds_bucket{le="2.5",status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts/:id"} 2
|
|
75
|
+
http_client_requests_seconds_bucket{le="5",status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts/:id"} 2
|
|
76
|
+
http_client_requests_seconds_bucket{le="10",status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts/:id"} 2
|
|
77
|
+
http_client_requests_seconds_bucket{le="+Inf",status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts/:id"} 2
|
|
78
|
+
http_client_requests_seconds_sum{status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts/:id"} 1.372366292
|
|
79
|
+
http_client_requests_seconds_count{status_code="200",method="GET",protocol="https:",host="jsonplaceholder.typicode.com",path="/posts/:id"} 2
|
|
94
80
|
```
|
|
95
81
|
|
|
96
82
|
### Custom config
|