From eb6ce54e07c59a8e850315ad2be83cac80e9006a Mon Sep 17 00:00:00 2001 From: Andreas Perhab Date: Wed, 4 Dec 2024 16:13:30 +0100 Subject: [PATCH] bind9_*: update stat_file only if it's older than 4 minutes --- plugins/bind/bind9_resolver_stats | 17 +++++++++++++---- plugins/bind/bind9_server_stats | 17 +++++++++++++---- plugins/bind/bind9_socket_stats | 17 +++++++++++++---- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/plugins/bind/bind9_resolver_stats b/plugins/bind/bind9_resolver_stats index d4f2f7e2..44614a51 100755 --- a/plugins/bind/bind9_resolver_stats +++ b/plugins/bind/bind9_resolver_stats @@ -26,11 +26,20 @@ if [ "$rndc" = "" ]; then rndc="/usr/sbin/rndc" fi -# Blank the stats file (else stats are appended not replaced) -rm ${stat_file} +# only renew stats if older than 4 minutes +if [ "$refresh_minutes" = "" ]; then + refresh_minutes=4 +fi -# Ask to bind to build new one -${rndc} stats +if [ "$(find "$(dirname "$stat_file")" -mindepth 1 -maxdepth 1 -cmin -"$refresh_minutes" -name "$(basename "$stat_file")" )" == "" ] ; then + if [ -e "${stat_file}" ] ; then + # Blank the stats file (else stats are appended not replaced) + rm "${stat_file}" + fi + + # Ask to bind to build new one + ${rndc} stats +fi # The section we are looking for in the stats. section="Resolver Statistics" diff --git a/plugins/bind/bind9_server_stats b/plugins/bind/bind9_server_stats index b84b9041..3e18fed5 100755 --- a/plugins/bind/bind9_server_stats +++ b/plugins/bind/bind9_server_stats @@ -26,11 +26,20 @@ if [ "$rndc" = "" ]; then rndc="/usr/sbin/rndc" fi -# Blank the stats file (else stats are appended not replaced) -rm ${stat_file} +# only renew stats if older than 4 minutes +if [ "$refresh_minutes" = "" ]; then + refresh_minutes=4 +fi -# Ask to bind to build new one -${rndc} stats +if [ "$(find "$(dirname "$stat_file")" -mindepth 1 -maxdepth 1 -cmin -"$refresh_minutes" -name "$(basename "$stat_file")" )" == "" ] ; then + if [ -e "${stat_file}" ] ; then + # Blank the stats file (else stats are appended not replaced) + rm "${stat_file}" + fi + + # Ask to bind to build new one + ${rndc} stats +fi # The section we are looking for in the stats. section="Name Server Statistics" diff --git a/plugins/bind/bind9_socket_stats b/plugins/bind/bind9_socket_stats index 7d6ac3f3..6ca95353 100755 --- a/plugins/bind/bind9_socket_stats +++ b/plugins/bind/bind9_socket_stats @@ -26,11 +26,20 @@ if [ "$rndc" = "" ]; then rndc="/usr/sbin/rndc" fi -# Blank the stats file (else stats are appended not replaced) -rm ${stat_file} +# only renew stats if older than 4 minutes +if [ "$refresh_minutes" = "" ]; then + refresh_minutes=4 +fi -# Ask to bind to build new one -${rndc} stats +if [ "$(find "$(dirname "$stat_file")" -mindepth 1 -maxdepth 1 -cmin -"$refresh_minutes" -name "$(basename "$stat_file")" )" == "" ] ; then + if [ -e "${stat_file}" ] ; then + # Blank the stats file (else stats are appended not replaced) + rm "${stat_file}" + fi + + # Ask to bind to build new one + ${rndc} stats +fi # The section we are looking for in the stats. section="Socket I/O Statistics"