-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a43e906
commit 89888be
Showing
4 changed files
with
61 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { allOk } from '@medplum/core'; | ||
import { FhirRequest, FhirResponse } from '@medplum/fhir-router'; | ||
import { OperationDefinition } from '@medplum/fhirtypes'; | ||
import { requireSuperAdmin } from '../../admin/super'; | ||
import { getDatabasePool } from '../../database'; | ||
import { buildOutputParameters } from './utils/parameters'; | ||
|
||
const operation: OperationDefinition = { | ||
resourceType: 'OperationDefinition', | ||
name: 'db-stats', | ||
status: 'active', | ||
kind: 'operation', | ||
code: 'status', | ||
experimental: true, | ||
system: true, | ||
type: false, | ||
instance: false, | ||
parameter: [{ use: 'out', name: 'tableString', type: 'string', min: 1, max: '1' }], | ||
}; | ||
|
||
export async function dbStatsHandler(_req: FhirRequest): Promise<FhirResponse> { | ||
requireSuperAdmin(); | ||
|
||
const client = getDatabasePool(); | ||
const sql = ` | ||
SELECT * FROM ( | ||
SELECT table_schema, table_name, pg_relation_size('"'||table_schema||'"."'||table_name||'"') AS table_size | ||
FROM information_schema.tables | ||
) tables | ||
WHERE table_size > 0 | ||
ORDER BY table_size DESC; | ||
`; | ||
|
||
const result = await client.query(sql); | ||
|
||
const tableString = result.rows.map((row) => `${row.table_schema}.${row.table_name}: ${row.table_size}`).join('\n'); | ||
|
||
return [allOk, buildOutputParameters(operation, { tableString })]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters