Skip to content

PostgreSQL backup tool with Point-In-Time-Recovery and restore verification

903 B
Raw Blame
import {
  WalStreamHealthLevel,
  type WalStreamStatistics,
} from '../../../../../entity/backups/physical';
import type { MonitoringFigures } from '../model/MonitoringFigures';

// The amounts come from the keeping-up summary rather than the newest sample, so the figures agree
// with the keeping-up sentence written under them.
export const getMonitoringFigures = (statistics: WalStreamStatistics): MonitoringFigures | null => {
  const { level } = statistics.health;

  if (
    level === WalStreamHealthLevel.COLLECTING_DATA ||
    level === WalStreamHealthLevel.NOT_STREAMING
  ) {
    return null;
  }

  return {
    lastSavedAt: statistics.current?.lastArchivedWalAt ?? null,
    waitingToBeSavedBytes: statistics.keepingUp.unarchivedWalBytes,
    writeBytesPerSecond: statistics.keepingUp.sourceWriteBytesPerSecond,
    saveBytesPerSecond: statistics.keepingUp.archiveBytesPerSecond,
  };
};