first commit
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
#!/bin/bash
|
||||
|
||||
function check_network_traffic() {
|
||||
total_inbound=0
|
||||
total_outbound=0
|
||||
|
||||
for ((i=1; i<=$MEASUREMENT_COUNT; i++)); do
|
||||
usage=$(ifstat -i $INTERFACE $INTERVAL 1 | tail -n 1)
|
||||
|
||||
if [[ -z "$usage" ]]; then
|
||||
log_error "No output from ifstat on measurement $i."
|
||||
exit 2
|
||||
fi
|
||||
|
||||
inbound=$(echo $usage | awk '{print $1}')
|
||||
outbound=$(echo $usage | awk '{print $2}')
|
||||
|
||||
total_inbound=$(echo "$total_inbound + $inbound" | bc)
|
||||
total_outbound=$(echo "$total_outbound + $outbound" | bc)
|
||||
done
|
||||
|
||||
avg_inbound=$(echo "scale=2; $total_inbound / $MEASUREMENT_COUNT" | bc)
|
||||
avg_outbound=$(echo "scale=2; $total_outbound / $MEASUREMENT_COUNT" | bc)
|
||||
|
||||
if (( $(echo "$avg_inbound < $THRESHOLD_INBOUND" | bc -l) )) || (( $(echo "$avg_outbound < $THRESHOLD_OUTBOUND" | bc -l) )); then
|
||||
log_critical "Network traffic below thresholds. Avg In: $avg_inbound KB/s, Avg Out: $avg_outbound KB/s."
|
||||
restart_service
|
||||
else
|
||||
log_info "Network traffic is above thresholds. Avg In: $avg_inbound KB/s, Avg Out: $avg_outbound KB/s."
|
||||
fi
|
||||
}
|
||||
Reference in New Issue
Block a user