Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
fix: add uptime calculation for card value - duration (private locations) (#2481)
Max2f084de94280
diff --git a/packages/api/src/router/statusPage.utils.ts b/packages/api/src/router/statusPage.utils.tsindex 32f978552..f7d25d451 100644--- a/packages/api/src/router/statusPage.utils.ts+++ b/packages/api/src/router/statusPage.utils.ts@@ -1,16 +1,27 @@import type { PageComponentImpact } from "@openstatus/db/src/schema";-import { impactToStatusType, worstImpact } from "@openstatus/db/src/schema";import {+ impactToStatusType,+ impactUptimeWeight,+ LEGACY_IMPACT_WEIGHT,+ worstImpact,+} from "@openstatus/db/src/schema";+import {+ clipToCoverage,+ type CoverageSegment,+ downtimeIntervals,type Event,MS_PER_DAY,+ probeDowntimeIntervals,type StatusData,type UptimeWindow,+ type WeightedInterval,dayCoverage,durationDowntimeMs,floorPct,getHighestPriorityStatus,getWorstVariant,isDateWithinEvent,+ mergedDowntimeMs,reportEventDayImpact,reportEventDayStatus,reportsOnlyDowntimeMs,@@ -662,10 +673,22 @@ export function getUptime({end: windowEndDate.getTime(),now: Date.now(),};- const duration =- barType === "manual"- ? reportsOnlyDowntimeMs(events, window, coverage)- : durationDowntimeMs(events, window, coverage);++ let duration: number;+ if (barType === "manual") {+ // Manual mode: only count manually created reports+ duration = reportsOnlyDowntimeMs(events, window, coverage);+ } else {+ // Duration mode: merge both event-based and probe-based downtime+ // to capture both manual incidents/reports AND automated probe failures+ const eventIntervals = downtimeIntervals(events, window, false);+ const probeIntervals = probeDowntimeIntervals(data, window);+ const allIntervals = [...eventIntervals, ...probeIntervals];+ duration = mergedDowntimeMs(+ coverage ? clipToCoverage(allIntervals, coverage) : allIntervals,+ );+ }+return `${floorPct((total - duration) / total)}%`;}diff --git a/packages/services/src/status-timeline/uptime.ts b/packages/services/src/status-timeline/uptime.tsindex c6a205f3e..5666a08e1 100644--- a/packages/services/src/status-timeline/uptime.ts+++ b/packages/services/src/status-timeline/uptime.ts@@ -4,7 +4,7 @@ import {} from "@openstatus/db/src/schema";import { type WeightedInterval, mergedDowntimeMs } from "./downtime";-import type { Event } from "./events";+import type { Event, StatusData } from "./events";export const MS_PER_DAY = 86_400_000;@@ -42,7 +42,7 @@ export function dayCoverage(// downtime during a coverage gap (paused monitor, missing data days) would// exceed a days-with-checks denominator and fake 0% for a healthy monitor —// clip every interval to the covered segments before merging-function clipToCoverage(+export function clipToCoverage(intervals: WeightedInterval[],coverage: CoverageSegment[],): WeightedInterval[] {@@ -73,7 +73,7 @@ export function requestsTally(counts: CheckCounts[]): {return { up, total };}-function clampInterval(+export function clampInterval(from: Date,to: Date | null,weight: number,@@ -85,7 +85,7 @@ function clampInterval(return { from: start, to: end, weight };}-function downtimeIntervals(+export function downtimeIntervals(events: Event[],window: UptimeWindow,reportsOnly: boolean,@@ -148,3 +148,41 @@ export function reportsOnlyDowntimeMs(coverage ? clipToCoverage(intervals, coverage) : intervals,);}++/**+ * Probe-based downtime intervals: converts probe failure data into weighted+ * downtime intervals. Each day's error ratio becomes the weight for that day's+ * interval, allowing it to be merged with event-based downtime.+ */+export function probeDowntimeIntervals(+ data: StatusData[],+ window: UptimeWindow,+): WeightedInterval[] {+ const intervals: WeightedInterval[] = [];++ for (const item of data) {+ const dayStart = new Date(item.day).getTime();+ const dayEnd = dayStart + MS_PER_DAY;++ // Clamp to window+ const start = Math.max(dayStart, window.start);+ const end = Math.min(dayEnd, window.end);+ if (end <= start) continue;++ const totalChecks = item.ok + item.degraded + item.error;+ if (totalChecks === 0) continue;++ // Calculate error ratio as the weight+ // degraded counts as "up" (like in requestsTally), only errors count as down+ const errorRatio = item.error / totalChecks;+ if (errorRatio === 0) continue;++ intervals.push({+ from: start,+ to: end,+ weight: errorRatio,+ });+ }++ return intervals;+}