-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(database monitor): query configured postgres values (#3711)
- provides a threshold for use in monitoring & alerting
- Loading branch information
1 parent
571338c
commit a6d7aad
Showing
7 changed files
with
211 additions
and
1 deletion.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
packages/monitor-deployment/src/observability/metrics/dbMaxLogicalReplicationWorkers.ts
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,33 @@ | ||
import prometheusClient from 'prom-client' | ||
import { join } from 'lodash-es' | ||
import type { MetricInitializer } from '@/observability/types.js' | ||
|
||
export const init: MetricInitializer = (config) => { | ||
const { labelNames, namePrefix, logger } = config | ||
const metric = new prometheusClient.Gauge({ | ||
name: join([namePrefix, 'db', 'max_logical_replication_workers'], '_'), | ||
help: 'Configured value of max_logical_replication_workers for the Postgres database', | ||
labelNames: ['region', ...labelNames] | ||
}) | ||
return async (params) => { | ||
const { dbClients, labels } = params | ||
await Promise.all( | ||
dbClients.map(async ({ client, regionKey }) => { | ||
const queryResults = await client.raw<{ | ||
rows: [{ max_logical_replication_workers: string }] | ||
}>(`SHOW max_logical_replication_workers;`) | ||
if (!queryResults.rows.length) { | ||
logger.error( | ||
{ region: regionKey }, | ||
"No max_logical_replication_workers found for region '{region}'. This is odd." | ||
) | ||
return | ||
} | ||
metric.set( | ||
{ ...labels, region: regionKey }, | ||
parseInt(queryResults.rows[0].max_logical_replication_workers) | ||
) | ||
}) | ||
) | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
packages/monitor-deployment/src/observability/metrics/dbMaxReplicationSlots.ts
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,33 @@ | ||
import prometheusClient from 'prom-client' | ||
import { join } from 'lodash-es' | ||
import type { MetricInitializer } from '@/observability/types.js' | ||
|
||
export const init: MetricInitializer = (config) => { | ||
const { labelNames, namePrefix, logger } = config | ||
const metric = new prometheusClient.Gauge({ | ||
name: join([namePrefix, 'db_max_replication_slots'], '_'), | ||
help: 'Configured value of max_replication_slots for the Postgres database', | ||
labelNames: ['region', ...labelNames] | ||
}) | ||
return async (params) => { | ||
const { dbClients, labels } = params | ||
await Promise.all( | ||
dbClients.map(async ({ client, regionKey }) => { | ||
const queryResults = await client.raw<{ | ||
rows: [{ max_replication_slots: string }] | ||
}>(`SHOW max_replication_slots;`) | ||
if (!queryResults.rows.length) { | ||
logger.error( | ||
{ region: regionKey }, | ||
"No max_replication_slots found for region '{region}'. This is odd." | ||
) | ||
return | ||
} | ||
metric.set( | ||
{ ...labels, region: regionKey }, | ||
parseInt(queryResults.rows[0].max_replication_slots) | ||
) | ||
}) | ||
) | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
packages/monitor-deployment/src/observability/metrics/dbMaxSyncWorkersPerSubscription.ts
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,33 @@ | ||
import prometheusClient from 'prom-client' | ||
import { join } from 'lodash-es' | ||
import type { MetricInitializer } from '@/observability/types.js' | ||
|
||
export const init: MetricInitializer = (config) => { | ||
const { labelNames, namePrefix, logger } = config | ||
const metric = new prometheusClient.Gauge({ | ||
name: join([namePrefix, 'db', 'max_sync_workers_per_subscription'], '_'), | ||
help: 'Configured value of max_sync_workers_per_subscription for the Postgres database', | ||
labelNames: ['region', ...labelNames] | ||
}) | ||
return async (params) => { | ||
const { dbClients, labels } = params | ||
await Promise.all( | ||
dbClients.map(async ({ client, regionKey }) => { | ||
const queryResults = await client.raw<{ | ||
rows: [{ max_sync_workers_per_subscription: string }] | ||
}>(`SHOW max_sync_workers_per_subscription;`) | ||
if (!queryResults.rows.length) { | ||
logger.error( | ||
{ region: regionKey }, | ||
"No max_sync_workers_per_subscription found for region '{region}'. This is odd." | ||
) | ||
return | ||
} | ||
metric.set( | ||
{ ...labels, region: regionKey }, | ||
parseInt(queryResults.rows[0].max_sync_workers_per_subscription) | ||
) | ||
}) | ||
) | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
packages/monitor-deployment/src/observability/metrics/dbMaxWalSenders.ts
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,33 @@ | ||
import prometheusClient from 'prom-client' | ||
import { join } from 'lodash-es' | ||
import type { MetricInitializer } from '@/observability/types.js' | ||
|
||
export const init: MetricInitializer = (config) => { | ||
const { labelNames, namePrefix, logger } = config | ||
const metric = new prometheusClient.Gauge({ | ||
name: join([namePrefix, 'db_max_wal_senders'], '_'), | ||
help: 'Configured value of max_wal_senders for the Postgres database', | ||
labelNames: ['region', ...labelNames] | ||
}) | ||
return async (params) => { | ||
const { dbClients, labels } = params | ||
await Promise.all( | ||
dbClients.map(async ({ client, regionKey }) => { | ||
const queryResults = await client.raw<{ | ||
rows: [{ max_wal_senders: string }] | ||
}>(`SHOW max_wal_senders;`) | ||
if (!queryResults.rows.length) { | ||
logger.error( | ||
{ region: regionKey }, | ||
"No max_wal_senders found for region '{region}'. This is odd." | ||
) | ||
return | ||
} | ||
metric.set( | ||
{ ...labels, region: regionKey }, | ||
parseInt(queryResults.rows[0].max_wal_senders) | ||
) | ||
}) | ||
) | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
packages/monitor-deployment/src/observability/metrics/dbMaxWorkerProcesses.ts
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,33 @@ | ||
import prometheusClient from 'prom-client' | ||
import { join } from 'lodash-es' | ||
import type { MetricInitializer } from '@/observability/types.js' | ||
|
||
export const init: MetricInitializer = (config) => { | ||
const { labelNames, namePrefix, logger } = config | ||
const metric = new prometheusClient.Gauge({ | ||
name: join([namePrefix, 'db', 'max_worker_processes'], '_'), | ||
help: 'Configured value of max_worker_processes for the Postgres database', | ||
labelNames: ['region', ...labelNames] | ||
}) | ||
return async (params) => { | ||
const { dbClients, labels } = params | ||
await Promise.all( | ||
dbClients.map(async ({ client, regionKey }) => { | ||
const queryResults = await client.raw<{ | ||
rows: [{ max_worker_processes: string }] | ||
}>(`SHOW max_worker_processes;`) | ||
if (!queryResults.rows.length) { | ||
logger.error( | ||
{ region: regionKey }, | ||
"No max_worker_processes found for region '{region}'. This is odd." | ||
) | ||
return | ||
} | ||
metric.set( | ||
{ ...labels, region: regionKey }, | ||
parseInt(queryResults.rows[0].max_worker_processes) | ||
) | ||
}) | ||
) | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
packages/monitor-deployment/src/observability/metrics/dbWalLevel.ts
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,33 @@ | ||
import prometheusClient from 'prom-client' | ||
import { join } from 'lodash-es' | ||
import type { MetricInitializer } from '@/observability/types.js' | ||
|
||
export const init: MetricInitializer = (config) => { | ||
const { labelNames, namePrefix, logger } = config | ||
const metric = new prometheusClient.Gauge({ | ||
name: join([namePrefix, 'db_wal_level_is_logical'], '_'), | ||
help: "Indicates whether the value of wal_level for the Postgres database is 'logical'", | ||
labelNames: ['region', ...labelNames] | ||
}) | ||
return async (params) => { | ||
const { dbClients, labels } = params | ||
await Promise.all( | ||
dbClients.map(async ({ client, regionKey }) => { | ||
const queryResults = await client.raw<{ | ||
rows: [{ wal_level: string }] | ||
}>(`SHOW wal_level;`) | ||
if (!queryResults.rows.length) { | ||
logger.error( | ||
{ region: regionKey }, | ||
"No wal_level found for region '{region}'. This is odd." | ||
) | ||
return | ||
} | ||
metric.set( | ||
{ ...labels, region: regionKey }, | ||
queryResults.rows[0].wal_level === 'logical' ? 1 : 0 | ||
) | ||
}) | ||
) | ||
} | ||
} |
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