mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-23 08:23:12 +09:00
Add metrics for pending request
Track the number of requests currently awaiting a response from a request handler both from interally issued requests and requests forwarded from other parties.
This commit is contained in:
1 parent
51fe6c9519
commit
d7edae99c5
4 files changed
+53
-6
No files matched your search
+2
-1
@@ -4,7 +4,8 @@
|
|||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
- Added support for `color-settings` Mod settings (#568)[https://github.com/clusterio/clusterio/issues/568].
|
- Added support for `color-settings` Mod settings [#568](https://github.com/clusterio/clusterio/issues/568).
|
||||||
|
- Added `clusterio_controller_pending_requests` and `clusterio_host_pending_requests` metrics.
|
||||||
|
|
||||||
### Changes
|
### Changes
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,24 @@ import { version } from "./package.json";
|
|||||||
// globals
|
// globals
|
||||||
let controller: Controller;
|
let controller: Controller;
|
||||||
|
|
||||||
|
void new lib.Gauge(
|
||||||
|
"clusterio_controller_pending_requests",
|
||||||
|
"Count of pending link requests currently waiting in memory on the controller.",
|
||||||
|
{
|
||||||
|
callback: (gauge) => {
|
||||||
|
let count = 0;
|
||||||
|
if (controller) {
|
||||||
|
for (const host of controller.wsServer.hostConnections.values()) {
|
||||||
|
count += host.pendingRequestCount;
|
||||||
|
}
|
||||||
|
for (const control of controller.wsServer.controlConnections.values()) {
|
||||||
|
count += control.pendingRequestCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gauge.set(count);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
void new lib.Gauge(
|
void new lib.Gauge(
|
||||||
"clusterio_controller_host_mapping",
|
"clusterio_controller_host_mapping",
|
||||||
|
|||||||
+26
-5
@@ -26,6 +26,27 @@ import { ConsoleTransport, levels, logger } from "@clusterio/lib";
|
|||||||
|
|
||||||
import Host from "./src/Host";
|
import Host from "./src/Host";
|
||||||
|
|
||||||
|
let host: Host | undefined;
|
||||||
|
|
||||||
|
void new lib.Gauge(
|
||||||
|
"clusterio_host_pending_requests",
|
||||||
|
"Count of pending link requests currently waiting in memory on the host.",
|
||||||
|
{
|
||||||
|
labels: ["host_id"],
|
||||||
|
callback: (gauge) => {
|
||||||
|
if (!host) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let count = host.pendingRequestCount;
|
||||||
|
for (const connection of host.instanceConnections.values()) {
|
||||||
|
count += connection.pendingRequestCount;
|
||||||
|
count += connection.instance.pendingRequestCount;
|
||||||
|
}
|
||||||
|
gauge.labels(String(host.config.get("host.id"))).set(count);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
export class HostConnector extends lib.WebSocketClientConnector {
|
export class HostConnector extends lib.WebSocketClientConnector {
|
||||||
constructor(
|
constructor(
|
||||||
@@ -205,7 +226,7 @@ async function startHost() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let hostConnector = new HostConnector(hostConfig, tlsCa, pluginInfos);
|
let hostConnector = new HostConnector(hostConfig, tlsCa, pluginInfos);
|
||||||
let host = new Host(
|
host = new Host(
|
||||||
hostConnector,
|
hostConnector,
|
||||||
args.config,
|
args.config,
|
||||||
hostConfig,
|
hostConfig,
|
||||||
@@ -227,7 +248,7 @@ async function startHost() {
|
|||||||
|
|
||||||
secondSigint = true;
|
secondSigint = true;
|
||||||
logger.info("Caught interrupt signal, shutting down");
|
logger.info("Caught interrupt signal, shutting down");
|
||||||
host.shutdown();
|
host!.shutdown();
|
||||||
});
|
});
|
||||||
let secondSigterm = false;
|
let secondSigterm = false;
|
||||||
process.on("SIGTERM", () => {
|
process.on("SIGTERM", () => {
|
||||||
@@ -240,11 +261,11 @@ async function startHost() {
|
|||||||
|
|
||||||
secondSigterm = true;
|
secondSigterm = true;
|
||||||
logger.info("Caught termination signal, shutting down");
|
logger.info("Caught termination signal, shutting down");
|
||||||
host.shutdown();
|
host!.shutdown();
|
||||||
});
|
});
|
||||||
process.on("SIGHUP", () => {
|
process.on("SIGHUP", () => {
|
||||||
logger.info("Terminal closed, shutting down");
|
logger.info("Terminal closed, shutting down");
|
||||||
host.shutdown();
|
host!.shutdown();
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -255,7 +276,7 @@ async function startHost() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
hostConnector.once("connect", () => {
|
hostConnector.once("connect", () => {
|
||||||
logger.add(new lib.LinkTransport({ link: host }));
|
logger.add(new lib.LinkTransport({ link: host! }));
|
||||||
});
|
});
|
||||||
|
|
||||||
await hostConnector.connect();
|
await hostConnector.connect();
|
||||||
|
|||||||
@@ -141,6 +141,13 @@ export class Link {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Count of requests currently waiting for a response on this link
|
||||||
|
*/
|
||||||
|
get pendingRequestCount() {
|
||||||
|
return this._pendingRequests.size + this._forwardedRequests.size;
|
||||||
|
}
|
||||||
|
|
||||||
_clearPendingRequests(err: Error & { code?: string }) {
|
_clearPendingRequests(err: Error & { code?: string }) {
|
||||||
for (let pending of this._pendingRequests.values()) {
|
for (let pending of this._pendingRequests.values()) {
|
||||||
pending.reject(err);
|
pending.reject(err);
|
||||||
|
|||||||
Reference in new issue
Block a user