forked from jupyterhub/configurable-http-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics.js
113 lines (98 loc) · 2.66 KB
/
metrics.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
"use strict";
var client = require("prom-client");
class Metrics {
constructor() {
this.register = new client.Registry();
client.collectDefaultMetrics({ register: this.register });
this.apiRouteGetCount = new client.Counter({
name: "api_route_get",
help: "Count of API route get requests",
registers: [this.register],
});
this.apiRouteAddCount = new client.Counter({
name: "api_route_add",
help: "Count of API route add requests",
registers: [this.register],
});
this.apiRouteDeleteCount = new client.Counter({
name: "api_route_delete",
help: "Count of API route delete requests",
registers: [this.register],
});
this.findTargetForReqSummary = new client.Summary({
name: "find_target_for_req",
help: "Summary of find target requests",
registers: [this.register],
});
this.lastActivityUpdatingSummary = new client.Summary({
name: "last_activity_updating",
help: "Summary of last activity updating requests",
registers: [this.register],
});
this.requestsWsCount = new client.Counter({
name: "requests_ws",
help: "Count of websocket requests",
registers: [this.register],
});
this.requestsWebCount = new client.Counter({
name: "requests_web",
help: "Count of web requests",
registers: [this.register],
});
this.requestsProxyCount = new client.Counter({
name: "requests_proxy",
help: "Count of proxy requests",
labelNames: ["status"],
registers: [this.register],
});
this.requestsApiCount = new client.Counter({
name: "requests_api",
help: "Count of API requests",
labelNames: ["status"],
registers: [this.register],
});
}
render(res) {
return this.register.metrics().then((s) => {
res.writeHead(200, { "Content-Type": this.register.contentType });
res.write(s);
res.end();
});
}
}
class MockMetrics {
constructor() {
return new Proxy(this, {
get(target, name) {
const mockCounter = new Proxy(
{},
{
get(target, name) {
if (name == "inc") {
return () => {};
}
if (name == "startTimer") {
return () => {
return () => {};
};
}
if (name == "labels") {
return () => {
return mockCounter;
};
}
},
}
);
return mockCounter;
},
});
}
render(res) {
return Promise.resolve();
}
}
module.exports = {
Metrics,
MockMetrics,
};