Openstatus www.openstatus.dev

fix: home stats (#1097)

authored by

Maximilian Kaske and committed by
GitHub
c87fff16 0da65430

+12 -24
+3 -3
apps/web/src/components/marketing/stats.tsx
··· 6 6 const tb = new OSTinybird(env.TINY_BIRD_API_KEY); 7 7 8 8 export async function Stats() { 9 - const tbTotalStats = await tb.homeStats({}); 10 9 const tbLastHourStats = await tb.homeStats({ period: "1h" }); 10 + const tbWeeklyStats = await tb.homeStats({ period: "1w" }); 11 11 // const totalActiveMonitors = await api.monitor.getTotalActiveMonitors.query(); 12 12 13 13 return ( ··· 15 15 <div className="grid grid-cols-1 gap-8 sm:grid-cols-3 sm:gap-16"> 16 16 <div className="text-center"> 17 17 <h3 className="font-cal text-3xl"> 18 - {numberFormatter(tbTotalStats?.data?.[0]?.count || 0)} 18 + {numberFormatter(tbWeeklyStats?.data?.[0]?.count || 0)} 19 19 </h3> 20 - <p className="font-light text-muted-foreground">Total pings</p> 20 + <p className="font-light text-muted-foreground">Weekly pings</p> 21 21 </div> 22 22 <div className="text-center"> 23 23 <h3 className="font-cal text-3xl">
+8 -2
packages/tinybird/pipes/endpoint__stats_global.pipe
··· 7 7 SELECT COUNT(*) as count 8 8 FROM ping_response__v8 9 9 {% if defined(period) %} 10 - {% if String(period) == "1h" %} 11 - WHERE cronTimestamp > toUnixTimestamp(now() - INTERVAL 1 HOUR) * 1000 10 + {% if String(period) == "1h" %} 11 + WHERE cronTimestamp > toUnixTimestamp(now() - INTERVAL 1 HOUR) * 1000 12 12 {% elif String(period) == "10m" %} 13 13 WHERE cronTimestamp > toUnixTimestamp(now() - INTERVAL 10 MINUTE) * 1000 14 + {% elif String(period) == "1d" %} 15 + WHERE cronTimestamp > toUnixTimestamp(now() - INTERVAL 1 DAY) * 1000 16 + {% elif String(period) == "1w" %} 17 + WHERE cronTimestamp > toUnixTimestamp(now() - INTERVAL 7 DAY) * 1000 18 + {% elif String(period) == "1m" %} 19 + WHERE cronTimestamp > toUnixTimestamp(now() - INTERVAL 1 MONTH) * 1000 14 20 {% else %} 15 21 WHERE cronTimestamp > 0 16 22 {% end %}
-18
packages/tinybird/pipes/home_stats.pipe
··· 1 - VERSION 0 2 - 3 - NODE home_stats_0 4 - SQL > 5 - 6 - % 7 - SELECT COUNT(*) as count 8 - FROM ping_response__v8 9 - {% if defined(period) %} 10 - {% if String(period) == "1h" %} 11 - WHERE cronTimestamp > toUnixTimestamp(now() - INTERVAL 1 HOUR) * 1000 12 - {% elif String(period) == "10m" %} 13 - WHERE cronTimestamp > toUnixTimestamp(now() - INTERVAL 10 MINUTE) * 1000 14 - {% else %} 15 - WHERE cronTimestamp > 0 16 - {% end %} 17 - {% end %} 18 -
+1 -1
packages/tinybird/src/client.ts
··· 19 19 pipe: "endpoint__stats_global__v0", 20 20 parameters: z.object({ 21 21 cronTimestamp: z.number().int().optional(), 22 - period: z.enum(["total", "1h", "10m"]).optional(), 22 + period: z.enum(["total", "1h", "10m", "1d", "1w", "1m"]).optional(), 23 23 }), 24 24 data: z.object({ 25 25 count: z.number().int(),