Skip to content

Database Monitoring

BRIDGEPORT uses plugin-driven monitoring queries to collect database-specific metrics from PostgreSQL, MySQL, SQLite, and Redis, connecting via direct SQL, SSH commands, or the Redis protocol depending on the database type.

  1. Go to Databases and select (or create) a database.
  2. Toggle Enable Monitoring on.
  3. Click Test Connection to verify BRIDGEPORT can reach the database.
  4. Metrics appear after the first collection interval (default: 60 seconds).
  5. View charts at Monitoring > Databases.
sequenceDiagram
    participant SCH as Scheduler
    participant COL as Collector
    participant PLUGIN as Plugin JSON
    participant DB as Target Database
    participant STORE as SQLite (metrics)

    SCH->>COL: runDatabaseMetricsCollection()
    COL->>COL: Filter to enabled databases<br/>past their collectionIntervalSec
    COL->>PLUGIN: Read monitoringConfig from DatabaseType
    COL->>DB: Execute queries (SQL / SSH / Redis)
    DB-->>COL: Query results
    COL->>STORE: Save DatabaseMetrics (JSON blob)
    COL->>STORE: Update Database status → connected

BRIDGEPORT supports three connection modes, determined by the database type’s plugin definition:

ModeUsed ByHow It Works
sqlPostgreSQL, MySQLDirect TCP connection using pg or mysql2 driver
sshSQLiteSSH into the server and run shell commands
redisRedisDirect TCP connection using ioredis

Connection mode: sql (driver: pg)

QueryWhat It MeasuresResult Type
dbSizeTotal database sizescalar (bytes)
tableCountNumber of tablesscalar
totalRowsEstimated total row countscalar
totalIndexSizeCombined index sizescalar (bytes)
deadTuplesDead tuples awaiting vacuumscalar
deadTupleRatioDead tuple percentagescalar (%)
oldestUnvacuumedSeconds since oldest autovacuumscalar (seconds)
topTableSizesTop 10 tables by sizerows

Connection mode: sql (driver: mysql2)

QueryWhat It MeasuresResult Type
dbSizeTotal database sizescalar (bytes)
tableCountNumber of tablesscalar
bufferPoolHitRatioInnoDB buffer pool hit ratioscalar (%)
slowQueriesTotal slow query countscalar
topTableSizesTop 10 tables by sizerows

Connection mode: ssh

QueryWhat It MeasuresResult Type
fileSizeDatabase file size on diskscalar (bytes)
tableCountNumber of tablesscalar
pageCountTotal SQLite pagesscalar
freelistCountFree (unused) pagesscalar
topTableSizesTop tables by row countrows

Connection mode: redis

QueryWhat It MeasuresResult Type
usedMemoryCurrent memory usagescalar (bytes)
peakMemoryPeak memory usagescalar (bytes)
memFragRatioMemory fragmentation ratioscalar
totalKeysTotal keys across all databasesscalar

Redis queries use a DSL rather than raw SQL:

DSL PrefixExampleDescription
INFO:INFO:used_memoryRead a field from Redis INFO output
CMD:CMD:DBSIZEExecute a Redis command
KEYSPACE:KEYSPACE:keysSum a field across all keyspace entries
COMPUTED:COMPUTED:hit_ratioCalculate a derived metric

Step-by-Step: Setting Up Database Monitoring

Section titled “Step-by-Step: Setting Up Database Monitoring”

If you have not already registered the database in BRIDGEPORT:

  1. Go to Databases and click Add Database.
  2. Select the database type (PostgreSQL, MySQL, SQLite, or Redis).
  3. Fill in the connection details (host, port, credentials, etc.).
  4. For SQLite, specify the file path and select the server where the file lives.
  1. Open the database detail page.
  2. Toggle Enable Monitoring on.
  3. Optionally adjust the Collection Interval (default: 60 seconds).

Click Test Connection. You should see:

Connection successful
Latency: 12ms
Server version: PostgreSQL 16.2

If the test fails, check:

  • Credentials are correct
  • Host/port is reachable from BRIDGEPORT
  • For SQLite: SSH key is configured for the environment and sqlite3 is installed on the server

Navigate to Monitoring > Databases (/monitoring/databases).

  • The grid view shows all monitored databases with status indicators and key metrics.
  • Click a database to see its detail page (/monitoring/databases/:id) with full charts.

Each monitoring query has a resultType that determines how the output is parsed:

TypeDescriptionExample
scalarSingle numeric or string valueSELECT count(*) AS value FROM ...
rowSingle row with named fieldsSELECT field1, field2 FROM ... LIMIT 1
rowsMultiple rows (table data)SELECT name, size FROM ... ORDER BY size DESC LIMIT 10

For row and rows types, you can specify a resultMapping to rename columns:

{
"name": "topTableSizes",
"query": "SELECT relname AS name, pg_total_relation_size(relid) AS size ...",
"resultType": "rows",
"resultMapping": { "name": "name", "size": "size", "rows": "rows" }
}

Queries can include a chartGroup field to group related metrics on the same chart in the UI. Queries with the same chartGroup value are rendered together.

SettingDefaultDescription
monitoringEnabledfalseToggle monitoring on or off
collectionIntervalSec60Seconds between metric collections

The global scheduler polls all enabled databases periodically (default: every 60 seconds). Each database’s own collectionIntervalSec is respected — if not enough time has passed since the last collection, that database is skipped.

SettingDefaultDescription
databaseMetricsRetentionDays30Global, in Admin > System Settings > Retention

Old DatabaseMetrics rows are cleaned up hourly by the scheduler, which hot-reloads this setting each tick.

After each collection, the database’s monitoringStatus is updated:

StatusMeaning
connectedLast collection succeeded
errorLast collection failed (error message stored in lastMonitoringError)
pendingMonitoring enabled but no collection has run yet

You can add custom queries by editing the database type in the admin UI:

  1. Go to Admin > Database Types.
  2. Select the database type (e.g., PostgreSQL).
  3. Edit the Monitoring Configuration JSON.
  4. Add new query objects to the queries array.

Example — adding a connections count query for PostgreSQL:

{
"name": "activeConnections",
"displayName": "Active Connections",
"query": "SELECT count(*) AS value FROM pg_stat_activity WHERE state = 'active'",
"resultType": "scalar"
}

Changes made in the admin UI set isCustomized: true on the database type, which prevents BRIDGEPORT from overwriting your changes on plugin sync. If you want to revert to the default plugin queries, use the Reset button in admin.

DatabaseCommon Causes
PostgreSQLWrong credentials, pg_hba.conf does not allow connections from BRIDGEPORT’s IP, SSL mismatch
MySQLWrong credentials, user not granted access from BRIDGEPORT’s IP
SQLiteSSH key not configured, sqlite3 not installed on server, wrong file path
RedisWrong password, requirepass set but no password provided, TLS required but useSsl not enabled
  1. Check the error message in the database detail page (lastMonitoringError).
  2. Click Test Connection to see the current error.
  3. Fix the underlying issue (credentials, network, permissions).
  4. The next successful collection automatically resets the status to connected.
  • Verify monitoringEnabled is true for the database.
  • Verify the database type has a monitoringConfig defined. Check Admin > Database Types — if the monitoring config is empty, no queries will run.
  • Verify the scheduler is running (look for [Scheduler] Collecting metrics from N database(s) in the BRIDGEPORT logs).

Individual query failures do not abort the entire collection. Check the stored DatabaseMetrics JSON for per-query error entries:

{
"dbSize": 1048576,
"tableCount": 12,
"slowQueries": { "error": "Access denied for user..." }
}

Fix the permissions for the failing query and the next collection will succeed.