collect: The agent now keep the data of network use, until at maximum 15 days

Signed-off-by: 's avatarEdileuton Henrique de Oliveira <eho09@c3sl.ufpr.br>
parent 8e5f628a
......@@ -28,7 +28,7 @@ function check_traffic_date()
# If there is no TRAFFIC (probably its the first run), then just create a
# new one.
if ! test -f "$TRAFFIC"; then
echo $(date +%F) > $TRAFFIC
echo $(date +%F) > $TRAFFIC
return
fi
......@@ -46,6 +46,7 @@ function check_traffic_date()
# Finally, create a new TRAFFIC (keeping the previous one as
# PREVIOUS_TRAFFIC) if the dates doesnt match.
if test $CURRENT_DATE -ne $TRAFFIC_DATE; then
mkdir -p "./previous"
cp $TRAFFIC $PREVIOUS_TRAFFIC
echo $(date +%F) > $TRAFFIC
fi
......@@ -86,7 +87,7 @@ cd $PREFIX
TRAFFIC="./traffic.txt"
# Collected data on the last day before the machine is disconnected
PREVIOUS_TRAFFIC="./previous-traffic.txt"
PREVIOUS_TRAFFIC="./previous/traffic-$(date +%F).txt"
# Stored interfaces from the last run
INTERFACES="./interfaces.txt"
......
......@@ -53,26 +53,6 @@ function xml_print()
printf "</netuse>"
}
# Function: xml_print_zero
# Function that prints the contents of XML when there was no collected
# data. Print the statistics with zeroed content.
function xml_print_zero()
{
local TRAFFIC_TIME=$(printf "%02d:%02d:30" $TRAFFIC_HOUR $TRAFFIC_MINUTE)
printf "<netuse id=\"$((COUNT+1))\">"
printf "<date value=\"$TRAFFIC_DATE\" type=\"string\"/>"
printf "<time value=\"$TRAFFIC_TIME\" type=\"string\"/>"
printf "<rx>"
printf "<packets value=\"0\" type=\"int\"/>"
printf "<bytes value=\"0\" type=\"int\"/>"
printf "</rx>"
printf "<tx>"
printf "<packets value=\"0\" type=\"int\"/>"
printf "<bytes value=\"0\" type=\"int\"/>"
printf "</tx>"
printf "</netuse>"
}
# Function: xml_data_generator
# This function compares the file date of the last day of collection
......@@ -105,12 +85,6 @@ function xml_data_generator()
else
INTERVALID=$(cut -d" " -f1 <<< $line)
while test $COUNT -lt $INTERVALID -a $COUNT -lt 288; do
xml_print_zero
COUNT=$((${COUNT} + 1))
increment_time
done
if test $COUNT -eq $INTERVALID -a $COUNT -lt 288; then
xml_print
COUNT=$((${COUNT} + 1))
......@@ -118,12 +92,9 @@ function xml_data_generator()
fi
fi
done < $TRAFFIC
while test $COUNT -lt 288; do
xml_print_zero
COUNT=$((${COUNT} + 1))
increment_time
done
else
# If date in TRAFFIC file is older than 15 days then remove the file.
rm -f $TRAFFIC
fi
printf "\n"
......@@ -142,10 +113,14 @@ if test "$(bash $PROJECT)" != "0" -o "${FIRST_EXECUTION}"; then
exit 0
fi
TRAFFIC="${PREFIX}/../../../net/previous-traffic.txt"
TRAFFICS="${PREFIX}/../../../net/previous"
test -f "${TRAFFIC}" || exit 0
test -s $TRAFFIC || exit 0
test -d ${TRAFFICS} || exit 0
# Call the function xml_data_generator to generate the data to XML
xml_data_generator
for TRAFFIC in $(ls -r ${TRAFFICS})
do
if test -s $TRAFFIC; then
xml_data_generator
fi
done
......@@ -66,7 +66,7 @@ function clientExec()
# ------------------------------------------------------------------------------
export PREFIX="$(dirname $(readlink -f $0))"
source ${PREFIX}/load-config.sh || exit 1
PREVIOUS_TRAFFIC="${PREFIX}/net/previous-traffic.txt"
PREVIOUS_TRAFFIC="${PREFIX}/net/previous"
exec >> ${LOGFILE} 2>&1
......@@ -82,7 +82,7 @@ fi
# Collect and send system data if elapsed enough time or if it's the first
# execution of the agent
if elapsedTime && test -s "${PREVIOUS_TRAFFIC}"; then
if elapsedTime && test -d "${PREVIOUS_TRAFFIC}"; then
if test -z "${NETXMLFILENAME}"; then
printf "ERROR: Net XML filename not defined at configuration file.\n"
exit 3
......@@ -106,7 +106,10 @@ if elapsedTime && test -s "${PREVIOUS_TRAFFIC}"; then
if ! clientExec --net-usage; then
exit 6
fi
# Remove data already sent
rm -rf ${PREVIOUS_TRAFFIC}
# Record the current execution time to be used by elapsedTime()
date +%s > ${NETLASTEXEC}
fi
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment