Skip to content

Commit

Permalink
Improve Prometheus error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Inrixia committed Oct 13, 2024
1 parent 496cb87 commit e516090
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/lib/prometheus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,21 @@ new Gauge({
export const initProm = (instance: string) => {
if (settings.metrics.contributeMetrics) {
const connect = () => {
const socket = new WebSocket("ws://targets.monitor.spookelton.net");
socket.on("open", () => socket.send(instance));
socket.on("ping", async () => socket.send(await register.metrics()));
socket.on("error", () => socket.close());
socket.on("close", () => {
const onError = () => {
socket.close();
setTimeout(connect, 1000);
};
const socket = new WebSocket("ws://targets.monitor.spookelton.net");
socket.on("open", () => socket.send(instance));
socket.on("ping", async () => {
try {
socket.send(await register.metrics());
} catch {
onError();
}
});
socket.on("error", onError);
socket.on("close", onError);
};
connect();
}
Expand Down

0 comments on commit e516090

Please sign in to comment.