Skip to content

Commit

Permalink
[change] Added random pause for every 10 successfull requests #128
Browse files Browse the repository at this point in the history
Closes #128

---------

Co-authored-by: Federico Capoano <[email protected]>
  • Loading branch information
Dhanus3133 and nemesifier authored May 10, 2024
1 parent 7718264 commit ea94503
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions openwisp-monitoring/files/monitoring.agent
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ handle_sigusr1() {
}

send_data() {
success=0
while true; do
for file in "$TMP_DIR"/*; do
if [ ! -f "$file" ]; then
Expand Down Expand Up @@ -166,6 +167,7 @@ send_data() {
# send data
response_code=$($CURL_COMMAND -H "Content-Type: application/json" -d "$data" "$url")
if [ "$response_code" = "200" ]; then
success=$((success + 1))
if [ "$VERBOSE_MODE" -eq "1" ]; then
logger -s "Data sent successfully." \
-p daemon.info
Expand Down Expand Up @@ -209,6 +211,12 @@ send_data() {
done
# retry sending same data again in next cycle
[ "$failures" -eq "$MAX_RETRIES" ] && break
# pause for a random time between 1 and 5 seconds every
# 10 successful requests sent to avoid overload the server
if [ $((success % 10)) -eq 0 ]; then
pause_duration=$(/usr/sbin/openwisp-get-random-number 1 5)
sleep "$pause_duration"
fi
done
done
}
Expand Down

0 comments on commit ea94503

Please sign in to comment.