[prev in list] [next in list] [prev in thread] [next in thread]
List: tkined
Subject: Re: scotty
From: Ed Phillips <flaregun () UDel ! Edu>
Date: 1996-05-09 9:42:00
[Download RAW message or body]
On Thu, 9 May 1996, Juergen Schoenwaelder wrote:
> Hi!
>
> Ed Phillips <flaregun@UDel.Edu> said:
>
> Ed> I've written a scotty program that continuously monitors MIB
> Ed> vars on our backbone routers and writes them into a file, and
> Ed> occasionally generate syslogs if there's a problem. The only
> Ed> problem I have is that the scotty process is growing. My
> Ed> program started out at about 2.5MB and grew to 32MB in a
> Ed> matter of days! I thought that maybe the version of tcl/tk I
> Ed> had compiled against was too shabby so I got the patches (tk
> Ed> 4.3p3 and tcl 7.4p3), but still, the process is growing. Does
> Ed> this sound like a correctable problem? Maybe something I do
> Ed> in the tcl code? Do I have to call some kind of garbage
> Ed> collection routine to occasionally clean up unused variables
> Ed> (I'm guessing at this point)? Also, is there a scotty mailing
> Ed> list?
>
> Well, it is hard to tell what is going wrong here. You usually do not
> have to care about memory issues when programming in Tcl. Variables
> are created and automatically freed when leave the scope of a
> procedure. You only have to take care of global variables which exists
> until you destroy them (unset) or you kill the interpreter.
I would hope so ;-)
>
> I it also possible that there is a memory leak in the scotty or the
> Tcl code. However, I did not receive complaints about it yet. The Tcl
> interpreter has a compile-time options which you can set in the
> Makefile which allows to track memory problems. Note, you have to turn
> this option on in all Makefiles of all extension you want to use.
>
> Another way to debug thinks is to try to strip the script down to the
> basics just to see where the problem happens. If you can come up with
> a small example that shows the problem, I can probably provide further
> assistence.
>
I made a stripped down version of my script that exhibits the
"growth problem" which can be seen very quickly. I've attached it to this
message.
> The mailing list for scotty is tkined@ibr.cs.tu-bs.de. You can
> subscribe to this list by sending email to
>
Thanks... I am now subscribed! :-)
> tkined-request@ibr.cs.tu-bs.de
>
> Juergen
>
Thanks,
Ed
+-------------------------------------------------------------------------+
| Ed Phillips <flaregun@udel.edu> University of Delaware (302) 831-6082 |
| Associate Systems Programmer, Network and Systems Services |
| Public key footprint: 1C D4 AC C2 A3 D5 97 AA DB 3B D8 85 88 E7 40 B8 |
| finger -l flaregun@polycut.nss.udel.edu for PGP public key |
+-------------------------------------------------------------------------+
["test.tcl" (TEXT/PLAIN)]
#!/opt/tcltk/bin/scotty -f
# Set these to control what is monitored (interval is in seconds)
set hostlist [list thishost thathost]
set community thatstring
set vars [list ifInErrors ifOutErrors]
set interval 10
set log_file "testlog"
set debug 1
# These don't need to be changed
set hosts [list]
set interfaces(0) 0
set num_interfaces(0) 0
set miss(0) 0
# NetMon - takes a hostname and a list of variables to get, retrieves them, and
# saves them in a log file along with a timestamp.
# tries to send fewer packets by retrieving 10 vars at a time
# this seems to work well and if you're getting lots of vars,
# it is much faster.
proc NetMon {thishost jvars} {
global s
set vlist $jvars
set partial [lrange $vlist 0 9]
set leftover [lrange $vlist 10 end]
while {[llength $partial] > 0} {
$s($thishost) get $partial {
global debug miss
set h [%S cget -address]
if {"%E" != "noError"} {
incr miss($h)
if {$miss($h) >= 5} {
syslog LOG_CRIT "test: $h %E"
set miss($h) 0
}
return
}
set tt [getclock]
set logf [open $log_file a]
foreach i "%V" {
set oid [lindex $i 0]
set vv [lindex $i 2]
set name [mib name $oid]
if $debug {
puts "$h $name $tt $vv"
}
puts $logf "$h $name $tt $vv"
}
close $logf
set miss($h) 0
}
set partial [lrange $leftover 0 9]
set leftover [lrange $leftover 10 end]
}
snmp wait
flush stdout
}
# Queries to see which interfaces are administratively up and adds this
# info to the array "interfaces()" and the hostname to the list "hosts"
proc AddHost {hname} {
global s hosts interfaces num_interfaces debug community
if {[lsearch -exact $hosts $hname] >= 0} {
return
}
lappend hosts $hname
set miss($hname) 0
set code [catch {snmp session -address $hname -community $community} s($hname)]
if $code {
puts "error opening snmp session for $hname"
syslog LOG_CRIT "netmon: error opening snmp session for $hname"
puts $s($hname)
exit 1
}
set interfaces($hname) ""
set n [$s($hname) get ifNumber.0]
set nn [lindex [lindex $n 0] 2]
set nup 0
for {set i 1} {$i <= $nn} {incr i} {
set val [$s($hname) get ifAdminStatus.$i]
set v [lindex [lindex $val 0] 2]
if {$v == "up"} {
lappend interfaces($hname) $i
}
incr nup
}
set num_interfaces($hname) $nup
if $debug {
puts "host $hname session started: $nup interfaces active"
}
}
# Main section
# call AddHost for each host
foreach i $hostlist {
AddHost $i
}
# create a job for each host that queries each interface to get the desired
# list of vars
#foreach i $hosts {
# set varlist [list]
# set miss($i) 0
# foreach j $vars {
# foreach k $interfaces($i) {
# lappend varlist $j.$k
# }
# }
# set r [job create [list NetMon $i $varlist] 10000]
# puts "$r started"
#}
#job wait
# alternate version without the job stuff
foreach i $hosts {
set miss($i) 0
}
while 1 {
set lasttime [getclock]
foreach i $hosts {
set varlist [list]
foreach j $vars {
foreach k $interfaces($i) {
lappend varlist $j.$k
}
}
NetMon $i $varlist
}
set waittime [expr $lasttime + $interval - [getclock]]
if {$waittime > 0} {
sleep $waittime
}
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic