2 # the next line restarts using tclsh -*- tcl -*- \
3 exec tclsh8.2 "$0" "$@"
5 #package require Tnm 3.0
6 package require Rrd 1.0.13
8 set rrdfile "[lindex $argv 0]-[lindex $argv 1].rrd"
10 # create rrdfile if not yet existent
11 if {[file exists $rrdfile] == 0} {
12 Rrd::create $rrdfile --step 5 \
13 DS:inOctets:COUNTER:10:U:U DS:outOctets:COUNTER:10:U:U \
17 # get an snmp session context
18 set session [Tnm::snmp generator -address [lindex $argv 0]]
20 # walk through the ifDescr column to find the right interface
21 $session walk descr IF-MIB!ifDescr {
23 # is this the right interface?
24 if {"[Tnm::snmp value $descr 0]" == "[lindex $argv 1]"} {
26 # get the instance part of this table row
27 set inst [lindex [Tnm::mib split [Tnm::snmp oid $descr 0]] 1]
29 # get the two interface's octet counter values
30 set in [lindex [lindex [$session get IF-MIB!ifInOctets.$inst] 0] 2]
31 set out [lindex [lindex [$session get IF-MIB!ifOutOctets.$inst] 0] 2]
33 # write the values to the rrd
35 Rrd::update $rrdfile --template inOctets:outOctets N:$in:$out
37 Rrd::graph gaga.png --title "gaga" \
38 DEF:in=$rrdfile:inOctets:AVERAGE \
39 DEF:out=$rrdfile:outOctets:AVERAGE \
40 AREA:in#0000FF:inOctets \
41 LINE2:out#00C000:outOctets
43 #puts [Rrd::fetch $rrdfile AVERAGE]