From ffed6366268db1c84fc838acfa29bd714fbb408a Mon Sep 17 00:00:00 2001 From: akumari Date: Mon, 18 May 2015 04:07:39 -0700 Subject: [PATCH] All directories under data_file_directories in cassandra.yaml need to be monitored Currently the database nodemgr only monitors the first entry under the data_file_directories in cassandra.yaml. Modified DatabaseNodemgr.py to monitor all the directories listed under data_file_directories and then send the sum of their disk usage. Closes-bug: #1446852 Change-Id: I179d22653108fe10c09491233aab7507e60e58a8 --- src/nodemgr/database_event_manager.py | 104 +++++++++++++++----------- 1 file changed, 60 insertions(+), 44 deletions(-) diff --git a/src/nodemgr/database_event_manager.py b/src/nodemgr/database_event_manager.py index 1f1dcda1a78..68d1a19e1e6 100644 --- a/src/nodemgr/database_event_manager.py +++ b/src/nodemgr/database_event_manager.py @@ -74,39 +74,47 @@ def process(self): (linux_dist, x, y) = platform.linux_distribution() if (linux_dist == 'Ubuntu'): - popen_cmd = "set `df -Pk \`grep -A 1 'data_file_directories:'" + \ - " /etc/cassandra/cassandra.yaml | grep '-' | cut -d'-'" + \ - " -f2 \`/ContrailAnalytics | grep %` && echo $3 |" + \ - " cut -d'%' -f1" + popen_cmd = "set `df -Pk" + \ + " \`sed -n -e '/'data_file_directories'/,/'#'/p'" + \ + " /etc/cassandra/cassandra.yaml | grep '-' | cut -d '-' -f2" + \ + " | sed 's/$/\/ContrailAnalytics/'\` | grep % |" + \ + " awk '{s+=$3}END{print s}'` && echo $1" (disk_space_used, error_value) = \ Popen(popen_cmd, shell=True, stdout=PIPE).communicate() - popen_cmd = "set `df -Pk \`grep -A 1 'data_file_directories:'" + \ - " /etc/cassandra/cassandra.yaml | grep '-' | cut -d'-'" + \ - " -f2\`/ContrailAnalytics | grep %` && echo $4" + \ - " | cut -d'%' -f1" + popen_cmd = "set `df -Pk" + \ + " \`sed -n -e '/'data_file_directories'/,/'#'/p'" + \ + " /etc/cassandra/cassandra.yaml | grep '-' | cut -d '-' -f2" + \ + " | sed 's/$/\/ContrailAnalytics/'\` | grep % |" + \ + " awk '{s+=$4}END{print s}'` && echo $1" (disk_space_available, error_value) = \ Popen(popen_cmd, shell=True, stdout=PIPE).communicate() - popen_cmd = "set `du -skL \`grep -A 1 'data_file_directories:'" + \ - " /etc/cassandra/cassandra.yaml | grep '-' | cut -d'-'" + \ - " -f2\`/ContrailAnalytics` && echo $1 | cut -d'%' -f1" + popen_cmd = "set `du -skL" + \ + " \`sed -n -e '/'data_file_directories'/,/'#'/p'" + \ + " /etc/cassandra/cassandra.yaml | grep '-' | cut -d '-' -f2" + \ + " | sed 's/$/\/ContrailAnalytics/'\` |" + \ + " awk '{s+=$1}END{print s}'` && echo $1" (analytics_db_size, error_value) = \ Popen(popen_cmd, shell=True, stdout=PIPE).communicate() else: - popen_cmd = "set `df -Pk \`grep -A 1 'data_file_directories:'" + \ - " /etc/cassandra/conf/cassandra.yaml | grep '-' |" + \ - " cut -d'-' -f2 \`/ContrailAnalytics | grep %` &&" + \ - " echo $3 | cut -d'%' -f1" + popen_cmd = "set `df -Pk" + \ + " \`sed -n -e '/'data_file_directories'/,/'#'/p'" + \ + " /etc/cassandra/conf/cassandra.yaml | grep '-' |" + \ + " cut -d '-' -f2 | sed 's/$/\/ContrailAnalytics/'\` |" + \ + " grep % | awk '{s+=$3}END{print s}'` && echo $1" (disk_space_used, error_value) = \ Popen(popen_cmd, shell=True, stdout=PIPE).communicate() - popen_cmd = "set `df -Pk \`grep -A 1 'data_file_directories:'" + \ - " /etc/cassandra/conf/cassandra.yaml | grep '-' |" + \ - " cut -d'-' -f2\`/ContrailAnalytics | grep %` && echo $4" + \ - " | cut -d'%' -f1" + popen_cmd = "set `df -Pk" + \ + " \`sed -n -e '/'data_file_directories'/,/'#'/p'" + \ + " /etc/cassandra/conf/cassandra.yaml | grep '-' |" + \ + " cut -d '-' -f2 | sed 's/$/\/ContrailAnalytics/'\` |" + \ + " grep % | awk '{s+=$4}END{print s}'` && echo $1" (disk_space_available, error_value) = \ Popen(popen_cmd, shell=True, stdout=PIPE).communicate() - popen_cmd = "set `du -skL \`grep -A 1 'data_file_directories:'" + \ - " /etc/cassandra/conf/cassandra.yaml | grep '-' | cut -d" + \ - "'-' -f2\`/ContrailAnalytics` && echo $1 | cut -d'%' -f1" + popen_cmd = "set `du -skL" + \ + " \`sed -n -e '/'data_file_directories'/,/'#'/p'" + \ + " /etc/cassandra/conf/cassandra.yaml | grep '-' |" + \ + " cut -d '-' -f2 | sed 's/$/\/ContrailAnalytics/'\` |" + \ + " awk '{s+=$1}END{print s}'` && echo $1" (analytics_db_size, error_value) = \ Popen(popen_cmd, shell=True, stdout=PIPE).communicate() disk_space_total = int(disk_space_used) + int(disk_space_available) @@ -143,39 +151,47 @@ def get_failbits_nodespecific_desc(self, fail_status_bits): def database_periodic(self): (linux_dist, x, y) = platform.linux_distribution() if (linux_dist == 'Ubuntu'): - popen_cmd = "set `df -Pk \`grep -A 1 'data_file_directories:'" + \ - " /etc/cassandra/cassandra.yaml | grep '-' | cut -d" + \ - "'-' -f2 \`/ContrailAnalytics | grep %` && echo $3 |" + \ - " cut -d'%' -f1" + popen_cmd = "set `df -Pk" + \ + " \`sed -n -e '/'data_file_directories'/,/'#'/p'" + \ + " /etc/cassandra/cassandra.yaml | grep '-' | cut -d '-' -f2" + \ + " | sed 's/$/\/ContrailAnalytics/'\` | grep % |" + \ + " awk '{s+=$3}END{print s}'` && echo $1" (disk_space_used, error_value) = \ Popen(popen_cmd, shell=True, stdout=PIPE).communicate() - popen_cmd = "set `df -Pk \`grep -A 1 'data_file_directories:'" + \ - " /etc/cassandra/cassandra.yaml | grep '-' | cut -d'-'" + \ - " -f2\`/ContrailAnalytics | grep %` && echo $4 |" + \ - " cut -d'%' -f1" + popen_cmd = "set `df -Pk" + \ + " \`sed -n -e '/'data_file_directories'/,/'#'/p'" + \ + " /etc/cassandra/cassandra.yaml | grep '-' | cut -d '-' -f2" + \ + " | sed 's/$/\/ContrailAnalytics/'\` | grep % |" + \ + " awk '{s+=$4}END{print s}'` && echo $1" (disk_space_available, error_value) = \ Popen(popen_cmd, shell=True, stdout=PIPE).communicate() - popen_cmd = "set `du -skL \`grep -A 1 'data_file_directories:'" + \ - " /etc/cassandra/cassandra.yaml | grep '-' | cut -d'-'" + \ - " -f2\`/ContrailAnalytics` && echo $1 | cut -d'%' -f1" + popen_cmd = "set `du -skL" + \ + " \`sed -n -e '/'data_file_directories'/,/'#'/p'" + \ + " /etc/cassandra/cassandra.yaml | grep '-' | cut -d '-' -f2" + \ + " | sed 's/$/\/ContrailAnalytics/'\` |" + \ + " awk '{s+=$1}END{print s}'` && echo $1" (analytics_db_size, error_value) = \ Popen(popen_cmd, shell=True, stdout=PIPE).communicate() else: - popen_cmd = "set `df -Pk \`grep -A 1 'data_file_directories:'" + \ - " /etc/cassandra/conf/cassandra.yaml | grep '-' |" + \ - " cut -d'-' -f2 \`/ContrailAnalytics | grep %` && echo" + \ - " $3 | cut -d'%' -f1" + popen_cmd = "set `df -Pk" + \ + " \`sed -n -e '/'data_file_directories'/,/'#'/p'" + \ + " /etc/cassandra/conf/cassandra.yaml | grep '-' |" + \ + " cut -d '-' -f2 | sed 's/$/\/ContrailAnalytics/'\` |" + \ + " grep % | awk '{s+=$3}END{print s}'` && echo $1" (disk_space_used, error_value) = \ Popen(popen_cmd, shell=True, stdout=PIPE).communicate() - popen_cmd = "set `df -Pk \`grep -A 1 'data_file_directories:'" + \ - " /etc/cassandra/conf/cassandra.yaml | grep '-' | cut -d" + \ - "'-' -f2\`/ContrailAnalytics | grep %` && echo $4" + \ - " | cut -d'%' -f1" + popen_cmd = "set `df -Pk" + \ + " \`sed -n -e '/'data_file_directories'/,/'#'/p'" + \ + " /etc/cassandra/conf/cassandra.yaml | grep '-' |" + \ + " cut -d '-' -f2 | sed 's/$/\/ContrailAnalytics/'\` |" + \ + " grep % | awk '{s+=$4}END{print s}'` && echo $1" (disk_space_available, error_value) = \ Popen(popen_cmd, shell=True, stdout=PIPE).communicate() - popen_cmd = "set `du -skL \`grep -A 1 'data_file_directories:'" + \ - " /etc/cassandra/conf/cassandra.yaml | grep '-' | cut -d" + \ - "'-' -f2\`/ContrailAnalytics` && echo $1 | cut -d'%' -f1" + popen_cmd = "set `du -skL" + \ + " \`sed -n -e '/'data_file_directories'/,/'#'/p'" + \ + " /etc/cassandra/conf/cassandra.yaml | grep '-' |" + \ + " cut -d '-' -f2 | sed 's/$/\/ContrailAnalytics/'\` |" + \ + " awk '{s+=$1}END{print s}'` && echo $1" (analytics_db_size, error_value) = \ Popen(popen_cmd, shell=True, stdout=PIPE).communicate() db_stat = DatabaseUsageStats()