code-dumps/openstack/openstack-simple-report.sh

44 lines
2.1 KiB
Bash
Raw Normal View History

2021-01-20 15:34:54 +08:00
#!/bin/bash
. /root/openrc
echo "Openstack usage generated on $(date)"
2021-01-20 16:08:30 +08:00
echo -en "\nNumber of active VMs: "
2021-01-20 15:34:54 +08:00
mysql nova -Nse "select count(1) from instances where vm_state = 'active'"
2021-01-20 16:08:30 +08:00
echo -en "\n***Usage summary***\n"
2021-02-25 15:56:18 +08:00
openstack usage list -f csv --quote none | column -t -s,
2021-01-20 16:08:30 +08:00
2021-02-25 15:56:18 +08:00
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"%"}'
2021-01-20 16:08:30 +08:00
2021-02-25 15:56:18 +08:00
echo -en "\n***Allocation per host (flavor/total)***\n"
2021-01-20 15:34:54 +08:00
echo -en "Host CPU% Memory%\n" | column -t
2021-02-25 15:56:18 +08:00
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)}'
2021-01-20 15:34:54 +08:00
2021-02-25 15:56:18 +08:00
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)"
2021-01-20 15:34:54 +08:00