Skip to content

Commit

Permalink
Better Prometheus socket handling & mode detailed request duration me…
Browse files Browse the repository at this point in the history
…trics
  • Loading branch information
Inrixia committed Oct 13, 2024
1 parent 0b29291 commit bc241de
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/lib/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const httpRequestDurationmMs = new Histogram({
name: "request_duration_ms",
help: "Duration of HTTP requests in ms",
labelNames: ["method", "hostname", "pathname", "status"],
buckets: [1, 10, 50, 100, 250, 500],
buckets: [5, 10, 15, 30, 50, 100, 250, 500, 750, 1000, 1500, 2000, 3000],
});
type WithStartTime<T> = T & { _startTime: number };
fApi.extend({
Expand Down
10 changes: 6 additions & 4 deletions src/lib/prometheus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@ new Gauge({
.labels({ version: DownloaderVersion })
.set(1);

let socket: WebSocket | undefined;
export const initProm = (instance: string) => {
if (settings.metrics.contributeMetrics) {
const connect = () => {
const onError = () => {
socket.close();
socket?.terminate();
setTimeout(connect, 1000);
};
const socket = new WebSocket("ws://targets.monitor.spookelton.net");
socket.on("open", () => socket.send(instance));
socket?.terminate();
socket = new WebSocket("ws://targets.monitor.spookelton.net");
socket.on("open", () => socket?.send(instance));
socket.on("ping", async () => {
try {
socket.send(await register.metrics());
socket?.send(await register.metrics());
} catch {
onError();
}
Expand Down

0 comments on commit bc241de

Please sign in to comment.