-
Notifications
You must be signed in to change notification settings - Fork 36
/
metrics.sh
executable file
·39 lines (32 loc) · 1.88 KB
/
metrics.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env bash
db=$(heroku config --app firesize | grep DATABASE_URL | tr -s ' ' | cut -d ' ' -f 2)
function sql {
psql $db -t -c "$1" | tr -s ' '
}
heroku=$(sql "SELECT COUNT(*) FROM accounts WHERE email LIKE '%heroku.com%' AND created_at > CURRENT_DATE - INTERVAL '30 days';")
manual=$(sql "SELECT COUNT(*) FROM accounts WHERE email NOT LIKE '%heroku.com%' AND created_at > CURRENT_DATE - INTERVAL '30 days';")
resizes=$(sql "SELECT COUNT(*) FROM image_requests WHERE created_at > CURRENT_DATE - INTERVAL '30 days';")
active_count=$(sql "SELECT COUNT(DISTINCT image_requests.account_id) FROM image_requests WHERE created_at > CURRENT_DATE - INTERVAL '30 days';")
active=$(sql "SELECT accounts.email, COUNT(accounts.email) FROM image_requests JOIN accounts ON image_requests.account_id = accounts.id WHERE accounts.created_at > CURRENT_DATE - INTERVAL '30 days' GROUP BY accounts.email ORDER BY COUNT(accounts.email) DESC LIMIT 10;")
echo "Last 30 days"
echo "------------"
echo "Heroku Signups: $heroku"
echo "Manaul Signups: $manual"
echo "Image resizes: $resizes"
echo "Active accounts: $active_count"
echo "Top #10 accounts by image resize count:"
echo "$active"
echo
heroku=$(sql "SELECT COUNT(*) FROM accounts WHERE email LIKE '%heroku.com%';")
manual=$(sql "SELECT COUNT(*) FROM accounts WHERE email NOT LIKE '%heroku.com%';")
resizes=$(sql "SELECT COUNT(*) FROM image_requests;")
active_count=$(sql "SELECT COUNT(DISTINCT image_requests.account_id) FROM image_requests ;")
active=$(sql "SELECT accounts.email, COUNT(accounts.email) FROM image_requests JOIN accounts ON image_requests.account_id = accounts.id GROUP BY accounts.email ORDER BY COUNT(accounts.email) DESC LIMIT 10;")
echo "All time"
echo "--------"
echo "Heroku Signups: $heroku"
echo "Manaul Signups: $manual"
echo "Image resizes: $resizes"
echo "Active accounts: $active_count"
echo "Top #10 accounts by image resize count:"
echo "$active"