-
Notifications
You must be signed in to change notification settings - Fork 1
/
run-stat-report
executable file
·82 lines (72 loc) · 1.91 KB
/
run-stat-report
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env bash
#
# Synospsis:
# Report of GREEN/YELLOW/RED stats for bio4d & flowd processes.
# Usage:
# run-stat-report
# See:
# https://github.com/jmscott/work
# /usr/local/jmscott/bin/duration-english
# Exit Status:
# 0 ok
# 1 error
# Note:
# Issue warning when BLOBIO_BIO4D_RRD_DURATION=0, otherwise the outp[ut
# seems mysteriously stae.
#
# Consider adding the disk usage of the volume storing
# $BLOBIO_ROOT/data. For gnu "df" do "df -h $BLOBIO_ROOT/data".
#
# On gnu/linux sort is ignoring the second key. The pain never ends.
#
NOW=$(date +'%s')
die()
{
echo "$(basename $0): ERROR: $@" >&2
exit 1
}
test $# = 0 || die "wrong number of arguments: got $#, expected 0"
test -n "$BLOBIO_ROOT" || die 'env not defined: BLOBIO_ROOT'
cd $BLOBIO_ROOT || die "cd BLOBIO_ROOT failed: exit status=$?"
cat <<END
Who Am I: $(hostname):$BLOBIO_ROOT
Now: $(date)
Load Avg: $(uptime | sed 's/.*load average: //')
END
(
cat <<END
Process State Boot Green,Yellow,Red Recent Green,Yellow,Red
------- ----- ----- ---------------- ------ ----------------
END
run-stat-tuple |
sort --key=2 --key=1 --field-separator=$'\t' |
while read PROC STATE \
BOOT_EPOCH BOOT_GREEN BOOT_YELLOW BOOT_RED \
REC_EPOCH REC_GREEN REC_YELLOW REC_RED; do
# collapse the green/yellow/red tuple to single
# G,Y,R value
if [ $BOOT_GREEN != null ]; then
BOOT_GYR="$BOOT_GREEN,$BOOT_YELLOW,$BOOT_RED"
else
BOOT_GYR=null
fi
if [ $REC_GREEN != null ]; then
REC_GYR="$REC_GREEN,$REC_YELLOW,$REC_RED"
else
REC_GYR=null
fi
# convert boot and recent sample epochs to
# readable english
if [ $BOOT_EPOCH != null ]; then
BOOT_AGO=$(elapsed-english $BOOT_EPOCH)
fi
if [ $REC_EPOCH != null ]; then
REC_AGO=$(elapsed-english $REC_EPOCH)
fi
cat <<END
$PROC $STATE $BOOT_AGO $BOOT_GYR $REC_AGO $REC_GYR
END
done
) |
column -s ' ' -t |
sed 's/ * //'