Summary/Total data from several hosts
list Darren Cotton
I have 5 hosts on which I have script monitoring connected users. This is
then sent to hobbit and as a result I have 5 separate entries which I then
want to total on the server.
Currently I am parsing the tmp file to get the number of users as follows:
DSLGWS="server1 server2 server3 server4 server5"
SERVICE=Total-Users
BBPROG=bb-pusers.sh; export BBPROG
RESULT=0
COLOR="clear"
BBTMP="/usr/lib/hobbit/server/tmp"
for USERS in $DSLGWS
do
if [ -f $BBTMP/hobbitd.chk ]; then
NBUSERS=`cat $BBTMP/hobbitd.chk | grep pusers | grep $USERS
| sed 's/.*: //g' | tr -d '\\' | sed 's/n.*//g' | bc`
RESULT=`echo "$RESULT+$NBUSERS" | bc`
else
echo "Unable to find "$BBTMP/hobbitd.chk" Sending 0 total
users"
RESULT=0
fi
done
MACHINE=$SERVICE
$BB $BBDISP "status $MACHINE.pusers $COLOR `date`
Connected_Users : $RESULT
"
Now this works but I think it is an ugly way of going about it - Is there
another simpler/better way of going about this that I cant see.
DISCLAIMER:
This e-mail contains proprietary information some or all of which may be legally privileged. It is for the intended recipient only. If an addressing or transmission error has misdirected this e-mail, please notify the author by replying to this e-mail. If you are not the intended recipient you must not use, disclose, distribute, copy, print, or rely on this e-mail.
list Henrik Størner
▸
On Wed, Oct 03, 2007 at 11:36:49AM +0200, user-326ea6859343@xymon.invalid wrote:
I have 5 hosts on which I have script monitoring connected users. This is then sent to hobbit and as a result I have 5 separate entries which I then want to total on the server. Currently I am parsing the tmp file to get the number of users as follows:
I'd use the hobbitdboard query against the server:
DSLGWS="^server[12345]\$"
RESULT=0
bb 127.0.0.1 "hobbitdboard host=${DSLGWS} test=pusers fields=msg" | \
while read L
do
NBUSERS=...whatever is needed to grab the number...
RESULT=`expr $RESULT + $NBUSERS`
done
Grabbing data from the checkpoint file suffers from the fact that by
default it is only updated once every 15 minutes, so it takes a long
time for changes to filter through to that file. By using the
hobbitdboard command, you always get the latest data that Hobbit has.
Regards,
Henrik
list Darren Cotton
Thanks Henrik,
I just having one small problem now - I can't send the data I get to
hobbit....
Output of the bb query is:
status server1.pusers green Wed Oct 3 12:40:00 UTC 2007\nConnected_Users :
175\n
DSLGWS="^server[12345]\$"
RESULT=0
bb 212.56.225.37 "hobbitdboard host=${DSLGWS} test=pusers fields=msg" | \
while read L
do
NBUSERS=`echo "$L" | sed 's/.* //g' | sed 's/n//g'`
RESULT=`expr $RESULT + $NBUSERS`
echo $RESULT
done
echo $RESULT
$BB $BBDISP "status Total-Users.pusers green `date`
Connected_Users : $RESULT
"
The first echo gives me the Total after each while/do ie.
186
370
527
677
839
but the second echo gives me 0. I've tried using export RESULT but can't
seem to be able to get the RESULT outside of the while/do statement.
Darren
user-ce4a2c883f75@xymon.invalid
(Henrik Stoerner)
To
03/10/2007 13:08 user-ae9b8668bcde@xymon.invalid
cc
Please respond to Subject
user-ae9b8668bcde@xymon.invalid Re: [hobbit] Summary/Total data
from several hosts
▸
On Wed, Oct 03, 2007 at 11:36:49AM +0200, user-326ea6859343@xymon.invalid
wrote:I have 5 hosts on which I have script monitoring connected users. This is then sent to hobbit and as a result I have 5 separate entries which I then want to total on the server. Currently I am parsing the tmp file to get the number of users as follows:
I'd use the hobbitdboard query against the server:
DSLGWS="^server[12345]\$"
RESULT=0
bb 127.0.0.1 "hobbitdboard host=${DSLGWS} test=pusers fields=msg" | \
while read L
do
NBUSERS=...whatever is needed to grab the number...
RESULT=`expr $RESULT + $NBUSERS`
done
Grabbing data from the checkpoint file suffers from the fact that by
default it is only updated once every 15 minutes, so it takes a long
time for changes to filter through to that file. By using the
hobbitdboard command, you always get the latest data that Hobbit has.
Regards,
Henrik
DISCLAIMER:
This e-mail contains proprietary information some or all of which may be legally privileged. It is for the intended recipient only. If an addressing or transmission error has misdirected this e-mail, please notify the author by replying to this e-mail. If you are not the intended recipient you must not use, disclose, distribute, copy, print, or rely on this e-mail.
list Ralph Mitchell
▸
On 10/3/07, user-326ea6859343@xymon.invalid <user-326ea6859343@xymon.invalid> wrote:
Thanks Henrik,
I just having one small problem now - I can't send the data I get to
hobbit....
Output of the bb query is:
status server1.pusers green Wed Oct 3 12:40:00 UTC 2007\nConnected_Users :
175\n
DSLGWS="^server[12345]\$"
RESULT=0
bb 212.56.225.37 "hobbitdboard host=${DSLGWS} test=pusers fields=msg" | \
while read L
do
NBUSERS=`echo "$L" | sed 's/.* //g' | sed 's/n//g'`
RESULT=`expr $RESULT + $NBUSERS`
echo $RESULT
done
echo $RESULT
$BB $BBDISP "status Total-Users.pusers green `date`
Connected_Users : $RESULT
"
The first echo gives me the Total after each while/do ie.
186
370
527
677
839
but the second echo gives me 0. I've tried using export RESULT but can't
seem to be able to get the RESULT outside of the while/do statement.
I've had the same problem occasionally. I don't know what the
"proper" solution is, but this works for me:
RES=`bb 212.56.225.37 "hobbitdboard host=${DSLGWS} test=pusers
▸
fields=msg" | \
while read L
do
NBUSERS=\`echo "$L" | sed 's/.* //g' | sed 's/n//g'\`
RESULT=\`expr $RESULT + $NBUSERS\`
echo $RESULT
done`
echo $RES
I.e., enclose the whole while loop in backticks, and also escape all
backticks within the outer set. *Anything* echoed inside the outer
set of backticks becomes part of the value of $RES, which makes
debugging tricky.
T'ain't pretty, but it works and it's all in shell...
Ralph Mitchell