Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[change] Random pause for every 10 successfull sent requests #131

Merged
merged 7 commits into from
May 10, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 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_count=0
Dhanus3133 marked this conversation as resolved.
Show resolved Hide resolved
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_count=$((success_count + 1))
if [ "$VERBOSE_MODE" -eq "1" ]; then
logger -s "Data sent successfully." \
-p daemon.info
Expand Down Expand Up @@ -195,6 +197,11 @@ send_data() {
done
# retry sending same data again in next cycle
[ "$failures" -eq "$MAX_RETRIES" ] && break
# pause for a while after every 10 successful request sent
Dhanus3133 marked this conversation as resolved.
Show resolved Hide resolved
if [ $((success_count % 10)) -eq 0 ]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't 0 % 10 == 0 ? Why not just use [ $success_rate -ge 10 ] which is more readable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-ge makes it run whenever the success_rate is more than or equal to 10. But as per the issue, it was meant for every 10 requests. Was I right on this one?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The requirement is to pause every 10 successful requests.
I don't see any success_rate variable in this diff, @pandafy where is success_rate coming from?
I only see success_count here.

pause_duration=$(/usr/sbin/openwisp-get-random-number 1 5)
sleep "$pause_duration"
fi
done
done
}
Expand Down