cancel
Showing results for 
Search instead for 
Did you mean: 

Problem this snippet solves:

Here's a way to monitor a specified interface's bits-in and bits-out stats using a custom tmsh script.

Code :

cli script intStats {
proc getFeedback { question } {
    puts -nonewline $question
    flush stdout
    return [gets stdin]
}
proc script::run {} {
    tmsh::clear_screen
    if { $tmsh::argc == 1 } {
        set int [getFeedback "Please enter the interface number (ie, 1.1): "]
    } else {
        set int [lindex $tmsh::argv 1]
    }

    set l1 []
    set l2 []
    set interval [getFeedback "Please enter refresh rate for the stats (in seconds): "]
    set delay [expr $interval * 1000]

    lappend l1 [lindex [lindex [split [tmsh::show net interface $int raw field-fmt] "\n"] 1] 1]
    lappend l1 [lindex [lindex [split [tmsh::show net interface $int raw field-fmt] "\n"] 2] 1]

    while { true } {
        after $delay
        lappend l2 [lindex [lindex [split [tmsh::show net interface $int raw field-fmt] "\n"] 1] 1]
        lappend l2 [lindex [lindex [split [tmsh::show net interface $int raw field-fmt] "\n"] 2] 1]
        tmsh::clear_screen

        set statsIn [expr ([lindex $l2 0] - [lindex $l1 0]) / $interval]
        set statsOut [expr ([lindex $l2 1] - [lindex $l1 1]) / $interval]

        puts "Interface\t\tInbound (bps)\t\tOutbound (bps)"
        puts "$int\t\t\t$statsIn\t\t\t$statsOut"

        set l1 $l2
        unset l2
    }
}
}
Version history
Last update:
‎10-Mar-2015 12:12
Updated by:
Contributors