Sélectionner une révision Git
-
Louis Fourcade a rédigéLouis Fourcade a rédigé
metrics.ts 5,03 Kio
/*
Copyright 2019 matrix-appservice-discord
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import { PrometheusMetrics, Bridge } from "matrix-appservice-bridge";
import { Gauge, Counter, Histogram } from "prom-client";
import { Log } from "./log";
const AgeCounters = PrometheusMetrics.AgeCounters;
const log = new Log("BridgeMetrics");
const REQUEST_EXPIRE_TIME_MS = 30000;
interface IAgeCounter {
setGauge(gauge: Gauge, morelabels: string[]);
bump(age: number);
}
interface IBridgeGauges {
matrixRoomConfigs: number;
remoteRoomConfigs: number;
matrixGhosts: number;
remoteGhosts: number;
matrixRoomsByAge: IAgeCounter;
remoteRoomsByAge: IAgeCounter;
matrixUsersByAge: IAgeCounter;
remoteUsersByAge: IAgeCounter;
}
export interface IBridgeMetrics {
registerRequest(id: string);
requestOutcome(id: string, isRemote: boolean, outcome: string);
remoteCall(method: string);
setPresenceCount(count: number);
storeCall(method: string, cached: boolean);
}
export class DummyBridgeMetrics implements IBridgeMetrics {
public registerRequest() {}
public requestOutcome() {}
public remoteCall() {}
public setPresenceCount() {}
public storeCall() {}
}
export class MetricPeg {
public static get get(): IBridgeMetrics {
return this.metrics;
}
public static set(metrics: IBridgeMetrics) {
this.metrics = metrics;
}
private static metrics: IBridgeMetrics = new DummyBridgeMetrics();
}
export class PrometheusBridgeMetrics implements IBridgeMetrics {
private metrics;