Write stats to tmp file before updating data file

This change updates the stats collection script so it writes to a
temporary file before updating the main stats file to ensure that
the update is an atomic operation.

Change-Id: I68d4e3e723ed62fb5e90ba6bcf284c432ba9cd6b
Closes-Bug: #1569143
This commit is contained in:
Liam Young 2017-10-02 11:00:14 +00:00
parent a68b912cf5
commit a8f7dea190
1 changed files with 3 additions and 1 deletions

View File

@ -43,11 +43,13 @@ fi
if [ ! -d $LOG_DIR ]; then
mkdir -p $LOG_DIR
fi
TMP_DATA_FILE=$(mktemp -p ${DATA_DIR})
echo "#Vhost Name Messages_ready Messages_unacknowledged Messages Consumers Memory Time" > $DATA_FILE
/usr/sbin/rabbitmqctl -q list_vhosts | \
while read VHOST; do
/usr/sbin/rabbitmqctl -q list_queues -p $VHOST name messages_ready messages_unacknowledged messages consumers memory | \
awk "{print \"$VHOST \" \$0 \" $(date +'%s') \"}" >> $DATA_FILE 2>${LOG_DIR}/list_queues.log
awk "{print \"$VHOST \" \$0 \" $(date +'%s') \"}" >> ${TMP_DATA_FILE} 2>${LOG_DIR}/list_queues.log
done
mv ${TMP_DATA_FILE} ${DATA_FILE}
echo "mnesia_size: ${MNESIA_DB_SIZE}@$NOW" > $RABBIT_STATS_DATA_FILE
echo "rss_size: ${RABBIT_RSS}@$NOW" >> $RABBIT_STATS_DATA_FILE