#!/usr/bin/sh #---------------------------------------------------------------------------------- # /var/install/bin/nut-show-chart - show nut chart # # Copyright (c) 2015-2024 The Eisfair Team, team(at)eisfair(dot)org # # Creation: 2015-09-26 jed # Last Update: $Id$ # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------------- # load eislib etc. . /var/install/include/eislib # exec 2>/tmp/nut-show-chart-trace-$$.log # set -x # variables configfile=/etc/config.d/nut logdir=/var/log act_pmode=`get_printmode` # check if screensize handling is available if [ -n "${_EISLIB_SCREENSIZE_Y}" ] then if check_screensize then # # define maxrownum = _EISLIB_SCREENSIZE # - 3 Header Lines # - 1 Footer Lines # ask line max_width=`expr ${_EISLIB_SCREENSIZE_X} - 1` max_height=`expr ${_EISLIB_SCREENSIZE_Y} - 2` true else mecho --info "Return to calling script" exit 1 fi else # default if screensize handling is not available max_width=80 max_height=21 fi # show current screensize on the screen #echo "X:$_EISLIB_SCREENSIZE_X"; echo "Y:$_EISLIB_SCREENSIZE_Y"; echo "W:${max_width} H:${max_height}"; anykey # check if gnuplot package has been installed. while [ ! -f /var/install/packages/gnuplot ] do mecho --error "The required gnuplot package couldn't be found!" echo if /var/install/bin/ask "Do you want to install the package now?" "yes" then /var/install/bin/install-package -y -p 'gnuplot' -v '2.0.0' if [ $? -eq 0 ] then mecho --info "The gnuplot package has successfully been installed." fi else mecho "The gnuplot package installation has been aborted." exit 1 fi done default_upsname='ups' . ${configfile} idx=1 ups_idx=1 ups_list=':' while [ ${idx} -le ${NUT_SERVER_N} ] do eval active='$NUT_SERVER_'${idx}'_ACTIVE' if [ "${active}" = "yes" ] then eval uname='$NUT_SERVER_'${idx}'_UPSNAME' eval desc='$NUT_SERVER_'${idx}'_COMMENT' if [ -n "${uname}" ] then upsname="${uname}" else upsname="${default_upsname}" fi # check if ups name has already been used echo "${ups_list}" | grep -q ":${upsname}," if [ $? -ne 0 ] then # ups name is uniq, use it ups_list="${ups_list}${upsname}:" else # create individual ups name upsname="${upsname}-${idx}" ups_list="${ups_list}${upsname}:" fi eval ups_${ups_idx}_upsname="${upsname}" eval ups_${ups_idx}_desc="${desc}" ups_idx=`expr ${ups_idx} + 1` fi idx=`expr ${idx} + 1` done ups_n=`expr ${ups_idx} - 1` endupsflag=0 until [ ${endupsflag} -eq 1 ] do clrhome mecho --info "Show UPS data as chart" mecho techo --begin '4r 10 30' techo --row --info "Nbr" --info "name" --info "comment" idx=1 while [ ${idx} -le ${ups_n} ] do eval upsname='$ups_'${idx}'_upsname' eval desc='$ups_'${idx}'_desc' techo --row "${idx}" "${upsname}" "${desc}" idx=`expr ${idx} + 1` done techo --end mecho /var/install/bin/ask "Please enter ups number (1-${ups_n}) or (q)uit:" '' '+' > /tmp/ask.$$ rc=$? nbr=`cat /tmp/ask.$$` rm -f /tmp/ask.$$ if [ $rc = 255 ] then exit 1 fi case "${nbr}" in [qQ] ) endupsflag=1 exit 1 ;; [0-9]|[1-9][0-9] ) ### number entered ### endchartflag=0 until [ ${endchartflag} -eq 1 ] do eval upsname='$ups_'${nbr}'_upsname' clrhome mecho --info "Show UPS data for ups '${upsname}' ..." if [ ${nbr} -ge 1 -a ${nbr} -le ${ups_n} ] then echo echo "Which data do you want to chart?" echo techo --begin '4r 30' techo --row --info "Nbr" --info "data" # check if log data exists file_name="${logdir}/nut-upslog-${upsname}.log" if [ -s ${file_name} ] then techo --row "1" "UPS charge" selstr="1" techo --row "2" "UPS load" selstr="${selstr},2" if [ `tail -n10 ${file_name} | cut -d, -f9 | grep "^NA" | wc -l` -ne 10 ] then techo --row "3" "UPS temperature" selstr="${selstr},3" else techo --row "-" "UPS temperature" fi techo --row "4" "UPS input voltage" selstr="${selstr},4" if [ `tail -n10 ${file_name} | cut -d, -f7 | grep "^NA" | wc -l` -ne 10 ] then techo --row "5" "UPS input frequency" selstr="${selstr},5" else techo --row "-" "UPS input frequency" fi techo --end mecho /var/install/bin/ask "Please enter the data number to chart (${selstr}) or (q)uit:" '' '+' > /tmp/ask.$$ crc=$? cnbr=`cat /tmp/ask.$$` rm -f /tmp/ask.$$ if [ ${crc} = 255 ] then exit 1 fi case "${cnbr}" in [qQ] ) # endupsflag=1 endchartflag=1 ;; [1-5] ) ### number entered ### xlabel='Time/Date\n(H:M/dd.mm.)' xformat='%H:%M\n%d.%m.' echo ",${selstr}," | grep -q ",${cnbr}," if [ $? -eq 0 ] then case ${cnbr} in 1 ) chart_type='charge' xcolumn=5 ylabel='Pct.(in %)' title='USV charge' ;; 2 ) chart_type='load' xcolumn=8 ylabel='Pct.(in %)' title='USV load' ;; 3 ) chart_type='temp' xcolumn=9 ylabel='Temp.(in °C)' title='USV temperature' ;; 4 ) chart_type='inpvolt' xcolumn=6 ylabel='Volt.(in V)' title='USV input voltage' ;; 5 ) chart_type='inpfreq' xcolumn=7 ylabel='Freq.(in Hz)' title='USV input frequency' ;; esac # DATE TIME,PID,UPSID,STATUS,BATT-CHARGE,INP-VOLT,INP-FREQ,UPS-LOAD,UPS-TEMP, # 2015-09-25,21:16,9873,UPSJED01,OL,100.0,230.1,50.00,010.9,034.6, clrhome /usr/bin/nut-plot-chart.sh -c "${xcolumn}" -fx "${xformat}" \ -s "${max_width}:${max_height}" -t "${title}" -x "${xlabel}" \ -y "${ylabel}" ${file_name} # experimental, only for testing purposes # watch -d -n 10 -t "/usr/bin/gnuplot-chart.sh -c \"${xcolumn}\" -fx \"${xformat}\" \ # -s \"${max_width}:${max_height}\" -t \"${title}\" -x \"${xlabel}\" \ # -y \"${ylabel}\" ${file_name}" anykey else mecho --warn "Invalid selection '${cnbr}' entered!" anykey fi ;; * ) ;; esac else mecho --warn "No data logged for UPS '${upsname}'!" fi fi done ;; * ) ;; esac done exit 0