Skip to content

Commit 1493800

Browse files
committed
add pipes
1 parent 4486b9e commit 1493800

File tree

5 files changed

+94
-0
lines changed

5 files changed

+94
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
TOKEN "read" READ
2+
3+
TAGS "vercel_logs"
4+
5+
NODE cache_stats
6+
SQL >
7+
SELECT
8+
toStartOfHour(event_time) as hour,
9+
count() as total_requests,
10+
countIf(event.proxy.vercelCache = 'HIT') as cache_hits,
11+
round(countIf(event.proxy.vercelCache = 'HIT') * 100.0 / count(), 2) as hit_rate
12+
FROM vercel_logs
13+
WHERE event.proxy.vercelCache != ''
14+
AND event_time >= {{DateTime(date_from, '2024-01-01 00:00:00')}}
15+
AND event_time <= {{DateTime(date_to, '2024-12-31 23:59:59')}}
16+
GROUP BY hour
17+
ORDER BY hour DESC

tinybird/pipes/vercel_errors.pipe

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
TOKEN "read" READ
2+
3+
TAGS "vercel_logs"
4+
5+
NODE errors_over_time
6+
SQL >
7+
SELECT
8+
toStartOfHour(event_time) as hour,
9+
countIf(event.proxy.statusCode >= 400) as error_count,
10+
count() as total_requests,
11+
round(countIf(event.proxy.statusCode >= 400) * 100.0 / count(), 2) as error_rate
12+
FROM vercel_logs
13+
WHERE event.proxy.statusCode != 0
14+
AND event_time >= {{DateTime(date_from, '2024-01-01 00:00:00')}}
15+
AND event_time <= {{DateTime(date_to, '2024-12-31 23:59:59')}}
16+
GROUP BY hour
17+
ORDER BY hour DESC
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
TOKEN "read" READ
2+
3+
TAGS "vercel_logs"
4+
5+
NODE requests_by_status
6+
SQL >
7+
SELECT
8+
event.proxy.statusCode as status,
9+
count() as count,
10+
round(count() * 100.0 / sum(count()) OVER (), 2) as percentage
11+
FROM vercel_logs
12+
WHERE event.proxy.statusCode != 0
13+
AND event_time >= {{DateTime(date_from, '2024-01-01 00:00:00')}}
14+
AND event_time <= {{DateTime(date_to, '2024-12-31 23:59:59')}}
15+
GROUP BY status
16+
ORDER BY count DESC
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
TOKEN "read" READ
2+
3+
TAGS "vercel_logs"
4+
5+
NODE response_times
6+
SQL >
7+
8+
SELECT
9+
toStartOfHour(event_time) as hour,
10+
round(avg(toFloat64OrZero(duration)), 2) as avg_duration,
11+
round(quantile(0.95)(toFloat64OrZero(duration)), 2) as p95_duration,
12+
round(max(toFloat64OrZero(duration)), 2) as max_duration
13+
FROM (
14+
SELECT
15+
event_time,
16+
event.proxy.path as path,
17+
extractAll(event.message, 'Duration: ([0-9]+) ms')[1] as duration
18+
FROM vercel_logs
19+
WHERE event_type = 'stdout'
20+
AND event.message LIKE '%Duration:%'
21+
AND event_time >= {{DateTime(date_from, '2024-01-01 00:00:00')}}
22+
AND event_time <= {{DateTime(date_to, '2024-12-31 23:59:59')}}
23+
)
24+
WHERE duration != ''
25+
GROUP BY hour
26+
ORDER BY hour DESC
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
TOKEN "read" READ
2+
3+
TAGS "vercel_logs"
4+
5+
NODE top_paths
6+
SQL >
7+
SELECT
8+
event.proxy.path as path,
9+
count() as requests,
10+
round(avg(if(event.proxy.statusCode >= 400, 1, 0)) * 100, 2) as error_rate,
11+
round(avg(if(event.proxy.vercelCache = 'HIT', 1, 0)) * 100, 2) as cache_hit_rate
12+
FROM vercel_logs
13+
WHERE event.proxy.path != ''
14+
AND event_time >= {{DateTime(date_from, '2024-01-01 00:00:00')}}
15+
AND event_time <= {{DateTime(date_to, '2024-12-31 23:59:59')}}
16+
GROUP BY path
17+
ORDER BY requests DESC
18+
LIMIT 10

0 commit comments

Comments
 (0)