Skip to content

Open-source status page, incident response and uptime monitoring

fix: home stats (#1097)

Maximilian Kaskec87fff16f9fe
diff --git a/apps/web/src/components/marketing/stats.tsx b/apps/web/src/components/marketing/stats.tsx
index 177711732..eddca4bf2 100644
--- a/apps/web/src/components/marketing/stats.tsx
+++ b/apps/web/src/components/marketing/stats.tsx
@@ -6,8 +6,8 @@ import { OSTinybird } from "@openstatus/tinybird";
const tb = new OSTinybird(env.TINY_BIRD_API_KEY);
export async function Stats() {
- const tbTotalStats = await tb.homeStats({});
const tbLastHourStats = await tb.homeStats({ period: "1h" });
+ const tbWeeklyStats = await tb.homeStats({ period: "1w" });
// const totalActiveMonitors = await api.monitor.getTotalActiveMonitors.query();
return (
@@ -15,9 +15,9 @@ export async function Stats() {
<div className="grid grid-cols-1 gap-8 sm:grid-cols-3 sm:gap-16">
<div className="text-center">
<h3 className="font-cal text-3xl">
- {numberFormatter(tbTotalStats?.data?.[0]?.count || 0)}
+ {numberFormatter(tbWeeklyStats?.data?.[0]?.count || 0)}
</h3>
- <p className="font-light text-muted-foreground">Total pings</p>
+ <p className="font-light text-muted-foreground">Weekly pings</p>
</div>
<div className="text-center">
<h3 className="font-cal text-3xl">
diff --git a/packages/tinybird/pipes/endpoint__stats_global.pipe b/packages/tinybird/pipes/endpoint__stats_global.pipe
index 37a270a83..ed4b7c235 100644
--- a/packages/tinybird/pipes/endpoint__stats_global.pipe
+++ b/packages/tinybird/pipes/endpoint__stats_global.pipe
@@ -7,10 +7,16 @@ SQL >
SELECT COUNT(*) as count
FROM ping_response__v8
{% if defined(period) %}
- {% if String(period) == "1h" %}
- WHERE cronTimestamp > toUnixTimestamp(now() - INTERVAL 1 HOUR) * 1000
+ {% if String(period) == "1h" %}
+ WHERE cronTimestamp > toUnixTimestamp(now() - INTERVAL 1 HOUR) * 1000
{% elif String(period) == "10m" %}
WHERE cronTimestamp > toUnixTimestamp(now() - INTERVAL 10 MINUTE) * 1000
+ {% elif String(period) == "1d" %}
+ WHERE cronTimestamp > toUnixTimestamp(now() - INTERVAL 1 DAY) * 1000
+ {% elif String(period) == "1w" %}
+ WHERE cronTimestamp > toUnixTimestamp(now() - INTERVAL 7 DAY) * 1000
+ {% elif String(period) == "1m" %}
+ WHERE cronTimestamp > toUnixTimestamp(now() - INTERVAL 1 MONTH) * 1000
{% else %}
WHERE cronTimestamp > 0
{% end %}
diff --git a/packages/tinybird/pipes/home_stats.pipe b/packages/tinybird/pipes/home_stats.pipe
deleted file mode 100644
index bdf885305..000000000
--- a/packages/tinybird/pipes/home_stats.pipe
+++ /dev/null
@@ -1,18 +0,0 @@
-VERSION 0
-
-NODE home_stats_0
-SQL >
-
- %
- SELECT COUNT(*) as count
- FROM ping_response__v8
- {% if defined(period) %}
- {% if String(period) == "1h" %}
- WHERE cronTimestamp > toUnixTimestamp(now() - INTERVAL 1 HOUR) * 1000
- {% elif String(period) == "10m" %}
- WHERE cronTimestamp > toUnixTimestamp(now() - INTERVAL 10 MINUTE) * 1000
- {% else %}
- WHERE cronTimestamp > 0
- {% end %}
- {% end %}
-
diff --git a/packages/tinybird/src/client.ts b/packages/tinybird/src/client.ts
index 6ce30f9d5..24add3d98 100644
--- a/packages/tinybird/src/client.ts
+++ b/packages/tinybird/src/client.ts
@@ -19,7 +19,7 @@ export class OSTinybird {
pipe: "endpoint__stats_global__v0",
parameters: z.object({
cronTimestamp: z.number().int().optional(),
- period: z.enum(["total", "1h", "10m"]).optional(),
+ period: z.enum(["total", "1h", "10m", "1d", "1w", "1m"]).optional(),
}),
data: z.object({
count: z.number().int(),