Files
scst/scripts/monitor-interrupt-rate
T
Gleb Chesnokov 0aa6689c3a scripts: Validate monitor intervals
Reject zero and nonnumeric sampling intervals before entering the
monitor loops, avoiding division errors and repeated failed sleep
calls.
2026-08-21 19:58:59 +03:00

30 lines
562 B
Bash
Executable File

#!/bin/bash
interval="${1:-5}"
if ! [[ "$interval" =~ ^0*[1-9][0-9]*$ ]]; then
echo "Error: interval must be a positive integer." >&2
exit 1
fi
interval="${interval#"${interval%%[!0]*}"}"
echo "Interrupts per second:"
while true
do
sum=0
while read -r line
do
for word in $line
do
if [ "${word#[0-9]}" != "$word" ] && [ "${word%[0-9]}" != "$word" ]; then
sum="$((sum + word))"
fi
done
done </proc/interrupts
if [ "$prev" != "" ]; then
echo $(((sum-prev)/interval))
fi
prev="$sum"
sleep "$interval"
done