Skip to content

Commit

Permalink
fix: home stats (#1097)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxkaske authored Nov 10, 2024
1 parent 0da6543 commit c87fff1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 24 deletions.
6 changes: 3 additions & 3 deletions apps/web/src/components/marketing/stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ 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 (
<Shell>
<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">
Expand Down
10 changes: 8 additions & 2 deletions packages/tinybird/pipes/endpoint__stats_global.pipe
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down
18 changes: 0 additions & 18 deletions packages/tinybird/pipes/home_stats.pipe

This file was deleted.

2 changes: 1 addition & 1 deletion packages/tinybird/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit c87fff1

Please sign in to comment.