Skip to content

Commit

Permalink
memory metric script updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Varun Chandak committed Jan 15, 2018
1 parent 20e7d94 commit 0e2f378
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ export AWS_DEFAULT_OUTPUT="text"
INST_ID="$(curl http://169.254.169.254/latest/meta-data/instance-id)"

MemoryMetric() {
mem=$(bc <<< "scale=2; $(free -m | grep ^Mem | awk '{print $3/$2*100}')/1")
vmstat -s | sed -e 's/^[ \t]*//' | cut -d' ' -f1,3- | tr -s ' ' ',' | grep -e 'total,memory' -e 'free,memory' -e 'buffer,memory' -e 'swap,cache' | awk -F, '{print $1/1024","$2" "$3}' > /tmp/mem-usage.csv
MemTotal="$(cat /tmp/mem-usage.csv | grep -e 'total memory' | awk -F, '{print $1}')"
MemFree="$(cat /tmp/mem-usage.csv | grep -e 'free memory' | awk -F, '{print $1}')"
Buffers="$(cat /tmp/mem-usage.csv | grep -e 'buffer memory' | awk -F, '{print $1}')"
Cached="$(cat /tmp/mem-usage.csv | grep -e 'swap cache' | awk -F, '{print $1}')"
TotalMemFree="$(bc -l <<< $MemFree+$Buffers+$Cached)"
TotalMemUsed="$(bc -l <<< $MemTotal-$TotalMemFree)"
mem="$(bc <<< "scale=2; $TotalMemUsed*100/$MemTotal")"
rm -f /tmp/mem-usage.csv
#mem=$(bc <<< "scale=2; $(free -m | grep ^Mem | awk '{print $3/$2*100}')/1")
aws cloudwatch put-metric-data \
--metric-name "MemoryUtilization" \
--unit Percent \
Expand Down

0 comments on commit 0e2f378

Please sign in to comment.