UPD: logging usage to sqlite

This commit is contained in:
xpk 2021-02-25 15:56:18 +08:00
parent f759c37e40
commit b0deed20cc
Signed by: xpk
GPG Key ID: CD4FF6793F09AB86
1 changed files with 30 additions and 7 deletions

View File

@ -6,15 +6,38 @@ 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 | column -t -s, | tr -d \"
openstack usage list -f csv --quote none | column -t -s,
echo -en "\n***Ceph info***\n"
ceph df | grep -v "0 B"
ceph osd df tree | grep host | awk '{print $NF,$(NF-4)"% Used"}'
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***Detail host usage***\n"
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
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\nGenerated by /root/openstack-simple-report.sh from $(hostname)"
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)"