-
Notifications
You must be signed in to change notification settings - Fork 1
/
run-stat-report
executable file
·80 lines (71 loc) · 1.84 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
#!/usr/bin/env bash
#
# Synospsis:
# Report of running flowd processes in schema/*/run.
# Usage:
# run-stat-report
# See:
# setspace/sbin/run-stat-tuple
# Note:
# Replace "column" command with gnuversion in util-linux macports
# or write replacement in https://github.com/jmscott/work.
#
# Ought to consolidate this script with blobio/sbin/run-stat-report.
#
# Sort is ignoring the second key on linux. The pain never ends.
#
die()
{
echo "ERROR: $@" >&2
exit 1
}
test $# = 0 || die "wrong number of arguments: got $#, expected 0"
test -n "$SETSPACE_ROOT" || die 'env not defined: SETSPACE_ROOT'
cd $SETSPACE_ROOT || die "cd SETSPACE_ROOT failed: exit status=$?"
cat <<END
Who Am I: $(hostname):$SETSPACE_ROOT
Now: $(date)
Load Avg: $(uptime | sed 's/.*load average: //')
END
(
cat <<END
Schema 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)
else
BOOT_AGO=null
fi
if [ $REC_EPOCH != null ]; then
REC_AGO=$(elapsed-english $REC_EPOCH)
else
REC_AGO=null
fi
cat <<END
$PROC $STATE $BOOT_AGO $BOOT_GYR $REC_AGO $REC_GYR
END
done
) |
sed 's@ null@ n/a@g' |
column -s ' ' -t |
sed 's/ * //'