-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmonitor-minion.txt
48 lines (30 loc) · 1.19 KB
/
monitor-minion.txt
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
40
41
42
43
44
45
46
47
48
############################ BASH SCRIPT
$ cat monitor
PW=$(grep 'postgresql:' /path/to/app.production.conf | perl -ne'm/APPNAME:(.+)@/ && print $1')
# Allow reading commands line-by-line, even if they have spaces
O=$IFS
IFS=$(echo -en "\n\b")
# Run each command
for cmd in $(cat sql); do
echo "# RUNNING COMMAND: $cmd"
PGPASSWORD=$PW \
psql \
-h example.com \
--username=USER \
--database=DBNAME \
-c "$cmd"
done
# Reading line-by-line cleanup
IFS=$O
############################ SQL COMMANDS
$ cat sql
select now(); -- CMD1
select * from minion_locks; -- CMD2
select queue, count(*) from minion_jobs group by queue; --CMD3
select queue, count(*) from minion_jobs where state != 'finished' group by queue; -- CMD4
select queue, state, count(*) from minion_jobs group by queue, state order by queue; -- CMD5
select queue, state, count(*), max(delayed), min(created) from minion_jobs where queue = 'QUEUENAME' group by queue, state order by queue; -- CMD6
############################ RUN
while /bin/true; do date; bash ./monitor >> log.txt; sleep 60; done &
############################ INTERPRET LOG
egrep 'CMD1|CMD6' -A 3 log.txt | egrep -v '\---|RUNNING'