Added script options: --timeout && --show-stats

This commit is contained in:
Patrick Van der Veken
2018-04-28 21:46:14 +02:00
parent 283a1e6101
commit 6ca8aa0f46
2 changed files with 140 additions and 8 deletions
+92
View File
@@ -1325,6 +1325,98 @@ print "${HC_STC}%%${HC_NOW}%%${HC_MSG}%%${HC_MSG_CUR_VAL}%%${HC_MSG_EXP_VAL}" \
return 0
}
# -----------------------------------------------------------------------------
# @(#) FUNCTION: show_statistics)
# DOES: show statistics about HC events
# EXPECTS: n/a
# RETURNS: n/a
# REQUIRES: n/a
function show_statistics
{
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
typeset _ARCHIVE_FILE=""
# current events
print
print -R "--- CURRENT events --"
print
print "${HC_LOG}:"
awk -F"${SEP}" '{
# all entries
total_count[$2]++
# set zero when empty
if (ok_count[$2] == "") { ok_count[$2]=0 }
if (nok_count[$2] == "") { nok_count[$2]=0 }
# count STCs
if ($3 == 0) {
ok_count[$2]++
} else {
nok_count[$2]++
}
# record first entry
if (first_entry[$2] == "" ) {
first_entry[$2]=$1
}
# pile up last entry
last_entry[$2]=$1
last_failid[$2]=$5
}
END {
for (hc in total_count) {
printf ("\t%s:\n", hc)
printf ("\t\t# entries: %s\n", total_count[hc])
printf ("\t\t# STC==0 : %s\n", ok_count[hc])
printf ("\t\t# STC<>0 : %s\n", nok_count[hc])
printf ("\t\tfirst : %s\n", first_entry[hc])
printf ("\t\tlast : %s\n", last_entry[hc])
}
}
' <${HC_LOG} 2>/dev/null
# archived events
print; print
print -R "--- ARCHIVED events --"
print
find ${ARCHIVE_DIR} -type f -name "hc.*.log" 2>/dev/null | while read _ARCHIVE_FILE
do
print "${_ARCHIVE_FILE}:"
awk -F"${SEP}" '{
# all entries
total_count[$2]++
# set zero when empty
if (ok_count[$2] == "") { ok_count[$2]=0 }
if (nok_count[$2] == "") { nok_count[$2]=0 }
# count STCs
if ($3 == 0) {
ok_count[$2]++;
} else {
nok_count[$2]++
}
# record first entry
if (first_entry[$2] == "" ) {
first_entry[$2]=$1
}
# pile up last entry
last_entry[$2]=$1
}
END {
for (hc in total_count) {
printf ("\t%s:\n", hc)
printf ("\t\t# entries: %s\n", total_count[hc])
printf ("\t\t# STC==0 : %s\n", ok_count[hc])
printf ("\t\t# STC<>0 : %s\n", nok_count[hc])
printf ("\t\tfirst : %s\n", first_entry[hc])
printf ("\t\tlast : %s\n", last_entry[hc])
}
}
' <${_ARCHIVE_FILE} 2>/dev/null
done
return 0
}
# -----------------------------------------------------------------------------
# @(#) FUNCTION: stat_hc()
# DOES: retrieve status of a HC