Skip to content

Open-source status page, incident response and uptime monitoring

chore: add period for better caching (#378)

Maximilian Kaske77c47a286af4
diff --git a/apps/web/src/components/marketing/stats.tsx b/apps/web/src/components/marketing/stats.tsx
index 4e029ca2b..5642ae2ce 100644
--- a/apps/web/src/components/marketing/stats.tsx
+++ b/apps/web/src/components/marketing/stats.tsx
@@ -4,11 +4,8 @@ import { numberFormatter } from "@/lib/utils";
import { api } from "@/trpc/server";
export async function Stats() {
- const last10m = new Date().getTime() - 60 * 60 * 1000; // cron timestamp 10m ago
const tbTotalStats = await getHomeStatsData({});
- const tbLast10mStats = await getHomeStatsData({
- cronTimestamp: last10m,
- });
+ const tbLastHourStats = await getHomeStatsData({ period: "1h" });
// FIXME:
// const totalActiveMonitors = await api.monitor.getTotalActiveMonitors.query(
// {},
@@ -27,20 +24,18 @@ export async function Stats() {
</div>
<div className="text-center">
<h3 className="font-cal text-3xl">
- {tbLast10mStats && tbLast10mStats?.length > 0
- ? numberFormatter(tbLast10mStats[0].count)
+ {tbLastHourStats && tbLastHourStats?.length > 0
+ ? numberFormatter(tbLastHourStats[0].count)
: 0}
</h3>
<p className="text-muted-foreground font-light">
- Pings in the last 10 minutes
+ Pings in the last hour
</p>
</div>
<div className="text-center">
<h3 className="font-cal text-3xl">
- {/* {tbLast10mStats && tbLast10mStats?.length > 0
- ? numberFormatter(totalActiveMonitors)
- : 0} */}
- 700+
+ {/* {numberFormatter(totalActiveMonitors)} */}
+ 900+
</h3>
<p className="text-muted-foreground font-light">Active monitors</p>
</div>
diff --git a/packages/tinybird/pipes/home_stats.pipe b/packages/tinybird/pipes/home_stats.pipe
index 1fd47c046..ffd9e95b3 100644
--- a/packages/tinybird/pipes/home_stats.pipe
+++ b/packages/tinybird/pipes/home_stats.pipe
@@ -4,8 +4,17 @@ NODE home_stats__0
SQL >
%
- SELECT
- COUNT(*) as count
- FROM ping_response__v3
- WHERE cronTimestamp > {{ Int64(cronTimestamp, 0) }}
+ SELECT COUNT(*) as count
+ FROM ping_response__v3
+ {% 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 %}
+ {% else %}
+ WHERE cronTimestamp > {{ Int64(cronTimestamp, 0) }}
+ {% end %}
diff --git a/packages/tinybird/src/validation.ts b/packages/tinybird/src/validation.ts
index 95703e1df..f40094ca4 100644
--- a/packages/tinybird/src/validation.ts
+++ b/packages/tinybird/src/validation.ts
@@ -106,6 +106,7 @@ export const tbBuildMonitorList = z.object({
*/
export const tbParameterHomeStats = z.object({
cronTimestamp: z.number().int().optional(),
+ period: z.enum(["total", "1h", "10m"]).optional(),
});
/**