[126584] in North American Network Operators' Group

home help back first fref pref prev next nref lref last post

Re: Useful TCL script?

daemon@ATHENA.MIT.EDU (Jian Gu)
Sat May 22 22:14:32 2010

In-Reply-To: <FA2E47FFA50291418803D2E7C1DF07F30B4EC97B@SDEXCL01.Proflowers.com>
Date: Sat, 22 May 2010 19:14:14 -0700
From: Jian Gu <guxiaojian@gmail.com>
To: Thomas Magill <tmagill@providecommerce.com>
Cc: nanog@nanog.org
Errors-To: nanog-bounces+nanog.discuss=bloom-picayune.mit.edu@nanog.org

Wouldn't SNMP walk/get gives you what you need?

On Thu, May 20, 2010 at 4:05 PM, Thomas Magill
<tmagill@providecommerce.com> wrote:
> I had to come up with a way to monitor average packet size on an
> interface so I wrote the following script (cisco devices). =A0I don't kno=
w
> if anyone finds it useful, but here it is if so. =A0Also, there is one
> issue with it where if the total number of packets an interface has seen
> is over 7 digits, it will not calculate it. =A0This appears to be a
> limitation of the expr command used in cisco TCL and mpexpr is not
> supported. =A0If anyone else knows a way to bypass this issue I would be
> glad to hear it. =A0For now it just tells you that the value is too high.
> I am also considering creating a job that can input the value into an
> OID that we can poll but not exactly sure how to do that so if anyone
> has any experience or good references (other than the cisco stuff I find
> on google) I would be thankful.
>
>
>
> I save this to flash: or disk: (depending on default tcl location per
> device) and assign the alias:
>
>
>
> alias exec psize tclsh psize.tcl
>
>
>
> Then use it like:
>
>
>
> Router#psize psize tun1
>
>
>
> Packet Size Information for Tunnel1
>
> ----------------------------------------------------
>
> =A05 minute input bits/sec =3D 43000
>
> =A05 minute input packets/sec =A0=3D 30
>
> =A05 minute average packet size =3D 179 Bytes
>
> ----------------------------------------------------
>
> =A05 minute output bits/sec =3D 3000
>
> =A05 minute output packets/sec =A0=3D 3
>
> =A05 minute average packet size =3D 125 Bytes
>
> ----------------------------------------------------
>
> =A0Total input bytes =3D 1678803
>
> =A0Total input packets =A0=3D 7761
>
> =A0Total average packet size =3D 216 Bytes
>
> ----------------------------------------------------
>
> =A0Total output bytes =3D 133316
>
> =A0Total output packets =A0=3D 1041
>
> =A0Total average packet size =3D 128 Bytes
>
> ----------------------------------------------------
>
>
>
> This is my first attempt at a script this complex so if you have any
> input/suggestions they are welcome.
>
>
>
> ########################################################################
> #####
>
> #
> #
>
> # psize.tcl
> #
>
> # By Thomas Magill - 5/7/2010
> #
>
> #
> #
>
> ########################################################################
> #####
>
> #
>
> # Get input from command line
>
> set ifname $argv
>
> # Check interface name for errors
>
> if {[string equal $ifname ""]} { puts "Usage: psize ifname"; return; }
>
> if { [ catch { exec "show ip interface $ifname" } errmsg ] } {
>
> puts "Invalid interface $ifname, command failed"; return}
>
> set cmdtext [ exec "show interface $ifname" ]
>
> # Pull interface information and calculate
>
> foreach line [split $cmdtext "\n"] {
>
> =A0if {[regexp -nocase {^(\S+) is (.*), line protocol is (\S+)} $line
> ignore ifnamefull ifstatus iflinkstatus]} {
>
> }
>
> =A0if {[regexp -nocase {5 minute input rate ([0-9]+) bits/sec, ([0-9]+)
> packets/sec} $line ignore bpsinfive ppsinfive]} {
>
> =A0if {$ppsinfive =3D=3D "0"} {set psizeinfive "0"} else {set psizeinfive
> [expr $bpsinfive / $ppsinfive]}
>
> =A0set psizeinfive [expr $psizeinfive / 8]
>
> }
>
> =A0if {[regexp -nocase {5 minute output rate ([0-9]+) bits/sec, ([0-9]+)
> packets/sec} $line ignore bpsoutfive ppsoutfive]} {
>
> =A0if {$ppsoutfive =3D=3D "0"} {set psizeoutfive "0"} else {set psizeoutf=
ive
> [expr $bpsoutfive / $ppsoutfive]}
>
> =A0set psizeoutfive [expr $psizeoutfive / 8]
>
> }
>
> =A0if {[regexp -nocase {([0-9]+) packets input, ([0-9]+) bytes} $line
> ignore ppsintotal bpsintotal]} {
>
> =A0if {$ppsintotal > "9999999"} {set psizeintotal "Too Large to Find"}
> elseif {$ppsintotal =3D=3D "0"} {set psizeintotal "0"} else {set
> psizeintotal [expr $bpsintotal / $ppsintotal]}
>
> }
>
> =A0if {[regexp -nocase {([0-9]+) packets output, ([0-9]+) bytes} $line
> ignore ppsouttotal bpsouttotal]} {
>
> =A0if {$ppsouttotal > "9999999"} {set psizeouttotal "Too Large to Find"}
> elseif {$ppsouttotal =3D=3D "0"} {set psizeouttotal "0"} else {set
> psizeouttotal [expr $bpsouttotal / $ppsouttotal]}
>
> }
>
> =A0}
>
> # Output Data
>
> =A0puts "\n\nPacket Size Information for $ifnamefull"
>
> =A0puts "---------------------------------------------------------"
>
> =A0puts " =A05 minute input bits/sec =3D $bpsinfive =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 "
>
> =A0puts " =A05 minute input packets/sec =A0=3D $ppsinfive =A0 =A0 =A0 =A0=
 =A0 =A0 =A0 "
>
> =A0puts " =A05 minute average packet size =3D $psizeinfive Bytes =A0 =A0 =
=A0"
>
> =A0puts "---------------------------------------------------------"
>
> =A0puts " =A05 minute output bits/sec =3D $bpsoutfive =A0 =A0 =A0 =A0 =A0=
 =A0 =A0 =A0 "
>
> =A0puts " =A05 minute output packets/sec =A0=3D $ppsoutfive =A0 =A0 =A0 =
=A0 =A0 =A0 "
>
> =A0puts " =A05 minute average packet size =3D $psizeoutfive Bytes =A0 =A0=
 "
>
> =A0puts "---------------------------------------------------------"
>
> =A0puts " =A0Total input bytes =3D $bpsintotal =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0"
>
> =A0puts " =A0Total input packets =A0=3D $ppsintotal =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 "
>
> =A0puts " =A0Total average packet size =3D $psizeintotal Bytes =A0 =A0 =
=A0 =A0"
>
> =A0puts "---------------------------------------------------------"
>
> =A0puts " =A0Total output bytes =3D $bpsouttotal =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0"
>
> =A0puts " =A0Total output packets =A0=3D $ppsouttotal =A0 =A0 =A0 =A0 =A0=
 =A0 =A0 =A0 =A0 "
>
> =A0puts " =A0Total average packet size =3D $psizeouttotal Bytes =A0 =A0 =
=A0 "
>
> =A0puts "---------------------------------------------------------"
>
>
>
>
>
>
>
> Thomas Magill
> Network Engineer
>
> Office: (858) 909-3777
>
> Cell: (858) 869-9685
> mailto:tmagill@providecommerce.com <mailto:tmagill@providecommerce.com>
>
>
> provide-commerce
> 4840 Eastgate Mall
>
> San Diego, CA =A092121
>
>
>
> ProFlowers <http://www.proflowers.com/> =A0| redENVELOPE
> <http://www.redenvelope.com/> =A0| Cherry Moon Farms
> <http://www.cherrymoonfarms.com/> =A0| Shari's Berries
> <http://www.berries.com/>
>
>
>
>


home help back first fref pref prev next nref lref last post