Re: Time marks...

Juergen Schoenwaelder (schoenw@ibr.cs.tu-bs.de)
Tue, 16 May 1995 23:26:56 +0200

Hi!

On Sat, 13 May 1995 16:05:48 +0200 (METDST),
Iztok Umek <iztok@snet.fer.uni-lj.si> said:

Iztok> Is there any way I could get time stamps into monitor for
Iztok> example of serial line on router? Like I would need load on
Iztok> serial line (link to outside) in 5 min time stamps for whole
Iztok> month.

Iztok> Hopfuly some daemon, since would be nice to log out (not being
Iztok> logged on X terminal for whole month).

Iztok> So... kinda load statistic for average of 5 min period and for longer
Iztok> period of time.

The basic idea behind Scotty is to make the implementation of
monitoring jobs a very straightforward task. To tell the truth, I
needed about 60 minutes to hack the solution appended below.
(Although I feel familiar with Scotty and Tcl - looks like I did not
reach my goal yet :-) Anyway, you can use the script by adding lines
of the form

MonitorIfLoad <ip-address> <interval-in-seconds> [<community>]

at the end of the script. I tried my best to make the code
readable. If you are interested in other SNMP statistics, please try
to understand how the script below works. It should be easy to write
your own script once you got the idea. (And let me know how much time
you needed :-)

Iztok> And second question. Will tkined one day have some daemon that
Iztok> would collect data (as netview and openview for example) in
Iztok> background... and you would view this with tkined laters?

I hope so. The idea is generalize the code below and to define some
conventions how to store results. But I have no time schedule for
this.

Iztok> And third... since lot of NS admins doesn't put HINFO in host
Iztok> tables (since they RFCs for that are really otdated) do you
Iztok> plan to set host icon based on SNMP (as in openview and
Iztok> netview)?

This is really easy to do. The most difficult thing is to compile a
list of sysObjectID / icon pairs. Does anyone have such a list? All I
have is the IANA enterprise OID list, but this won't be a good start.
(HPUX workstations would probably get a HP printer icon ;-)

Juergen

#!/bin/sh
# Tcl sees the next lines as an assignment to variable `kludge'.
# For sh, the two shifts cancel the effect of the set, and then we
# run scotty on this script.

set kludge { $*
shift
shift
if test -x ../scotty ; then
exec ../scotty -nf $0 $*
else
exec scotty -nf $0 $*
fi
}

##
## A small utility to test if a given ifType is full duplex or not.
##

proc FullDuplex { ifType } {

# Note, IANAifType (RFC 1573) has somewhat different encodings
# than RFC 1213. We use RFC 1213 style.

set fullDuplex {
regular1822 hdh1822 ddn-x25 rfc877-x25 lapb sdlc ds1 e1
basicISDN primaryISDN propPointToPointSerial ppp slip ds3 sip
frame-relay
}

return [expr [lsearch $fullDuplex $ifType] < 0]
}

##
## Calculate the interface utilisation. This is done using the formula
##
## util = ( 8 * ( delta (ifInOctets, t1, t0)
## + delta (ifOutOctets, t1, t0) ) / (t1 - t0) ) / ifSpeed
##
## This formula returns incorrect results for full-duplex point to point
## links. In this case, the following formula should be used:
##
## util = ( 8 * max ( delta (ifInOctets, t1, t0) ,
## delta (ifOutOctets, t1, t0) ) / (t1 - t0) ) / ifSpeed
##
## See Simple Times, 1(5), November/December, 1992 for more details.
##

proc GetIfLoad {} {
global cx
set id [job current]
set ifIndex $cx($id,ifIndex)

set vbl [$cx($id,session) get \
"sysUpTime.0 ifInOctets.$ifIndex ifOutOctets.$ifIndex"]

set sysUpTime [mib scan sysUpTime [lindex [lindex $vbl 0] 2]]
set ifInOctets [lindex [lindex $vbl 1] 2]
set ifOutOctets [lindex [lindex $vbl 2] 2]

set deltaIn [expr $ifInOctets - $cx($id,ifInOctets)]
set deltaOut [expr $ifOutOctets - $cx($id,ifOutOctets)]

if {$cx($id,duplex)} {
set delta [expr $deltaIn > $deltaOut ? $deltaIn : $deltaOut]
} else {
set delta [expr $deltaIn + $deltaOut]
}

if {$sysUpTime > $cx($id,sysUpTime)} {
set secs [expr ($sysUpTime - $cx($id,sysUpTime)) / 100.0]
set val [expr (8.0 * $delta / $secs) / $cx($id,ifSpeed) * 100]
} else {
set val 0
}

puts stdout [format "%s %s %d: %5.2f %% (%s)" [getclock] \
[$cx($id,session) cget -address] $ifIndex $val $cx($id,ifDescr)]

set cx($id,sysUpTime) $sysUpTime
set cx($id,ifInOctets) $ifInOctets
set cx($id,ifOutOctets) $ifOutOctets
}

##
## Start a new interface load monitoring job for the given SNMP session.
## The ifIndex parameter contains the interface index and interval the
## monitoring interval in seconds. We retrieve some information from
## the agent to initialize the monitor jobs. Afterwards, we create a
## new job and store the job parameters in a global array.
##

proc StartIfLoadMonitor { s ifIndex interval } {
global cx

set vbl [$s get [list sysUpTime.0 \
ifInOctets.$ifIndex ifOutOctets.$ifIndex \
ifSpeed.$ifIndex ifDescr.$ifIndex ifType.$ifIndex ]]

set id [job create GetIfLoad [expr $interval * 1000]]

set cx($id,session) $s
set cx($id,ifIndex) $ifIndex
set cx($id,sysUpTime) [lindex [lindex $vbl 0] 2]
set cx($id,sysUpTime) [mib scan sysUpTime $cx($id,sysUpTime)]
set cx($id,ifInOctets) [lindex [lindex $vbl 1] 2]
set cx($id,ifOutOctets) [lindex [lindex $vbl 2] 2]
set cx($id,ifSpeed) [lindex [lindex $vbl 3] 2]
set cx($id,ifDescr) [lindex [lindex $vbl 4] 2]
set cx($id,duplex) [FullDuplex [lindex [lindex $vbl 5] 2]]
}

##
## The following procedure walks the ifTable and starts an interface
## load monitoring procedure for every interface that is marked up.
##

proc MonitorIfLoad {ip seconds {community public}} {
set s [snmp session -address $ip -community $community]
$s walk vbl "ifIndex ifAdminStatus" {
set ifIndex [lindex [lindex $vbl 0] 2]
set ifAdminStatus [lindex [lindex $vbl 1] 2]
if {$ifAdminStatus == "up"} {
StartIfLoadMonitor $s $ifIndex $seconds
}
}
}

##
## Some examples to set up monitoring jobs. Make sure to use IP
## addresses as this will make more readable output.
##

# MonitorIfLoad [netdb host address ciscobs.rz] 5