Skip to content

Open-source status page, incident response and uptime monitoring

feat: improved region table charts (#644)

Maximilian Kaske223c15e9f338
diff --git a/apps/web/public/assets/changelog/dashboard-metrics-card.png b/apps/web/public/assets/changelog/dashboard-metrics-card.png
index 32d294d94..5e1b05d49 100644
Binary files a/apps/web/public/assets/changelog/dashboard-metrics-card.png and b/apps/web/public/assets/changelog/dashboard-metrics-card.png differ
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/_components/metrics-card.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/_components/metrics-card.tsx
index c49e95afb..aa741fa6b 100644
--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/_components/metrics-card.tsx
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/_components/metrics-card.tsx
@@ -30,7 +30,7 @@ const metricsCardVariants = cva("flex flex-col px-3 py-2 border rounded-lg", {
interface MetricsCardProps extends VariantProps<typeof metricsCardVariants> {
title: string;
- value?: number;
+ value?: number | null;
suffix: string;
/**
* Value indicating the change in the metric compared to the previous period.
@@ -62,9 +62,7 @@ export function MetricsCard({
<div className="flex flex-1 items-center gap-2">
<p className="flex">
<code className="mr-1 font-mono text-xl font-semibold empty:mr-0">
- {typeof value === "number"
- ? new Intl.NumberFormat().format(value)
- : null}
+ {formatNumber(value)}
</code>
<span className="text-muted-foreground self-center text-xs">
{suffix}
@@ -76,6 +74,12 @@ export function MetricsCard({
);
}
+export function formatNumber(value?: number | null) {
+ return typeof value === "number"
+ ? new Intl.NumberFormat().format(value)
+ : null;
+}
+
// --- DeltaBadge.tsx ---
const badgeVariants = cva("", {
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/_components/chart.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/_components/chart.tsx
index 90fda83a7..b4c396820 100644
--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/_components/chart.tsx
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/_components/chart.tsx
@@ -43,6 +43,7 @@ export function Chart({ data, regions }: ChartProps) {
curveType="monotone"
intervalType="equidistantPreserveStart"
customTooltip={customTooltip}
+ showAnimation={true}
/>
);
}
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/_components/combined-chart-wrapper.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/_components/combined-chart-wrapper.tsx
index 2f7fd4682..1993e03b8 100644
--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/_components/combined-chart-wrapper.tsx
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/_components/combined-chart-wrapper.tsx
@@ -4,17 +4,19 @@ import { useMemo, useState } from "react";
import { LineChart } from "lucide-react";
import type { Monitor } from "@openstatus/db/src/schema";
-import type { Region, ResponseGraph } from "@openstatus/tinybird";
+import type {
+ Region,
+ ResponseGraph,
+ ResponseTimeMetricsByRegion,
+} from "@openstatus/tinybird";
import { Toggle } from "@openstatus/ui";
-import { flyRegionsDict } from "@openstatus/utils";
-import { EmptyState } from "@/components/dashboard/empty-state";
import { IntervalPreset } from "../../_components/interval-preset";
import { QuantilePreset } from "../../_components/quantile-preset";
import { RegionsPreset } from "../../_components/region-preset";
import type { Interval, Period, Quantile } from "../../utils";
import { Chart } from "./chart";
-import { SimpleChart } from "./simple-chart";
+import { RegionTable } from "./region-table";
import { groupDataByTimestamp } from "./utils";
export function CombinedChartWrapper({
@@ -25,6 +27,7 @@ export function CombinedChartWrapper({
regions,
monitor,
isQuantileDisabled,
+ metricsByRegion,
}: {
data: ResponseGraph[];
period: Period;
@@ -33,6 +36,7 @@ export function CombinedChartWrapper({
regions: Region[];
monitor: Monitor;
isQuantileDisabled: boolean;
+ metricsByRegion: ResponseTimeMetricsByRegion[];
}) {
const chartData = useMemo(
() => groupDataByTimestamp(data, period, quantile),
@@ -40,9 +44,6 @@ export function CombinedChartWrapper({
);
const [combinedRegions, setCombinedRegions] = useState(false);
- const hasData = chartData.data.length > 0;
- const hasRegions = regions.length > 0;
-
return (
<>
<div className="flex flex-col gap-2 sm:flex-row sm:items-end sm:justify-between">
@@ -51,14 +52,13 @@ export function CombinedChartWrapper({
pressed={combinedRegions}
onPressedChange={setCombinedRegions}
variant="outline"
- disabled={!hasData}
>
<LineChart className="mr-2 h-4 w-4" />
- Combine Regions
+ {!combinedRegions ? "Combine regions" : "Split regions"}
</Toggle>
<RegionsPreset
regions={monitor.regions as Region[]}
- selectedRegions={regions as Region[]}
+ selectedRegions={regions}
/>
</div>
<div className="flex gap-2">
@@ -71,57 +71,13 @@ export function CombinedChartWrapper({
{combinedRegions ? (
<Chart data={chartData.data} regions={regions} />
) : (
- <div className="grid gap-1">
- {chartData.regions
- .filter((region) => regions.includes(region))
- .map((region) => {
- const { code, flag, location } = flyRegionsDict[region];
- return (
- <div key={region} className="flex items-end gap-2">
- <div className="grid w-24 gap-1">
- <p className="text-muted-foreground text-xs">
- {location}
- </p>
- <p className="font-mono text-xs">
- {flag} {code}
- </p>
- </div>
- <SimpleChart data={chartData.data} region={region} />
- </div>
- );
- })}
- </div>
+ <RegionTable
+ metricsByRegion={metricsByRegion}
+ regions={regions}
+ data={chartData}
+ />
)}
- <ChartEmptyState hasData={hasData} hasRegions={hasRegions} />
</div>
</>
);
}
-
-export function ChartEmptyState({
- hasData,
- hasRegions,
-}: {
- hasData: boolean;
- hasRegions: boolean;
-}) {
- if (!hasData) {
- return (
- <EmptyState
- icon="line-chart"
- title="No data available"
- description="There is no data available for the selected period."
- />
- );
- }
- if (!hasRegions) {
- return (
- <EmptyState
- icon="globe"
- title="No regions selected"
- description="Select at least one region to display the data."
- />
- );
- }
- return null;
-}
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/_components/region-table.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/_components/region-table.tsx
new file mode 100644
index 000000000..115f835c8
--- /dev/null
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/_components/region-table.tsx
@@ -0,0 +1,85 @@
+import type { Region, ResponseTimeMetricsByRegion } from "@openstatus/tinybird";
+import {
+ Table,
+ TableBody,
+ TableCaption,
+ TableCell,
+ TableHead,
+ TableHeader,
+ TableRow,
+} from "@openstatus/ui";
+import { flyRegionsDict } from "@openstatus/utils";
+
+import { formatNumber } from "../../_components/metrics-card";
+import { SimpleChart } from "./simple-chart";
+
+interface Props {
+ regions: Region[];
+ data: {
+ regions: Region[];
+ data: (Partial<Record<Region, string>> & { timestamp: string })[];
+ };
+ metricsByRegion: ResponseTimeMetricsByRegion[];
+}
+
+export function RegionTable({ regions, data, metricsByRegion }: Props) {
+ return (
+ <Table>
+ <TableCaption>A list of your regions.</TableCaption>
+ <TableHeader>
+ <TableRow>
+ <TableHead className="w-[100px]">Region</TableHead>
+ <TableHead className="min-w-[300px]">Trend</TableHead>
+ <TableHead className="w-[50px]">AVG</TableHead>
+ <TableHead className="w-[50px]">P95</TableHead>
+ <TableHead className="w-[50px]">P99</TableHead>
+ </TableRow>
+ </TableHeader>
+ <TableBody>
+ {regions
+ .filter((region) => regions.includes(region))
+ .map((region) => {
+ const { code, flag, location } = flyRegionsDict[region];
+ const metrics = metricsByRegion.find((m) => m.region === region);
+ return (
+ <TableRow key={region}>
+ <TableCell>
+ <p className="text-muted-foreground text-xs">{location}</p>
+ <p className="font-mono text-xs">
+ {flag} {code}
+ </p>
+ </TableCell>
+ <TableCell>
+ <SimpleChart data={data.data} region={region} />
+ </TableCell>
+ <TableCell className="text-right font-medium">
+ {formatNumber(metrics?.avgLatency)}
+ <span className="text-muted-foreground text-xs font-normal">
+ ms
+ </span>
+ </TableCell>
+ <TableCell className="text-right font-medium">
+ {formatNumber(metrics?.p95Latency)}
+ <span className="text-muted-foreground text-xs font-normal">
+ ms
+ </span>
+ </TableCell>
+ <TableCell className="text-right font-medium">
+ {formatNumber(metrics?.p99Latency)}
+ <span className="text-muted-foreground text-xs font-normal">
+ ms
+ </span>
+ </TableCell>
+ </TableRow>
+ );
+ })}
+ </TableBody>
+ {/* <TableFooter>
+ <TableRow>
+ <TableCell colSpan={4}>Total</TableCell>
+ <TableCell className="text-right">0</TableCell>
+ </TableRow>
+ </TableFooter> */}
+ </Table>
+ );
+}
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/_components/simple-chart.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/_components/simple-chart.tsx
index ced89bb32..f3b775aa8 100644
--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/_components/simple-chart.tsx
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/_components/simple-chart.tsx
@@ -27,6 +27,7 @@ export function SimpleChart({ data, region }: ChartProps) {
showGridLines={false}
showLegend={false}
customTooltip={customTooltip}
+ showAnimation={true}
/>
);
}
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/_components/utils.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/_components/utils.tsx
index c30e569b7..cac60b688 100644
--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/_components/utils.tsx
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/_components/utils.tsx
@@ -1,3 +1,5 @@
+import { format } from "date-fns";
+
import type { Region, ResponseGraph } from "@openstatus/tinybird";
import { regionsDict } from "@openstatus/utils";
@@ -64,14 +66,8 @@ export function groupDataByTimestamp(
*/
export function renderTimestamp(timestamp: number, period: Period) {
const isInDay = ["1h", "1d"].includes(period);
- return new Date(timestamp).toLocaleString("en-US", {
- year: !isInDay ? "numeric" : undefined,
- month: !isInDay ? "numeric" : undefined,
- day: !isInDay ? "numeric" : undefined,
- hour: "2-digit",
- minute: "2-digit",
- hour12: false,
- });
+ const date = new Date(timestamp);
+ return format(date, "MMM d, HH:mm");
}
export function dataFormatter(number: number) {
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/page.tsx
index fff454c84..7bde2471f 100644
--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/page.tsx
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/page.tsx
@@ -6,7 +6,11 @@ import { flyRegions } from "@openstatus/db/src/schema";
import type { Region } from "@openstatus/tinybird";
import { Separator } from "@openstatus/ui";
-import { getResponseGraphData, getResponseTimeMetricsData } from "@/lib/tb";
+import {
+ getResponseGraphData,
+ getResponseTimeMetricsByRegionData,
+ getResponseTimeMetricsData,
+} from "@/lib/tb";
import { api } from "@/trpc/server";
import { ButtonReset } from "../_components/button-reset";
import { DatePickerPreset } from "../_components/date-picker-preset";
@@ -93,7 +97,12 @@ export default async function Page({
interval: periodicityHours,
});
- if (!data || !metrics) return null;
+ const metricsByRegion = await getResponseTimeMetricsByRegionData({
+ monitorId: id,
+ interval: periodicityHours,
+ });
+
+ if (!data || !metrics || !metricsByRegion) return null;
const { period, quantile, interval, regions } = search.data;
@@ -119,6 +128,7 @@ export default async function Page({
regions={regions as Region[]}
monitor={monitor}
isQuantileDisabled={isQuantileDisabled}
+ metricsByRegion={metricsByRegion}
/>
</div>
);
diff --git a/apps/web/src/components/layout/marketing-footer.tsx b/apps/web/src/components/layout/marketing-footer.tsx
index c6880af78..305243135 100644
--- a/apps/web/src/components/layout/marketing-footer.tsx
+++ b/apps/web/src/components/layout/marketing-footer.tsx
@@ -23,7 +23,10 @@ export function MarketingFooter({ className }: Props) {
<BrandName />
<p className="text-muted-foreground mt-2 text-sm font-light">
We are on a mission to provide a reliable, easy and fast way to
- synthetically monitor your APIs and websites.
+ monitor your APIs and websites.{" "}
+ <span className="underline decoration-dotted underline-offset-2">
+ Let&apos;s end <code>us-east-1</code> privilege together.
+ </span>
</p>
</div>
<StatusWidgetContainer slug="status" />
diff --git a/apps/web/src/lib/tb.ts b/apps/web/src/lib/tb.ts
index 462760c82..6944e5298 100644
--- a/apps/web/src/lib/tb.ts
+++ b/apps/web/src/lib/tb.ts
@@ -4,6 +4,7 @@ import type {
ResponseDetailsParams,
ResponseGraphParams,
ResponseListParams,
+ ResponseTimeMetricsByRegionParams,
ResponseTimeMetricsParams,
} from "@openstatus/tinybird";
import {
@@ -14,6 +15,7 @@ import {
getResponseGraph,
getResponseList,
getResponseTimeMetrics,
+ getResponseTimeMetricsByRegion,
Tinybird,
} from "@openstatus/tinybird";
@@ -100,3 +102,15 @@ export async function getResponseTimeMetricsData(
}
return;
}
+
+export async function getResponseTimeMetricsByRegionData(
+ props: ResponseTimeMetricsByRegionParams,
+) {
+ try {
+ const res = await getResponseTimeMetricsByRegion(tb)(props);
+ return res.data;
+ } catch (e) {
+ console.error(e);
+ }
+ return;
+}
diff --git a/packages/tinybird/pipes/response_time_metrics_by_region.pipe b/packages/tinybird/pipes/response_time_metrics_by_region.pipe
new file mode 100644
index 000000000..d3e78287f
--- /dev/null
+++ b/packages/tinybird/pipes/response_time_metrics_by_region.pipe
@@ -0,0 +1,23 @@
+VERSION 0
+
+NODE response_time_metrics_region__v0_0
+SQL >
+
+ %
+ SELECT
+ region,
+ round(avg(latency)) as avgLatency,
+ round(quantile(0.75)(latency)) as p75Latency,
+ round(quantile(0.9)(latency)) as p90Latency,
+ round(quantile(0.95)(latency)) as p95Latency,
+ round(quantile(0.99)(latency)) as p99Latency
+ -- max(latency) as maxLatency,
+ -- min(latency) as minLatency
+ FROM materialized_view_ping_response_45d_ttl__v7
+ WHERE
+ monitorId = {{ String(monitorId, '1') }}
+ AND timestamp
+ >= toUnixTimestamp64Milli(toDateTime64(now() - INTERVAL {{ Int32(interval, 24) }} HOUR, 3))
+ GROUP BY region
+
+
diff --git a/packages/tinybird/src/client.ts b/packages/tinybird/src/client.ts
index 23b9936cc..93ad9ebc1 100644
--- a/packages/tinybird/src/client.ts
+++ b/packages/tinybird/src/client.ts
@@ -8,6 +8,7 @@ import {
tbBuildResponseGraph,
tbBuildResponseList,
tbBuildResponseTimeMetrics,
+ tbBuildResponseTimeMetricsByRegion,
tbIngestPingResponse,
tbParameterHomeStats,
tbParameterMonitorList,
@@ -16,6 +17,7 @@ import {
tbParameterResponseGraph,
tbParameterResponseList,
tbParameterResponseTimeMetrics,
+ tbParameterResponseTimeMetricsByRegion,
} from "./validation";
// REMINDER:
@@ -120,3 +122,14 @@ export function getResponseTimeMetrics(tb: Tinybird) {
},
});
}
+
+export function getResponseTimeMetricsByRegion(tb: Tinybird) {
+ return tb.buildPipe({
+ pipe: "response_time_metrics_by_region__v0",
+ parameters: tbParameterResponseTimeMetricsByRegion,
+ data: tbBuildResponseTimeMetricsByRegion,
+ opts: {
+ revalidate: 30, // 30 sec cache - mostly for timestamp metric
+ },
+ });
+}
diff --git a/packages/tinybird/src/validation.ts b/packages/tinybird/src/validation.ts
index 3d62ec908..1da5963cd 100644
--- a/packages/tinybird/src/validation.ts
+++ b/packages/tinybird/src/validation.ts
@@ -213,6 +213,23 @@ export const tbBuildResponseTimeMetrics = z
})
.merge(latencyMetrics);
+/**
+ * Params for pipe response_time_metrics_by_region
+ */
+export const tbParameterResponseTimeMetricsByRegion = z.object({
+ monitorId: z.string(),
+ interval: z.number().int().default(24), // 24 hours
+});
+
+/**
+ * Values from the pipe response_time_metrics_by_region
+ */
+export const tbBuildResponseTimeMetricsByRegion = z
+ .object({
+ region: z.enum(flyRegions),
+ })
+ .merge(latencyMetrics);
+
export type Ping = z.infer<typeof tbBuildResponseList>;
export type Region = (typeof flyRegions)[number]; // TODO: rename type AvailabeRegion
export type Monitor = z.infer<typeof tbBuildMonitorList>;
@@ -229,3 +246,9 @@ export type ResponseTimeMetrics = z.infer<typeof tbBuildResponseTimeMetrics>;
export type ResponseTimeMetricsParams = z.infer<
typeof tbParameterResponseTimeMetrics
>;
+export type ResponseTimeMetricsByRegion = z.infer<
+ typeof tbBuildResponseTimeMetricsByRegion
+>;
+export type ResponseTimeMetricsByRegionParams = z.infer<
+ typeof tbParameterResponseTimeMetricsByRegion
+>;