Skip to content

Open-source status page, incident response and uptime monitoring

feat: improve og image and status-page (#68)

Maximilian Kaske7010014a5eb9
diff --git a/apps/web/src/app/api/og/route.tsx b/apps/web/src/app/api/og/route.tsx
index 5afc025e4..0b19455db 100644
--- a/apps/web/src/app/api/og/route.tsx
+++ b/apps/web/src/app/api/og/route.tsx
@@ -1,5 +1,8 @@
import { ImageResponse } from "next/server";
+import { getMonitorListData } from "@/lib/tb";
+import { cn, formatDate } from "@/lib/utils";
+
export const runtime = "edge";
const size = {
@@ -9,24 +12,52 @@ const size = {
const TITLE = "Open Status";
const DESCRIPTION = "An Open Source Alternative for your next Status Page";
+const LIMIT = 40;
const interRegular = fetch(
new URL("../../../public/fonts/Inter-Regular.ttf", import.meta.url),
).then((res) => res.arrayBuffer());
+const interLight = fetch(
+ new URL("../../../public/fonts/Inter-Light.ttf", import.meta.url),
+).then((res) => res.arrayBuffer());
+
const calSemiBold = fetch(
new URL("../../../public/fonts/CalSans-SemiBold.ttf", import.meta.url),
).then((res) => res.arrayBuffer());
export async function GET(req: Request) {
const interRegularData = await interRegular;
+ const interLightData = await interLight;
const calSemiBoldData = await calSemiBold;
const { searchParams } = new URL(req.url);
+
const title = searchParams.has("title") ? searchParams.get("title") : TITLE;
const description = searchParams.has("description")
? searchParams.get("description")
: DESCRIPTION;
+ const monitorId = searchParams.has("monitorId")
+ ? searchParams.get("monitorId")
+ : undefined;
+
+ const data =
+ (monitorId &&
+ (await getMonitorListData({
+ siteId: monitorId,
+ groupBy: "day",
+ limit: LIMIT,
+ }))) ||
+ [];
+
+ const uptime = data?.reduce(
+ (prev, curr) => {
+ prev.ok += curr.ok;
+ prev.count += curr.count;
+ return prev;
+ },
+ { ok: 0, count: 0 },
+ );
return new ImageResponse(
(
@@ -36,15 +67,61 @@ export async function GET(req: Request) {
// not every css variable is supported
style={{
backgroundImage: "radial-gradient(#cbd5e1 10%, transparent 10%)",
- backgroundSize: "32px 32px",
- filter: "blur(1px)", // to be discussed... couldn't put it inside the content container
+ backgroundSize: "24px 24px",
}}
></div>
- <div tw="max-w-2xl relative flex flex-col items-center rounded-lg border border-slate-200 p-6 overflow-hidden bg-white bg-opacity-80">
- <h1 style={{ fontFamily: "Cal" }} tw="text-6xl text-center">
+ <div
+ tw="flex w-full h-full absolute inset-0 opacity-70"
+ style={{
+ backgroundColor: "white",
+ backgroundImage:
+ "radial-gradient(farthest-corner at 100px 100px, #64748b, white 70%)", // tbd: switch color position
+ }}
+ ></div>
+ <div tw="max-w-4xl relative flex flex-col">
+ <h1 style={{ fontFamily: "Cal" }} tw="text-6xl">
{title}
</h1>
- <p tw="text-slate-600 text-3xl text-center">{description}</p>
+ <p tw="text-slate-600 text-3xl">{description}</p>
+ {data && data.length > 0 ? (
+ <div tw="flex flex-col w-full mt-6">
+ <div tw="flex flex-row items-center justify-between -mb-1 text-black font-light">
+ <p tw="">{formatDate(new Date())}</p>
+ <p tw="mr-1">
+ {((uptime.ok / uptime.count) * 100).toFixed(2)}% uptime
+ </p>
+ </div>
+ <div tw="flex flex-row relative">
+ {/* Empty State */}
+ {new Array(LIMIT).fill(null).map((_, i) => {
+ return (
+ <div
+ key={i}
+ tw="h-16 w-2.5 rounded-full mr-1 bg-black/20"
+ ></div>
+ );
+ })}
+ <div tw="flex flex-row absolute right-0">
+ {data.map((item, i) => {
+ const status = item.ok / item.count === 1 ? "up" : "down"; // needs to be better defined!
+ return (
+ <div
+ key={i}
+ tw={cn("h-16 w-2.5 rounded-full mr-1", {
+ "bg-green-600": status === "up",
+ "bg-red-600": status === "down",
+ })}
+ ></div>
+ );
+ })}
+ </div>
+ </div>
+ <div tw="flex flex-row items-center justify-between -mt-3 text-slate-500 text-sm">
+ <p tw="">{LIMIT} days ago</p>
+ <p tw="mr-1">today</p>
+ </div>
+ </div>
+ ) : null}
</div>
</div>
),
@@ -57,6 +134,12 @@ export async function GET(req: Request) {
style: "normal",
weight: 400,
},
+ {
+ name: "Inter",
+ data: interLightData,
+ style: "normal",
+ weight: 300,
+ },
{
name: "Cal",
data: calSemiBoldData,
diff --git a/apps/web/src/app/play/layout.tsx b/apps/web/src/app/play/layout.tsx
index 79876349d..cf8126c85 100644
--- a/apps/web/src/app/play/layout.tsx
+++ b/apps/web/src/app/play/layout.tsx
@@ -1,8 +1,18 @@
import * as React from "react";
+import type { Metadata } from "next";
import { BackButton } from "@/components/layout/back-button";
import { Footer } from "@/components/layout/footer";
+export const metadata: Metadata = {
+ twitter: {
+ images: [`/api/og?monitorId=openstatus`],
+ },
+ openGraph: {
+ images: [`/api/og?monitorId=openstatu`],
+ },
+};
+
export default function PlayLayout({
children,
modal,
diff --git a/apps/web/src/app/status-page/[domain]/layout.tsx b/apps/web/src/app/status-page/[domain]/layout.tsx
index d663a6fed..641ed258c 100644
--- a/apps/web/src/app/status-page/[domain]/layout.tsx
+++ b/apps/web/src/app/status-page/[domain]/layout.tsx
@@ -4,10 +4,23 @@ export default function StatusPageLayout({
children: React.ReactNode;
}) {
return (
- <main className="flex min-h-screen w-full flex-col space-y-6 p-4 md:p-8">
- <div className="flex flex-1 flex-col items-center justify-center gap-8">
- <div className="mx-auto max-w-xl text-center">{children}</div>
- </div>
- </main>
+ <div className="flex min-h-screen w-full flex-col space-y-6 p-4 md:p-8">
+ <main className="flex flex-1 flex-col items-center justify-center gap-8">
+ <div className="mx-auto w-full max-w-xl text-center">{children}</div>
+ </main>
+ <footer className="z-10">
+ <p className="text-muted-foreground text-center text-sm">
+ powered by{" "}
+ <a
+ href="https://openstatus.dev"
+ target="_blank"
+ rel="noreferrer"
+ className="text-foreground underline underline-offset-4 hover:no-underline"
+ >
+ openstatus.dev
+ </a>
+ </p>
+ </footer>
+ </div>
);
}
diff --git a/apps/web/src/app/status-page/[domain]/loading.tsx b/apps/web/src/app/status-page/[domain]/loading.tsx
new file mode 100644
index 000000000..fa099d16f
--- /dev/null
+++ b/apps/web/src/app/status-page/[domain]/loading.tsx
@@ -0,0 +1,17 @@
+import { Container } from "@/components/dashboard/container";
+import { Header } from "@/components/dashboard/header";
+import { Shell } from "@/components/dashboard/shell";
+
+export default function StatusPageLoading() {
+ return (
+ <Shell>
+ <div className="grid gap-6">
+ <Header.Skeleton />
+ <div className="grid gap-4">
+ <Container.Skeleton />
+ <Container.Skeleton />
+ </div>
+ </div>
+ </Shell>
+ );
+}
diff --git a/apps/web/src/app/status-page/[domain]/page.tsx b/apps/web/src/app/status-page/[domain]/page.tsx
index 85f5ba920..99cae098f 100644
--- a/apps/web/src/app/status-page/[domain]/page.tsx
+++ b/apps/web/src/app/status-page/[domain]/page.tsx
@@ -16,8 +16,12 @@ export default async function Page({ params }: { params: { domain: string } }) {
return (
<Shell>
- <div className="grid gap-4">
- <Header title={page.title} description={page.description} />
+ <div className="grid gap-6">
+ <Header
+ title={page.title}
+ description={page.description}
+ className="max-w-lg"
+ />
<MonitorList monitors={page.monitors} />
</div>
</Shell>
diff --git a/apps/web/src/components/monitor/tracker.tsx b/apps/web/src/components/monitor/tracker.tsx
index 3d9283a1c..b98d98284 100644
--- a/apps/web/src/components/monitor/tracker.tsx
+++ b/apps/web/src/components/monitor/tracker.tsx
@@ -37,16 +37,23 @@ const tracker = cva("h-10 w-1.5 sm:w-2 rounded-full md:w-2.5", {
interface TrackerProps {
data: Monitor[];
url: string;
- id: string;
+ id: string | number;
name: string;
/**
* Maximium length of the data array
*/
maxSize?: number;
+ context?: "play" | "status-page"; // TODO: we might need to extract those two different use cases - for now it's ok I'd say.
}
-// TODO: discusss to move data fetching inside of Tracker
-export function Tracker({ data, url, id, name, maxSize = 35 }: TrackerProps) {
+export function Tracker({
+ data,
+ url,
+ id,
+ name,
+ maxSize = 35,
+ context = "play",
+}: TrackerProps) {
const slicedData = data.slice(0, maxSize).reverse();
const placeholderData: null[] = Array(maxSize).fill(null);
@@ -69,7 +76,7 @@ export function Tracker({ data, url, id, name, maxSize = 35 }: TrackerProps) {
<div className="mb-1 flex justify-between text-sm sm:mb-2">
<div className="flex items-center gap-2">
<p className="text-foreground font-semibold">{name}</p>
- <MoreInfo {...{ url, id }} />
+ <MoreInfo {...{ url, id, context }} />
</div>
<p className="text-muted-foreground font-light">
{`${totalUptime}%`} uptime
@@ -83,7 +90,9 @@ export function Tracker({ data, url, id, name, maxSize = 35 }: TrackerProps) {
</div>
<div className="absolute right-0 top-0 flex gap-0.5">
{slicedData.map((props) => {
- return <Bar key={props.cronTimestamp} {...props} />;
+ return (
+ <Bar key={props.cronTimestamp} context={context} {...props} />
+ );
})}
</div>
</div>
@@ -91,9 +100,14 @@ export function Tracker({ data, url, id, name, maxSize = 35 }: TrackerProps) {
);
}
-const MoreInfo = ({ url, id }: Record<"id" | "url", string>) => {
+const MoreInfo = ({
+ url,
+ id,
+ context,
+}: Pick<TrackerProps, "url" | "id" | "context">) => {
const [open, setOpen] = React.useState(false);
const formattedURL = new URL(url);
+ const link = `${formattedURL.host}${formattedURL.pathname}`;
return (
<TooltipProvider>
<Tooltip open={open} onOpenChange={setOpen}>
@@ -101,19 +115,28 @@ const MoreInfo = ({ url, id }: Record<"id" | "url", string>) => {
<Info className="h-4 w-4" />
</TooltipTrigger>
<TooltipContent>
- <Link
- href={`/monitor/${id}`}
- className="text-muted-foreground hover:text-foreground"
- >
- {`${formattedURL.host}${formattedURL.pathname}`}
- </Link>
+ <p className="text-muted-foreground">
+ {context === "play" ? (
+ <Link href={`/monitor/${id}`} className="hover:text-foreground">
+ {link}
+ </Link>
+ ) : (
+ link
+ )}
+ </p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
);
};
-const Bar = ({ count, ok, avgLatency, cronTimestamp }: Monitor) => {
+const Bar = ({
+ count,
+ ok,
+ avgLatency,
+ cronTimestamp,
+ context,
+}: Monitor & Pick<TrackerProps, "context">) => {
const [open, setOpen] = React.useState(false);
const ratio = ok / count;
const isOk = ratio === 1; // TODO: when operational, downtime, degraded
@@ -139,12 +162,14 @@ const Bar = ({ count, ok, avgLatency, cronTimestamp }: Monitor) => {
<p className="text-sm font-semibold">
{isOk ? "Operational" : "Downtime"}
</p>
- <Link
- href={`/monitor/openstatus?fromDate=${cronTimestamp}&toDate=${toDate}`}
- className="text-muted-foreground hover:text-foreground"
- >
- <Eye className="h-4 w-4" />
- </Link>
+ {context === "play" ? (
+ <Link
+ href={`/monitor/openstatus?fromDate=${cronTimestamp}&toDate=${toDate}`}
+ className="text-muted-foreground hover:text-foreground"
+ >
+ <Eye className="h-4 w-4" />
+ </Link>
+ ) : null}
</div>
<div className="flex justify-between">
<p className="text-xs font-light">
diff --git a/apps/web/src/components/status-page/monitor-list.tsx b/apps/web/src/components/status-page/monitor-list.tsx
index c336d4356..ceacc4503 100644
--- a/apps/web/src/components/status-page/monitor-list.tsx
+++ b/apps/web/src/components/status-page/monitor-list.tsx
@@ -10,7 +10,7 @@ export const MonitorList = ({
monitors: z.infer<typeof selectMonitorSchema>[];
}) => {
return (
- <div>
+ <div className="grid gap-4">
{monitors.map((monitor, index) => (
<div key={index}>
{/* Fetch tracker and data */}
diff --git a/apps/web/src/components/status-page/monitor.tsx b/apps/web/src/components/status-page/monitor.tsx
index c0d626bd9..f8a1ad686 100644
--- a/apps/web/src/components/status-page/monitor.tsx
+++ b/apps/web/src/components/status-page/monitor.tsx
@@ -10,21 +10,21 @@ export const Monitor = async ({
}: {
monitor: z.infer<typeof selectMonitorSchema>;
}) => {
- // fix this we should update our tinybird to fetch with pageId and monitorId
- // const data = await getMonitorListData({ siteId: String(monitor.pageId) });
- const data = await getMonitorListData({ siteId: "openstatus" });
+ const data = await getMonitorListData({
+ siteId: "openstatus", // TODO: use proper id
+ groupBy: "day",
+ });
if (!data) return <div>Something went wrong</div>;
return (
- <div className="border-border rounded-lg border p-8">
- <h1 className="font-cal mb-3 text-center text-2xl">Status</h1>
- <Tracker
- data={data}
- id="openstatus"
- name="Ping"
- url="https://openstatus.dev/api/ping"
- />
- </div>
+ <Tracker
+ data={data}
+ id={monitor.id}
+ name="Ping"
+ url="https://openstatus.dev/api/ping"
+ context="status-page"
+ maxSize={40}
+ />
);
};
diff --git a/apps/web/src/lib/utils.ts b/apps/web/src/lib/utils.ts
index 526181d8a..a109f460a 100644
--- a/apps/web/src/lib/utils.ts
+++ b/apps/web/src/lib/utils.ts
@@ -1,5 +1,6 @@
import { clsx } from "clsx";
import type { ClassValue } from "clsx";
+import { format } from "date-fns";
import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
@@ -9,3 +10,7 @@ export function cn(...inputs: ClassValue[]) {
export function wait(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
+
+export function formatDate(date: Date) {
+ return format(date, "dd/MM/yyyy");
+}
diff --git a/apps/web/src/middleware.ts b/apps/web/src/middleware.ts
index 66e157f20..04631969c 100644
--- a/apps/web/src/middleware.ts
+++ b/apps/web/src/middleware.ts
@@ -58,7 +58,7 @@ export default authMiddleware({
"/api/checker/regions/(.*)",
"/api/checker/cron/10m",
],
-
+ ignoredRoutes: ["/api/og"], // FIXME: we should check the `publicRoutes`
beforeAuth: before,
async afterAuth(auth, req, evt) {
// handle users who aren't authenticated
diff --git a/apps/web/src/public/fonts/Inter-Light.ttf b/apps/web/src/public/fonts/Inter-Light.ttf
new file mode 100644
index 000000000..9e265d890
Binary files /dev/null and b/apps/web/src/public/fonts/Inter-Light.ttf differ