Skip to content

Open-source status page, incident response and uptime monitoring

Docs/status widget (#356)

Maximilian Kaskeefb7d0279327
diff --git a/apps/docs/pages/_meta.json b/apps/docs/pages/_meta.json
index ac043ec61..de3461a4e 100644
--- a/apps/docs/pages/_meta.json
+++ b/apps/docs/pages/_meta.json
@@ -3,7 +3,7 @@
"getting-started": "Getting started",
"integrations": "Integrations",
"developer-guide": "Developer guide",
- "rest-api": "API",
+ "api-server": "API",
"contact": {
"title": "🌐 Website",
"type": "page",
diff --git a/apps/docs/pages/api-server/_meta.json b/apps/docs/pages/api-server/_meta.json
new file mode 100644
index 000000000..5ec11d9a1
--- /dev/null
+++ b/apps/docs/pages/api-server/_meta.json
@@ -0,0 +1,5 @@
+{
+ "auth": "Auth Token",
+ "openapi": "OpenAPI Specs",
+ "status-widget": "Status Widget"
+}
\ No newline at end of file
diff --git a/apps/docs/pages/rest-api/auth.mdx b/apps/docs/pages/api-server/auth.mdx
similarity index 90%
rename from apps/docs/pages/rest-api/auth.mdx
rename to apps/docs/pages/api-server/auth.mdx
index 6ba8e8d5f..cd7188599 100644
--- a/apps/docs/pages/rest-api/auth.mdx
+++ b/apps/docs/pages/api-server/auth.mdx
@@ -19,7 +19,7 @@ const monitors = await fetch(`https://api.openstatus.dev/v1/monitors`, {
Use the above snippet to try it out.
-Learn more about [all the endpoints](/rest-api/openapi) we provide.
+Learn more about [all the endpoints](/api-server/openapi) we provide.
We currently do not have an SDK to make the best out of it. Any contributions
are welcome.
diff --git a/apps/docs/pages/rest-api/openapi.mdx b/apps/docs/pages/api-server/openapi.mdx
similarity index 100%
rename from apps/docs/pages/rest-api/openapi.mdx
rename to apps/docs/pages/api-server/openapi.mdx
diff --git a/apps/docs/pages/api-server/status-widget.mdx b/apps/docs/pages/api-server/status-widget.mdx
new file mode 100644
index 000000000..08f4ccc96
--- /dev/null
+++ b/apps/docs/pages/api-server/status-widget.mdx
@@ -0,0 +1,136 @@
+# Public Status Widget
+
+We have added a public endpoint where you can access the status of your status
+page. To access it, you only need the unique `:slug` you have chosen for your
+page.
+
+```bash
+curl https://api.openstatus.dev/public/status/:slug
+```
+
+The response is a JSON object with the following structure:
+
+```json
+{ "status": "operational" }
+```
+
+in which the status can be one of the following values:
+
+```ts
+enum Status {
+ Operational = "operational",
+ DegradedPerformance = "degraded_performance",
+ PartialOutage = "partial_outage",
+ MajorOutage = "major_outage",
+ UnderMaintenance = "under_maintenance", // currently not in use
+ Unknown = "unknown",
+}
+```
+
+### How does it work?
+
+The status is calculated by the ratio `uptime / (uptime + downtime)` of the last
+5 cron jobs of each monitor which we accumulate together. It is a simple
+calculation that gives us a good overview of the status of your services.
+
+```ts
+function getStatus(ratio: number) {
+ if (isNaN(ratio)) return Status.Unknown;
+ if (ratio >= 0.98) return Status.Operational;
+ if (ratio >= 0.6) return Status.DegradedPerformance;
+ if (ratio >= 0.3) return Status.PartialOutage;
+ if (ratio >= 0) return Status.MajorOutage;
+ return Status.Unknown;
+}
+```
+
+We are caching the result for `30 seconds` to reduce the load on our database.
+
+> If you have a doubt about the above calculation, feel free to contact us via
+> [discord](https://openstatus.dev/discord).
+
+### React Widget
+
+We currently do not provide any SDK or package to integrate the status into your
+stack. But will in the future.
+
+If you are using Nextjs and RSC with the `/app` directory, feel free to use that
+Component. Small reminder that we are using shadcn ui and tailwindcss. You might
+want to update the `bg-muted` and `text-foreground` classes to your needs.
+
+![Status Widget](/img/status-widget/widget-example.png)
+
+We are using `zod` to validate the response. You can use any other library if
+you want or just remove it. But better be safe than sorry.
+
+```tsx
+import * as z from "zod";
+
+const statusEnum = z.enum([
+ "operational",
+ "degraded_performance",
+ "partial_outage",
+ "major_outage",
+ "under_maintenance", // currently not in use
+ "unknown",
+]);
+
+const statusSchema = z.object({ status: statusEnum });
+
+const dictionary = {
+ operational: {
+ label: "Operational",
+ color: "bg-green-500",
+ },
+ degraded_performance: {
+ label: "Degraded Performance",
+ color: "bg-yellow-500",
+ },
+ partial_outage: {
+ label: "Partial Outage",
+ color: "bg-yellow-500",
+ },
+ major_outage: {
+ label: "Major Outage",
+ color: "bg-red-500",
+ },
+ unknown: {
+ label: "Unknown",
+ color: "bg-gray-500",
+ },
+ under_maintenance: {
+ label: "Under Maintenance",
+ color: "bg-gray-500",
+ },
+} as const;
+
+export async function StatusWidget({ slug }: { slug: string }) {
+ const res = await fetch(`https://api.openstatus.dev/public/status/${slug}`, {
+ next: { revalidate: 60 }, // cache request for 60 seconds
+ });
+ const data = await res.json();
+ const parsed = statusSchema.safeParse(data);
+
+ let label = "Unknown";
+ let color = "bg-gray-500";
+
+ if (parsed.success) {
+ const status = dictionary[parsed.data.status];
+ label = status.label;
+ color = status.color;
+ }
+
+ return (
+ <a
+ className="border-border text-foreground/70 hover:bg-muted hover:text-foreground inline-flex max-w-fit items-center gap-2 rounded-md border px-3 py-1 text-sm"
+ href={`https://${slug}.openstatus.dev`}
+ target="_blank"
+ rel="noreferrer"
+ >
+ {label}
+ <span className={`inline-block h-2 w-2 rounded-full ${color}`} />
+ </a>
+ );
+}
+```
diff --git a/apps/docs/pages/rest-api/_meta.json b/apps/docs/pages/rest-api/_meta.json
deleted file mode 100644
index d49132243..000000000
--- a/apps/docs/pages/rest-api/_meta.json
+++ /dev/null
@@ -1,4 +0,0 @@
-{
- "auth": "Auth Token",
- "openapi": "OpenAPI Specs"
-}
\ No newline at end of file
diff --git a/apps/docs/public/img/status-widget/widget-example.png b/apps/docs/public/img/status-widget/widget-example.png
new file mode 100644
index 000000000..25c87a619
Binary files /dev/null and b/apps/docs/public/img/status-widget/widget-example.png differ
diff --git a/apps/docs/public/sitemap-0.xml b/apps/docs/public/sitemap-0.xml
index 6e6fbc495..8be9bdcc7 100644
--- a/apps/docs/public/sitemap-0.xml
+++ b/apps/docs/public/sitemap-0.xml
@@ -1,24 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
-<url><loc>https://docs.openstatus.dev</loc><lastmod>2023-10-02T15:53:57.199Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
-<url><loc>https://docs.openstatus.dev/developer-guide/get-started</loc><lastmod>2023-10-02T15:53:57.199Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
-<url><loc>https://docs.openstatus.dev/developer-guide/requirements</loc><lastmod>2023-10-02T15:53:57.199Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
-<url><loc>https://docs.openstatus.dev/developer-guide/setup</loc><lastmod>2023-10-02T15:53:57.199Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
-<url><loc>https://docs.openstatus.dev/developer-guide/setup-env</loc><lastmod>2023-10-02T15:53:57.199Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
-<url><loc>https://docs.openstatus.dev/getting-started</loc><lastmod>2023-10-02T15:53:57.199Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
-<url><loc>https://docs.openstatus.dev/getting-started/alerting</loc><lastmod>2023-10-02T15:53:57.199Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
-<url><loc>https://docs.openstatus.dev/getting-started/heartbeat</loc><lastmod>2023-10-02T15:53:57.199Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
-<url><loc>https://docs.openstatus.dev/getting-started/monitor</loc><lastmod>2023-10-02T15:53:57.199Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
-<url><loc>https://docs.openstatus.dev/getting-started/status-page</loc><lastmod>2023-10-02T15:53:57.199Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
-<url><loc>https://docs.openstatus.dev/integrations</loc><lastmod>2023-10-02T15:53:57.199Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
-<url><loc>https://docs.openstatus.dev/integrations/discord</loc><lastmod>2023-10-02T15:53:57.199Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
-<url><loc>https://docs.openstatus.dev/integrations/fly</loc><lastmod>2023-10-02T15:53:57.199Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
-<url><loc>https://docs.openstatus.dev/integrations/otel</loc><lastmod>2023-10-02T15:53:57.199Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
-<url><loc>https://docs.openstatus.dev/integrations/phone-call</loc><lastmod>2023-10-02T15:53:57.199Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
-<url><loc>https://docs.openstatus.dev/integrations/slack</loc><lastmod>2023-10-02T15:53:57.200Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
-<url><loc>https://docs.openstatus.dev/integrations/sms</loc><lastmod>2023-10-02T15:53:57.200Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
-<url><loc>https://docs.openstatus.dev/integrations/telegram</loc><lastmod>2023-10-02T15:53:57.200Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
-<url><loc>https://docs.openstatus.dev/integrations/vercel</loc><lastmod>2023-10-02T15:53:57.200Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
-<url><loc>https://docs.openstatus.dev/rest-api/auth</loc><lastmod>2023-10-02T15:53:57.200Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
-<url><loc>https://docs.openstatus.dev/rest-api/openapi</loc><lastmod>2023-10-02T15:53:57.200Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
+<url><loc>https://docs.openstatus.dev</loc><lastmod>2023-10-04T17:44:38.856Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
+<url><loc>https://docs.openstatus.dev/api-server/status-widget</loc><lastmod>2023-10-04T17:44:38.856Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
</urlset>
\ No newline at end of file
diff --git a/apps/server/src/public/status.ts b/apps/server/src/public/status.ts
index 0707615fc..814b86fbd 100644
--- a/apps/server/src/public/status.ts
+++ b/apps/server/src/public/status.ts
@@ -41,7 +41,7 @@ status.get("/:slug", async (c) => {
monitorData.map(async ({ monitors_to_pages }) => {
return await getMonitorList(tb)({
monitorId: String(monitors_to_pages.monitorId),
- limit: 3, // limits the grouped cronTimestamps
+ limit: 5, // limits the grouped cronTimestamps
});
}),
);
diff --git a/apps/web/src/components/layout/marketing-footer.tsx b/apps/web/src/components/layout/marketing-footer.tsx
index 508282ec3..57173c429 100644
--- a/apps/web/src/components/layout/marketing-footer.tsx
+++ b/apps/web/src/components/layout/marketing-footer.tsx
@@ -1,6 +1,7 @@
import Link from "next/link";
import { ArrowUpRight } from "lucide-react";
+import { StatusWidget } from "@/components/status-widget";
import { cn } from "@/lib/utils";
import { Shell } from "../dashboard/shell";
@@ -11,33 +12,36 @@ interface Props {
export function MarketingFooter({ className }: Props) {
return (
<footer className={cn("w-full", className)}>
- <Shell className="grid grid-cols-2 gap-6 md:grid-cols-4">
- <div className="flex flex-col gap-3 text-sm">
- <p className="text-foreground font-semibold">People</p>
- <FooterLink
- href="https://twitter.com/thibaultleouay"
- label="@thibaultleouay"
- />
- <FooterLink href="https://twitter.com/mxkaske" label="@mxkaske" />
- </div>
- <div className="flex flex-col gap-3 text-sm">
- <p className="text-foreground font-semibold">Community</p>
- <FooterLink href="/github" label="GitHub" external />
- <FooterLink href="/discord" label="Discord" external />
- <FooterLink href="https://twitter.com/openstatusHQ" label="X" />
- </div>
- <div className="flex flex-col gap-3 text-sm">
- <p className="text-foreground font-semibold">Resources</p>
- <FooterLink href="https://status.openstatus.dev" label="Status" />
- <FooterLink href="/blog" label="Blog" />
- <FooterLink href="https://docs.openstatus.dev" label="Docs" />
- <FooterLink href="/oss-friends" label="OSS Friends" />
- </div>
- <div className="flex flex-col gap-3 text-sm">
- <p className="text-foreground font-semibold">Legal</p>
- <FooterLink href="/legal/terms" label="Terms" />
- <FooterLink href="/legal/privacy" label="Privacy" />
+ <Shell className="grid gap-6">
+ <div className="grid grid-cols-2 gap-6 md:grid-cols-4">
+ <div className="flex flex-col gap-3 text-sm">
+ <p className="text-foreground font-semibold">People</p>
+ <FooterLink
+ href="https://twitter.com/thibaultleouay"
+ label="@thibaultleouay"
+ />
+ <FooterLink href="https://twitter.com/mxkaske" label="@mxkaske" />
+ </div>
+ <div className="flex flex-col gap-3 text-sm">
+ <p className="text-foreground font-semibold">Community</p>
+ <FooterLink href="/github" label="GitHub" external />
+ <FooterLink href="/discord" label="Discord" external />
+ <FooterLink href="https://twitter.com/openstatusHQ" label="X" />
+ </div>
+ <div className="flex flex-col gap-3 text-sm">
+ <p className="text-foreground font-semibold">Resources</p>
+ <FooterLink href="https://status.openstatus.dev" label="Status" />
+ <FooterLink href="/blog" label="Blog" />
+ <FooterLink href="https://docs.openstatus.dev" label="Docs" />
+ <FooterLink href="/oss-friends" label="OSS Friends" />
+ </div>
+ <div className="flex flex-col gap-3 text-sm">
+ <p className="text-foreground font-semibold">Legal</p>
+ <FooterLink href="/legal/terms" label="Terms" />
+ <FooterLink href="/legal/privacy" label="Privacy" />
+ </div>
</div>
+ <StatusWidget slug="status" />
</Shell>
</footer>
);
diff --git a/apps/web/src/components/marketing/partners.tsx b/apps/web/src/components/marketing/partners.tsx
index 9de6c01fa..375fa2f6b 100644
--- a/apps/web/src/components/marketing/partners.tsx
+++ b/apps/web/src/components/marketing/partners.tsx
@@ -2,11 +2,11 @@ import { ArrowUpRight } from "lucide-react";
export function Partners() {
return (
- <div className="grid gap-2">
+ <div className="grid gap-4">
<h3 className="text-muted-foreground font-cal text-center text-sm">
Trusted By
</h3>
- <div className="grid grid-cols-1 gap-8 sm:grid-cols-3 sm:gap-16">
+ <div className="grid grid-cols-1 gap-8 sm:grid-cols-4 sm:gap-16">
<div className="flex items-center justify-center">
<a
href="https://status.hanko.io"
@@ -53,10 +53,7 @@ export function Partners() {
</a>
</div>
<div className="flex items-center justify-center">
- {/* <p className="text-muted-foreground text-xs">You</p> */}
- </div>
- <div className="flex items-center justify-center">
- <p className="text-muted-foreground text-md">You</p>
+ <p className="text-muted-foreground text-sm">You</p>
</div>
</div>
</div>
diff --git a/apps/web/src/components/status-widget.tsx b/apps/web/src/components/status-widget.tsx
new file mode 100644
index 000000000..255ac8361
--- /dev/null
+++ b/apps/web/src/components/status-widget.tsx
@@ -0,0 +1,67 @@
+import * as z from "zod";
+
+const statusEnum = z.enum([
+ "operational",
+ "degraded_performance",
+ "partial_outage",
+ "major_outage",
+ "unknown",
+]);
+
+const statusSchema = z.object({ status: statusEnum });
+
+const dictionary = {
+ operational: {
+ label: "Operational",
+ color: "bg-green-500",
+ },
+ degraded_performance: {
+ label: "Degraded Performance",
+ color: "bg-yellow-500",
+ },
+ partial_outage: {
+ label: "Partial Outage",
+ color: "bg-yellow-500",
+ },
+ major_outage: {
+ label: "Major Outage",
+ color: "bg-red-500",
+ },
+ unknown: {
+ label: "Unknown",
+ color: "bg-gray-500",
+ },
+ under_maintenance: {
+ label: "Under Maintenance",
+ color: "bg-gray-500",
+ },
+} as const;
+
+export async function StatusWidget({ slug }: { slug: string }) {
+ const res = await fetch(`https://api.openstatus.dev/public/status/${slug}`, {
+ next: { revalidate: 60 }, // cache request for 60 seconds
+ });
+ const data = await res.json();
+ const parsed = statusSchema.safeParse(data);
+
+ let label = "Unknown";
+ let color = "bg-gray-500";
+
+ if (parsed.success) {
+ const status = dictionary[parsed.data.status];
+ label = status.label;
+ color = status.color;
+ }
+
+ return (
+ <a
+ className="border-border text-foreground/70 hover:bg-muted hover:text-foreground inline-flex max-w-fit items-center gap-2 rounded-md border px-3 py-1 text-sm"
+ href={`https://${slug}.openstatus.dev`}
+ target="_blank"
+ rel="noreferrer"
+ >
+ {label}
+ <span className={`inline-block h-2 w-2 rounded-full ${color}`} />
+ </a>
+ );
+}