-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun-stat-report
More file actions
executable file
·98 lines (88 loc) · 2.23 KB
/
run-stat-report
File metadata and controls
executable file
·98 lines (88 loc) · 2.23 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env bash
#
# Synospsis:
# Report of running flowd processes in schema/*/run.
# Usage:
# run-stat-report
# See:
# setspace/sbin/run-stat-tuple
# setspace/sbin/run-stat-tuple . # limit stats to schema in current dir/
# 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
}
case $# in
0)
LIMIT_SCHEMA=
;;
1)
test $1 = . || die "unknown limit schema: $1"
LIMIT_SCHEMA=$(basename $(pwd))
test -d "../../schema/$LIMIT_SCHEMA" ||
die "no schema dir: $LIMIT_SCHEMA"
;;
*)
die "wrong nmumber of cli args: got $#, need 0 or 1"
;;
esac
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 $LIMIT_SCHEMA |
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/ * //'
STATUS=${PIPESTATUS[*]}
test "$STATUS" = '0 0 0 0' || die "run-tuple pipe failed: exit status=$STATUS"
exit 0