1

We currently have a server monitor script monitoring 63 servers, and we want to add another 40 servers to this script. The problem being is that we would like to keep the entire contents of the script on a single monitor (turned 90degrees).

I am wondering if at all it is possible to output 2 servers on one line, and if it is possible how its done. for example

We currently have

web1                        | 2.11 | 2.05 | 1.95 | (116) HTTP Processes
web2                        | 0.06 | 0.12 | 0.15 | (113) HTTP Processes

data1                       | 1.04 | 0.93 | 0.90 |
data2                       | 0.36 | 0.52 | 0.43 |
data3                       | 0.41 | 0.31 | 0.28 |
data4                       | 1.48 | 1.41 | 1.28 |
data5                       | 1.10 | 1.07 | 1.10 |
data6                       | 5.60 | 4.78 | 4.08 |
data7                       | 0.30 | 0.31 | 0.29 |
data8                       | 1.44 | 2.18 | 2.00 |
data9                       | 0.11 | 0.22 | 0.26 |
data10                      | 0.19 | 0.25 | 0.31 |

sql1                        | 0.42 | 0.58 | 0.61 |
sql2                        | 0.26 | 0.24 | 0.27 |
sql3                        | 0.06 | 0.08 | 0.09 |

What we would like to do is:

web1           | 2.11 | 2.05 | 1.95 | (116) HTTP Processes
web2           | 0.06 | 0.12 | 0.15 | (113) HTTP Processes

data1          | 1.04 | 0.93 | 0.90 | - data6          | 5.60 | 4.78 | 4.08 |
data2          | 0.36 | 0.52 | 0.43 | - data7          | 0.30 | 0.31 | 0.29 |
data3          | 0.41 | 0.31 | 0.28 | - data8          | 1.44 | 2.18 | 2.00 |
data4          | 1.48 | 1.41 | 1.28 | - data9          | 0.11 | 0.22 | 0.26 |
data5          | 1.10 | 1.07 | 1.10 | - data10         | 0.19 | 0.25 | 0.31 |

sql1           | 0.42 | 0.58 | 0.61 |
sql2           | 0.26 | 0.24 | 0.27 |
sql3           | 0.06 | 0.08 | 0.09 |

etc etc

As you can see we want to group certain server types together (web, cassandra, sql, grid).

The script monitors average loads, so need to fit that in too (plenty of space on the monitor to display this)

Possible or am i asking the impossible?

The current script:

cleanquit () {
echo "$(tput sgr0)"
clear
exit $?
 }

 trap cleanquit SIGINT

 clear

 while [ 1 ]
 do
 tput cup 0 0

 echo "$(tput sgr0)"

 for i in web1 web2 data1 data2 data3 data4
if [ $i == "space" ]; then
    echo "$(tput setaf 7)"
    UPS=""
else

if [ $i == "self" ]; then
        UPTIME=$(cat /proc/loadavg);
    else
        UPTIME=$(ssh root@$i cat /proc/loadavg);
    fi

    if [ -z "$UPTIME" ]; then
        tput cuu1
        tput el
        printf " $(tput setaf 1)%-25s\t | CONNECTION FAILED  |\n" $i;
    else
        thisloadavg1=$(echo $UPTIME|awk '{ print $1}' | bc -q 2>/dev/null)
        thisloadavg2=$(echo $UPTIME|awk '{ print $2}' | bc -q 2>/dev/null)
        thisloadavg3=$(echo $UPTIME|awk '{ print $3}' | bc -q 2>/dev/null)
        additional=""

        if [ ${i:0:3} == "web" -o ${i:0:4} == "grid" ]; then
            additional=$(ssh root@$i ps aux | grep "sbin/http" | wc -l)
            if [ $additional -gt 0 ]; then
                additional="("$additional") HTTP Processes"
            else
                additional=""
            fi
        fi

        if [ $i == "self" ]; then

            additional=$(ps aux | grep "sbin/http" | wc -l)
            if [ $additional -gt 0 ]; then
                additional="("$additional") HTTP Processes"
            else
                additional=""
            fi

        fi

        if [ $(echo "$thisloadavg1 > 5.0" | bc) -eq 1 ]; then
            printf " $(tput setaf 1)%-25s\t $(tput setaf 7)|$(tput setaf 1) %0.2f $(tput setaf 7)|$(tput setaf 1) %0.2f $(tput setaf 7)|$(tput setaf 1) %0.2f $(tput setaf 7)| %s %s %s\n" $i $thisloadavg1 $thisloadavg2 $thisloadavg3 $additional;
        else
            if [ $(echo "$thisloadavg1 > 3.0" | bc) -eq 1 ]; then
                printf " $(tput setaf 3)%-25s\t $(tput setaf 7)|$(tput setaf 3) %0.2f $(tput setaf 7)|$(tput setaf 3) %0.2f $(tput setaf 7)|$(tput setaf 3) %0.2f $(tput setaf 7)| %s %s %s \n" $i $thisloadavg1 $thisloadavg2 $thisloadavg3 $additional;
            else
                if [ $(echo "$thisloadavg1 > 1.5" | bc) -eq 1 ]; then
                    printf " $(tput setaf 6)%-25s\t $(tput setaf 7)|$(tput setaf 6) %0.2f $(tput setaf 7)|$(tput setaf 6) %0.2f $(tput setaf 7)|$(tput setaf 6) %0.2f $(tput setaf 7)| %s %s %s \n" $i $thisloadavg1 $thisloadavg2 $thisloadavg3 $additional;
                else
                    printf " $(tput setaf 7)%-25s\t | %0.2f | %0.2f | %0.2f | %s %s %s\n" $i $thisloadavg1 $thisloadavg2 $thisloadavg3 $additional;
                fi
            fi
        fi
    fi

fi
tput el
done

echo

tput sgr0
tput ed
sleep 2;
done`
8
  • 1
    Please post some actual code that shows how you're printing the output. Commented Mar 20, 2012 at 14:27
  • 1
    if you have such amount of servers monitored, why don't you move to more sophisticated monitoring tools like Nagios. It has grouping and average load monitoring out of the box. Commented Mar 20, 2012 at 14:35
  • @EduardoIvanec current code added. Commented Mar 20, 2012 at 14:59
  • @hovanessyan we have looked at nagios and although it does a lot of things, this is a realtime monitoring of the loads of our systems in one place. Nagios also takes a lot of time to setup, this script forms just a small part of our entire monitoring system. :) Commented Mar 20, 2012 at 15:01
  • Sure Nagios requires some time to get used to the configuration. Although the basic setup could be 1 line in linux and 10 mins of package downloads :). Also it can provide near-real-time average-load monitoring (or monitoring of other parameters as a matter of fact) but in most cases this causes unnecessary high bandwidth in the network - most people avoid it. Commented Mar 20, 2012 at 15:13

2 Answers 2

2

You can use the column standard filter to columnate arbitrary input.

2
  • @J.F.Sebastian: it works perfectly in my terminal. It also worked correctly in your Ideone snippet when I added a newline after the last input entry. Try column -c 20 for better output. Commented Mar 20, 2012 at 16:01
  • @EduardoIvanec nice, but problem being we dont want all the servers displayed like this, only certain ones, how would this fit in to the existing code we have? Commented Mar 20, 2012 at 16:05
1

The pr filter can put data in columns. It was designed to lay out line printer pages with headers and footers, but at least GNU pr lets you turn off those things. Try pr -bt3 <input.txt for three-column output.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.