#!/bin/bash . /root/openrc echo "Openstack usage generated on $(date)" echo -en "\nNumber of active VMs: " mysql nova -Nse "select count(1) from instances where vm_state = 'active'" echo -en "\n***Usage summary***\n" openstack usage list -f csv --quote none | column -t -s, echo -en "\n***Ceph node disk usage***\n" # ceph df | grep -v "0 B" ceph osd df tree | grep host | awk '{print $NF,$(NF-4)"%"}' | tee /tmp/ceph-node-df.txt echo -en "Overall usage " cat /tmp/ceph-node-df.txt | tr -d \\% | datamash -t ' ' mean 2 | awk '{print $1"%"}' echo -en "\n***Allocation per host (flavor/total)***\n" echo -en "Host CPU% Memory%\n" | column -t openstack host list -fvalue -c 'Host Name' | grep compute | sort | while read h; do openstack host show $h -fcsv | egrep '(total|now)' | tr -d \" | paste - - | awk -F, '{print $1, $7/$3*100"%", $8/$4*100"%"}'; done | column -t | tee /tmp/cluster-cpu-ram.txt echo -en "Overall allocation " cat /tmp/cluster-cpu-ram.txt | tr -d \\% | awk '{print $1,$2,$3}' | datamash -t ' ' mean 2 mean 3 | awk '{printf("%.1f %.1f\n", $1, $2)}' echo -en "\n***Overcommit ratio***\n" cat /etc/nova/nova.conf | grep allocation_ratio | grep -v ^# # store key data into sqlite # Table schema: create table usage(date date, active_vm number, ceph_usage float, alloc_cpu float, alloc_mem float); # TODAY=$(date +%Y-%m-%d) ACTIVEVM=$(mysql nova -Nse "select count(1) from instances where vm_state = 'active'") CEPHUSAGE=$(cat /tmp/ceph-node-df.txt | tr -d \\% | datamash -t ' ' mean 2) ALLOCCPU=$(cat /tmp/cluster-cpu-ram.txt | tr -d \\% | awk '{print $1,$2,$3}' | datamash -t ' ' mean 2 mean 3 | awk '{print $1}') ALLOCRAM=$(cat /tmp/cluster-cpu-ram.txt | tr -d \\% | awk '{print $1,$2,$3}' | datamash -t ' ' mean 2 mean 3 | awk '{print $2}') echo "insert into usage values ('$TODAY', '$ACTIVEVM', '$CEPHUSAGE', '$ALLOCCPU', '$ALLOCRAM')" \ | sqlite3 /root/openstack-weekly.db echo -en "\n***Historical records***\n" echo "select * from usage;" | sqlite3 -header -column /root/openstack-weekly.db echo -en "\n\nGenerated by /root/simple-report.sh from $(hostname)"