Skip to content

Commit

Permalink
metrics: add WAL checkpoint metrics
Browse files Browse the repository at this point in the history
Add metrics for the WAL checkpoint pages for each database.

Log output:
```
info: WAL checkpoint {"class":"StandaloneSqliteDatabase","dbName":"data","timestamp":"2024-09-24T14:22:13.957Z","walCheckpoint":{"busy":0,"checkpointed":0,"log":0}}
```

Metric output:
```
sqlite_wal_checkpoint_pages{db="data",type="busy"} 0
sqlite_wal_checkpoint_pages{db="data",type="checkpointed"} 0
sqlite_wal_checkpoint_pages{db="data",type="log"} 0
```
  • Loading branch information
karlprieb committed Sep 24, 2024
1 parent 60d421b commit 42a23df
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/database/standalone-sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2348,7 +2348,9 @@ export class StandaloneSqliteDatabaseWorker {
}

cleanupWal(dbName: 'core' | 'bundles' | 'data' | 'moderation'): void {
this.dbs[dbName].pragma('wal_checkpoint(TRUNCATE)');
const walCheckpoint = this.dbs[dbName].pragma('wal_checkpoint(TRUNCATE)');

return walCheckpoint[0];
}
}

Expand Down Expand Up @@ -2971,7 +2973,25 @@ export class StandaloneSqliteDatabase
}

async cleanupWal(dbName: WorkerPoolName): Promise<void> {
return this.queueWrite(dbName, 'cleanupWal', [dbName]);
this.queueWrite(dbName, 'cleanupWal', [dbName]).then((walCheckpoint) => {
this.log.info('WAL checkpoint', {
dbName,
walCheckpoint,
});

metrics.sqliteWalCheckpointPages.set(
{ db: dbName, type: 'busy' },
walCheckpoint.busy,
);
metrics.sqliteWalCheckpointPages.set(
{ db: dbName, type: 'log' },
walCheckpoint.log,
);
metrics.sqliteWalCheckpointPages.set(
{ db: dbName, type: 'checkpointed' },
walCheckpoint.checkpointed,
);
});
}
}

Expand Down Expand Up @@ -3114,8 +3134,8 @@ if (!isMainThread) {
parentPort?.postMessage(null);
break;
case 'cleanupWal':
worker.cleanupWal(args[0]);
parentPort?.postMessage(undefined);
const walCheckpoint = worker.cleanupWal(args[0]);
parentPort?.postMessage(walCheckpoint);
break;
case 'terminate':
parentPort?.postMessage(null);
Expand Down
6 changes: 6 additions & 0 deletions src/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ export const saveMethodsDuplicateCounter = new promClient.Counter({
labelNames: ['method'],
});

export const sqliteWalCheckpointPages = new promClient.Gauge({
name: 'sqlite_wal_checkpoint_pages',
help: 'Number of pages in the WAL',
labelNames: ['db', 'type'],
});

//
// Block importer metrics
//
Expand Down

0 comments on commit 42a23df

Please sign in to comment.