Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
feat: sla uptime calculator (#1391)
Maximilian Kaske84b500cc62d2
diff --git a/apps/web/src/app/(pages)/(content)/play/page.tsx b/apps/web/src/app/(pages)/(content)/play/page.tsxindex 7b8179bda..38b885baa 100644--- a/apps/web/src/app/(pages)/(content)/play/page.tsx+++ b/apps/web/src/app/(pages)/(content)/play/page.tsx@@ -6,6 +6,7 @@ import {Package,Palette,PanelTop,+ ShieldCheck,Table,Terminal,} from "lucide-react";@@ -67,6 +68,13 @@ const playgrounds: CardProps[] = [description: "Easily generate curl commands to test your API endpoints.",icon: Terminal,},+ {+ href: "/play/uptime-sla",+ title: "Uptime SLA Calculator",+ description:+ "Calculate uptime SLA percentages, allowed downtime, and service availability metrics.",+ icon: ShieldCheck,+ },{href: "https://light.openstatus.dev",title: "Vercel Edge Ping",diff --git a/apps/web/src/app/(pages)/(content)/play/uptime-sla/_components/uptime-sla-form.tsx b/apps/web/src/app/(pages)/(content)/play/uptime-sla/_components/uptime-sla-form.tsxnew file mode 100644index 000000000..f9d69685b--- /dev/null+++ b/apps/web/src/app/(pages)/(content)/play/uptime-sla/_components/uptime-sla-form.tsx@@ -0,0 +1,333 @@+"use client";++import { zodResolver } from "@hookform/resolvers/zod";+import {+ Badge,+ Button,+ Form,+ FormDescription,+ FormField,+ FormItem,+ FormLabel,+ FormMessage,+ InputWithAddons,+ Tabs,+ TabsContent,+ TabsList,+ TabsTrigger,+} from "@openstatus/ui";+import { Clock, Percent } from "lucide-react";+import { useForm } from "react-hook-form";+import { z } from "zod";++const periods = ["days", "weeks", "months", "years"] as const;++const periodsInSeconds = {+ days: 24 * 60 * 60,+ weeks: 24 * 60 * 60 * 7,+ months: 24 * 60 * 60 * 30,+ years: 24 * 60 * 60 * 365,+} satisfies Record<(typeof periods)[number], number>;++// Parse downtime string like "11h 30m 10s" or "1d 2h 30m" to seconds+function parseDowntimeToSeconds(downtime: string): number {+ if (!downtime.trim()) return 0;++ const regex = /(\d+)\s*(d|h|m|s)/g;+ let totalSeconds = 0;+ let match: RegExpExecArray | null = null;++ // biome-ignore lint/suspicious/noAssignInExpressions: <explanation>+ while ((match = regex.exec(downtime)) !== null) {+ const value = Number.parseInt(match[1], 10);+ const unit = match[2];++ switch (unit) {+ case "w":+ totalSeconds += value * 24 * 60 * 60 * 7; // weeks+ break;+ case "d":+ totalSeconds += value * 24 * 60 * 60; // days+ break;+ case "h":+ totalSeconds += value * 60 * 60; // hours+ break;+ case "m":+ totalSeconds += value * 60; // minutes+ break;+ case "s":+ totalSeconds += value; // seconds+ break;+ }+ }++ return totalSeconds;+}++// Calculate uptime percentage from downtime seconds and period+function calculateUptimePercentage(+ downtimeSeconds: number,+ periodSeconds: number,+): number {+ if (downtimeSeconds >= periodSeconds) return 0;+ const uptimeSeconds = periodSeconds - downtimeSeconds;+ return (uptimeSeconds / periodSeconds) * 100;+}++// Format seconds into human-readable format (days, hours, minutes, seconds)+function formatDuration(seconds: number): string {+ if (seconds === 0) return "0s";++ const days = Math.floor(seconds / (24 * 60 * 60));+ const hours = Math.floor((seconds % (24 * 60 * 60)) / (60 * 60));+ const minutes = Math.floor((seconds % (60 * 60)) / 60);+ const remainingSeconds = Math.floor(seconds % 60);++ const parts: string[] = [];++ if (days > 0) parts.push(`${days}d`);+ if (hours > 0) parts.push(`${hours}h`);+ if (minutes > 0) parts.push(`${minutes}m`);+ if (remainingSeconds > 0) parts.push(`${remainingSeconds}s`);++ return parts.join(" ");+}++const formSchema = z.object({+ uptime: z.number().min(0).max(100).default(99.99),+ downtime: z.string(), // 1h 10m 30s+});++export function UptimeSLAForm({+ defaultValues,+}: {+ defaultValues?: z.infer<typeof formSchema>;+}) {+ const form = useForm<z.infer<typeof formSchema>>({+ resolver: zodResolver(formSchema),+ defaultValues,+ });++ const watchUptime = form.watch("uptime");+ const watchDowntime = form.watch("downtime");++ return (+ <Form {...form}>+ <form+ onSubmit={form.handleSubmit((data) => {+ console.log(data);+ })}+ className="w-full"+ >+ <Tabs defaultValue="uptime" className="w-full">+ <TabsList className="w-full">+ <TabsTrigger value="uptime" className="w-full">+ <span className="block sm:hidden">Uptime</span>+ <span className="hidden sm:block">Uptime Percentage</span>+ </TabsTrigger>+ <TabsTrigger value="downtime" className="w-full">+ <span className="block sm:hidden">Downtime</span>+ <span className="hidden sm:block">Downtime Duration</span>+ </TabsTrigger>+ </TabsList>+ <TabsContent value="uptime" className="grid gap-4">+ <div className="grid gap-3 sm:grid-cols-2">+ <FormField+ control={form.control}+ name="uptime"+ render={({ field }) => (+ <FormItem>+ <FormLabel className="sr-only">Uptime</FormLabel>+ <InputWithAddons+ type="number"+ placeholder="99.99"+ leading={<Percent className="mt-1 size-4" />}+ step={0.01}+ min={0}+ max={100}+ {...field}+ onChange={(e) => {+ // Convert comma to dot for parsing, but keep comma in display+ const normalizedValue = e.target.value.replace(+ ",",+ ".",+ );+ const value = Number.parseFloat(normalizedValue);+ if (Number.isNaN(value)) {+ field.onChange("");+ } else {+ field.onChange(value);+ }+ }}+ />+ <FormDescription>uptime percentage</FormDescription>+ <FormMessage />+ </FormItem>+ )}+ />+ <div>+ <div className="flex flex-wrap gap-0.5">+ <Button+ size="sm"+ variant={watchUptime === 99.9 ? "default" : "outline"}+ onClick={() => form.setValue("uptime", 99.9)}+ asChild+ >+ <Badge variant="outline" className="h-6 rounded-full px-2">+ three nines+ </Badge>+ </Button>+ <Button+ size="sm"+ variant={watchUptime === 99.99 ? "default" : "outline"}+ onClick={() => form.setValue("uptime", 99.99)}+ asChild+ >+ <Badge variant="outline" className="h-6 rounded-full px-2">+ four nines+ </Badge>+ </Button>+ <Button+ size="sm"+ variant={watchUptime === 99.999 ? "default" : "outline"}+ onClick={() => form.setValue("uptime", 99.999)}+ asChild+ >+ <Badge variant="outline" className="h-6 rounded-full px-2">+ five nines+ </Badge>+ </Button>+ <Button+ size="sm"+ variant={watchUptime === 99.9999 ? "default" : "outline"}+ onClick={() => form.setValue("uptime", 99.9999)}+ asChild+ >+ <Badge variant="outline" className="h-6 rounded-full px-2">+ six nines+ </Badge>+ </Button>+ </div>+ </div>+ </div>+ <div>+ <ul className="list-inside list-disc marker:text-muted-foreground/50">+ {periods.map((period) => {+ const totalSeconds =+ (watchUptime * periodsInSeconds[period]) / 100;+ const allowedDowntimeSeconds =+ periodsInSeconds[period] - totalSeconds;+ return (+ <li key={period}>+ <span className="text-muted-foreground capitalize">+ {period} reporting:+ </span>{" "}+ <span className="font-medium">+ {formatDuration(Math.round(allowedDowntimeSeconds))}+ </span>{" "}+ <span className="text-muted-foreground">downtime</span>+ </li>+ );+ })}+ </ul>+ </div>+ </TabsContent>+ <TabsContent value="downtime" className="grid gap-4">+ <div className="grid gap-3 sm:grid-cols-2">+ <FormField+ control={form.control}+ name="downtime"+ render={({ field }) => (+ <FormItem>+ <FormLabel className="sr-only">Downtime</FormLabel>+ <InputWithAddons+ leading={<Clock className="mt-1 size-4" />}+ type="text"+ placeholder="11h 30m 10s"+ {...field}+ />+ <FormDescription>+ downtime duration, e.g.{" "}+ <code className="font-mono text-foreground">+ 1d 11h 30m 10s+ </code>+ </FormDescription>+ <FormMessage />+ </FormItem>+ )}+ />+ <div>+ <div className="flex gap-0.5">+ <Button+ size="sm"+ variant={watchDowntime === "1m" ? "default" : "outline"}+ onClick={() => form.setValue("downtime", "1m")}+ asChild+ >+ <Badge variant="outline" className="h-6 rounded-full px-2">+ 1m+ </Badge>+ </Button>+ <Button+ size="sm"+ variant={watchDowntime === "1h" ? "default" : "outline"}+ onClick={() => form.setValue("downtime", "1h")}+ asChild+ >+ <Badge variant="outline" className="h-6 rounded-full px-2">+ 1h+ </Badge>+ </Button>+ <Button+ size="sm"+ variant={watchDowntime === "1h 30m" ? "default" : "outline"}+ onClick={() => form.setValue("downtime", "1h 30m")}+ asChild+ >+ <Badge variant="outline" className="h-6 rounded-full px-2">+ 1h 30m+ </Badge>+ </Button>+ <Button+ size="sm"+ variant={watchDowntime === "1d" ? "default" : "outline"}+ onClick={() => form.setValue("downtime", "1d")}+ asChild+ >+ <Badge variant="outline" className="h-6 rounded-full px-2">+ 1d+ </Badge>+ </Button>+ </div>+ </div>+ </div>+ <div>+ <ul className="list-inside list-disc marker:text-muted-foreground/50">+ {periods.map((period) => {+ const downtimeSeconds = parseDowntimeToSeconds(watchDowntime);+ const periodSeconds = periodsInSeconds[period];+ const uptimePercentage = calculateUptimePercentage(+ downtimeSeconds,+ periodSeconds,+ );++ return (+ <li key={period}>+ <span className="text-muted-foreground capitalize">+ {period} reporting:+ </span>{" "}+ <span className="font-medium">+ {uptimePercentage.toFixed(5)}%{" "}+ <span className="text-muted-foreground">uptime</span>+ </span>+ </li>+ );+ })}+ </ul>+ </div>+ </TabsContent>+ </Tabs>+ </form>+ </Form>+ );+}diff --git a/apps/web/src/app/(pages)/(content)/play/uptime-sla/layout.tsx b/apps/web/src/app/(pages)/(content)/play/uptime-sla/layout.tsxnew file mode 100644index 000000000..493466360--- /dev/null+++ b/apps/web/src/app/(pages)/(content)/play/uptime-sla/layout.tsx@@ -0,0 +1,31 @@+import {+ Breadcrumb,+ BreadcrumbItem,+ BreadcrumbLink,+ BreadcrumbList,+ BreadcrumbPage,+ BreadcrumbSeparator,+} from "@openstatus/ui";+import Link from "next/link";+import type React from "react";++export default function Layout({ children }: { children: React.ReactNode }) {+ return (+ <>+ <Breadcrumb className="mb-4 px-3 md:px-6">+ <BreadcrumbList>+ <BreadcrumbItem>+ <BreadcrumbLink asChild>+ <Link href="/play">Play</Link>+ </BreadcrumbLink>+ </BreadcrumbItem>+ <BreadcrumbSeparator />+ <BreadcrumbItem>+ <BreadcrumbPage>Uptime SLA Calculator</BreadcrumbPage>+ </BreadcrumbItem>+ </BreadcrumbList>+ </Breadcrumb>+ {children}+ </>+ );+}diff --git a/apps/web/src/app/(pages)/(content)/play/uptime-sla/page.tsx b/apps/web/src/app/(pages)/(content)/play/uptime-sla/page.tsxnew file mode 100644index 000000000..1989349bf--- /dev/null+++ b/apps/web/src/app/(pages)/(content)/play/uptime-sla/page.tsx@@ -0,0 +1,97 @@+import {+ defaultMetadata,+ ogMetadata,+ twitterMetadata,+} from "@/app/shared-metadata";+import { Shell } from "@/components/dashboard/shell";+import {+ CardContainer,+ CardDescription,+ CardHeader,+ CardIcon,+ CardTitle,+} from "@/components/marketing/card";+import { BottomCTA } from "@/components/marketing/in-between-cta";+import type { Metadata } from "next";+import { UptimeSLAForm } from "./_components/uptime-sla-form";++const title = "Uptime SLA Calculator";+const description =+ "Calculate uptime SLA percentages, allowed downtime, and service availability metrics. Free tool for monitoring uptime across days, weeks, months, and years. Perfect for SLA planning and compliance.";++export const metadata: Metadata = {+ ...defaultMetadata,+ title,+ description,+ twitter: {+ ...twitterMetadata,+ title,+ description,+ images: [`/api/og?title=${title}&description=${description}`],+ },+ openGraph: {+ ...ogMetadata,+ title,+ description,+ images: [`/api/og?title=${title}&description=${description}`],+ },+};++export default function CurlBuilder() {+ return (+ <div className="grid h-full w-full gap-12">+ <CardContainer>+ <CardHeader>+ <CardIcon icon="shield-check" />+ <CardTitle>Uptime SLA Calculator</CardTitle>+ <CardDescription className="max-w-md">+ Calculate allowed downtime from uptime percentages or determine+ uptime percentages from actual downtime. Supports multiple reporting+ periods and SLA tiers.+ </CardDescription>+ </CardHeader>+ <div className="mx-auto grid w-full max-w-xl gap-8">+ <UptimeSLAForm+ defaultValues={{+ uptime: 99.99,+ downtime: "1m",+ }}+ />+ <p className="text-center text-muted-foreground text-sm">+ All calculations assume continuous 24/7 availability requirements.+ </p>+ </div>+ </CardContainer>+ <Informations />+ <BottomCTA />+ </div>+ );+}++//+function Informations() {+ return (+ <Shell>+ <div className="grid gap-1">+ <h3 className="font-semibold">Understanding Uptime SLA</h3>+ <p className="text-muted-foreground">+ Service Level Agreements (SLAs) define the expected performance and+ availability of your services. Understanding uptime percentages and+ their corresponding downtime allowances is crucial for maintaining+ customer trust and meeting compliance requirements.+ </p>+ <p className="text-muted-foreground">+ Common SLA tiers include 99.9% (three nines), 99.99% (four nines), and+ 99.999% (five nines), each representing different levels of+ reliability. For example, 99.9% uptime allows for 8.77 hours of+ downtime per year, while 99.99% allows only 52.6 minutes annually.+ </p>+ <p className="text-muted-foreground">+ This calculator helps you understand the real-world impact of your SLA+ commitments and plan for capacity, incident response, and stakeholder+ expectations.+ </p>+ </div>+ </Shell>+ );+}diff --git a/apps/web/src/components/icons.tsx b/apps/web/src/components/icons.tsxindex 530d1f70a..b425cea33 100644--- a/apps/web/src/components/icons.tsx+++ b/apps/web/src/components/icons.tsx@@ -52,6 +52,7 @@ import {Search,SearchCheck,Server,+ ShieldCheck,Siren,Sparkles,SunMedium,@@ -140,6 +141,7 @@ export const Icons = {user: UserCircle,camera: Camera,"book-open-check": BookOpenCheck,+ "shield-check": ShieldCheck,info: Info,server: Server,command: Command,diff --git a/apps/web/src/components/layout/marketing-footer.tsx b/apps/web/src/components/layout/marketing-footer.tsxindex f09701ae5..69af13bb4 100644--- a/apps/web/src/components/layout/marketing-footer.tsx+++ b/apps/web/src/components/layout/marketing-footer.tsx@@ -80,6 +80,7 @@ export function MarketingFooter({ className }: Props) {<FooterLink href="/play" label="Playground" /><FooterLink href="/play/checker" label="Speed Checker" /><FooterLink href="/play/curl" label="cURL Builder" />+ <FooterLink href="/play/uptime-sla" label="Uptime SLA Calculator" /><FooterLink href="https://openstat.us" label="All Status Codes" /><FooterLinkhref="https://light.openstatus.dev"