UPC / ravada

Remote Virtual Desktops Manager
https://ravada.upc.edu/
GNU Affero General Public License v3.0
543 stars 174 forks source link

Script to generate graphics #1312

Open dani-sanchez-dorado opened 4 years ago

dani-sanchez-dorado commented 4 years ago

Related to create reports for my boss, I made this script to pass data to mi graph system (RRDgraph based). Feel free to use, distribute or modify

!/bin/sh

# Simple data extractor for RAVADA # Daniel Sanchez Dorado Apr 2020 - UPC # Feel free to distribute or modify

VIRSHBIN=/usr/bin/virsh GREP=/bin/grep WC=/usr/bin/wc AWK=/usr/bin/awk FREE=/usr/bin/free CPUINFO=/proc/cpuinfo CAT=/bin/cat VMSTAT=/usr/bin/vmstat TAIL=/usr/bin/tail ########

# Total memory available TOTAL_MEM=`$FREE -g | grep -i mem | $AWK '{ print $2 }' ` echo "$TOTAL_MEM :TOTAL_MEM"

# Used memory USED_MEM=`$FREE -g | grep -i mem | $AWK '{ print $3 }' ` echo "$USED_MEM :USED_MEM "

# total CPU total available TOTAL_CPU=`$CAT $CPUINFO | $GREP processor | $WC -l ` echo "$TOTAL_CPU :TOTAL_CPU"

# CPU total use #cheat: ~--># vmstat -w #procs -----------------------memory---------------------- ---swap-- -----io---- -system-- --------cpu-------- # r b swpd free buff cache si so bi bo in cs us sy id wa st # 0 0 0 119939312 870268 7129104 0 0 2 8 3 7 1 0 99 0 0 # we will use r+b #FIELD DESCRIPTION FOR VM MODE # r: The number of runnable processes (running or waiting for run time). # b: The number of processes in uninterruptible sleep. USED_CPU=$VMSTAT -w | $TAIL -1 | $AWK '{ print $1 + $2 }' echo "$USED_CPU :USED_CPU"

# Defined vm MAQUINAS_CREATED=`$VIRSHBIN list --all | $GREP -vi ID | $GREP -v "--" | $GREP "-" | $WC -l` echo "$MAQUINAS_CREATED :TOTAL_VM "

# Running vw MAQUINAS_RUNNING=`$VIRSHBIN list | $GREP -vi ID | $GREP -v "--" | $GREP "-" | $WC -l` echo "$MAQUINAS_RUNNING :RUNNING_VM "

Here you can see some results: report_example

report_example2

That's all.

frankiejol commented 4 years ago

Hey, this is nice, there are missing backiticks in this line but it worked when I fixed it: USED_CPU=$VMSTAT -w | $TAIL -1 | $AWK '{ print $1 + $2 }'

frankiejol commented 4 years ago

@dani-sanchez-dorado I made a boilerplate document so you can insert you script there. Just follow this step-by-step guide to add the script in the documentation. https://ravada.readthedocs.io/en/latest/docs/new_documentation.html

If you put the script on branch gh-pages, at docs/docs/report_rrd.sh it will appear on our docs and you will get proper attribution.