back: adding postgresql statistics (#762)

This commit is contained in:
Eric Doughty-Papassideris
2024-12-08 22:52:52 +01:00
parent 6f8ff34051
commit e6593986f1
2 changed files with 17 additions and 3 deletions
@@ -74,10 +74,24 @@ export class PostgresConnector extends AbstractConnector<PostgresConnectionOptio
switch (depth) {
case TServiceDiagnosticDepth.alive:
return { ok: true, didConnect: await this.ping() };
case TServiceDiagnosticDepth.stats_basic:
case TServiceDiagnosticDepth.stats_track:
return {
ok: true,
db: (
await this.client.query("select * from pg_stat_database where datname = $1", [
this.options.database,
])
).rows,
};
case TServiceDiagnosticDepth.stats_basic:
return { ok: true, warn: "pgsql_basic_has_nothing_more_than_track" };
case TServiceDiagnosticDepth.stats_deep:
return { ok: true, warn: "unsupported_depth" };
return {
ok: true,
databases: (await this.client.query("select * from pg_stat_database")).rows,
tables: (await this.client.query("select * from pg_stat_user_tables")).rows,
indexes: (await this.client.query("select * from pg_stat_user_indexes")).rows,
};
default:
throw new Error(`Unexpected TServiceDiagnosticDepth: ${JSON.stringify(depth)}`);
@@ -1,4 +1,4 @@
import diagnostics from "../../../framework/api/diagnostics";
import globalResolver from "../../../../../services/global-resolver";
export default () => diagnostics.registerServiceProviders("db", () => globalResolver.database, {});
export default () => diagnostics.registerServiceProviders("db", () => globalResolver.database);