Nov 18, 2009

RRD Monitoring tool for FlexLM




These are some BASH scripts which generate RRD databases for FlexLM servers.

First, here is the crontab entry :
*/5 * * * * /root/scripts/ansys_lic


Here is the script ansys_lic (which monitors every 5mn the status of a FlexLM server) :
#!/bin/bash

lmutil="/usr/local/flexlm/lmutil"
license="27000@192.168.100.100"
stockage="/data/rrd"
rep_logs="/root/logs"
rep_img="/data/www/monitoring"
declare -ar features='([0]="abaqus" [1]="cae" [2]="viewer" [3]="standard" [4]="explicit" [5]="foundation" )'
declare -ar features_aff='([0]="abaqus" [1]="cae" [2]="viewer" )'
declare -ar couleurs='([0]="#FF0000" [1]="#00D832" [2]="#1C05EA" [3]="#B505EA" [4]="#DDA0DD" [5]="#9ACD32" [6]="#008000" [7]="#0000FF" [8]="#6A5ACD" [9]="#48D1CC")'
declare -ar durees='([0]="1" [1]="10" [2]="30" [3]="90" )'

creation_rrd(){

if [ ! -f $stockage/abaqus_lic.rrd ]
then
echo "rrdtool create $stockage/abaqus_lic.rrd -s 300 \\" > /tmp/create.sh
for i in ${features[*]}
do
echo "DS:$i:GAUGE:600:U:U \\" >> /tmp/create.sh
echo "RRA:MAX:0.5:1:2880 \\" >> /tmp/create.sh
echo "RRA:AVERAGE:0.5:12:480 \\" >> /tmp/create.sh
echo "RRA:AVERAGE:0.5:60:240 \\" >> /tmp/create.sh
done
echo >> /tmp/create.sh
. /tmp/create.sh
rm -f /tmp/create.sh
fi
}

maj_rrd(){
$lmutil lmstat -a -c $license > /tmp/abaqus_lic.log
commande="rrdtool update $stockage/abaqus_lic.rrd N"
for i in ${features[*]}
do
used=$(grep $i /tmp/abaqus_lic.log | grep Total |head -1| awk '{print $11}')
commande=$commande":$used"
done
$($commande)
}

creation_graph(){
for d in ${durees[*]}
do
echo "rrdtool graph $rep_img/abaqus_lic_"$d".png \\" > /tmp/graph_abaqus.sh
echo "-s \"now -"$d" day\" -e now \\" >> /tmp/graph_abaqus.sh
echo "--title=\"Occupation du serveur de licences Abaqus, "$i" derniers jours\" \\" >> /tmp/graph_abaqus.sh
echo "--vertical-label=Nombre \\" >> /tmp/graph_abaqus.sh
echo "--imgformat=PNG \\" >> /tmp/graph_abaqus.sh
echo "--color=BACK#CCCCCC \\" >> /tmp/graph_abaqus.sh
echo "--color=CANVAS#343434 \\" >> /tmp/graph_abaqus.sh
echo "--color=SHADEB#9999CC \\" >> /tmp/graph_abaqus.sh
echo "--width=800 \\" >> /tmp/graph_abaqus.sh
echo "--base=1000 \\" >> /tmp/graph_abaqus.sh
echo "--height=600 \\" >> /tmp/graph_abaqus.sh
echo "--interlaced \\" >> /tmp/graph_abaqus.sh
echo "--upper-limit=36 \\" >> /tmp/graph_abaqus.sh
echo "AREA:32#F6FACF:\"32 Licences Max\" \\" >> /tmp/graph_abaqus.sh
rang=0
for i in ${features_aff[*]}
do
couleur=${couleurs[$rang]}
echo "DEF:$i=$stockage/abaqus_lic.rrd:$i:MAX \\" >> /tmp/graph_abaqus.sh
echo "LINE1:"$i$couleur":\" Nombre de $i\" \\" >> /tmp/graph_abaqus.sh
#echo "VDEF:"$i"_MAX="$i",MAXIMUM \\" >> /tmp/graph.sh
rang=$( expr $rang + 1 )
done
. /tmp/graph_abaqus.sh
rm -f /tmp/graph_abaqus.sh
done
}

creation_rrd
maj_rrd
creation_graph

In this script you will have to change paths to FlexLM lmutil command and the features declared in the beginning.
Then you can also change the colors of the lines for representing the features (couleurs array) and the durations for graph generation (1 days, 10 days, 30 days and 90 days, durees array).

3 things are done in the script : first we create the RRD database (5mn between 2 records, and we keep 2880 records of these, meaning the last 10 days with precision of 5mn, then we keep 480 records of the max every 60mn, meaning 20 days, at last we keep 240 records of the max every 5hours, meaning 50 days). It's up to you to change this.
After creating the database we update the values in the RRD file, and the we re-generate the png graphic.

The final result is the image in the beginning of the post; it's the last day graph for license usage.

Have fun !

1 comment:

Unknown said...

Awesome :) , RRD tool is what i was looking for .