this script shows u how u can read the incomming and out going speed on ur linux box maybe usefull to show in channel when u ask stats like this u can make an average speed or something .. or mrtg .. change ppp0 to eth0 or eth1 .. what ever you prefer ..
Constant readout
Code: Select all
#!/usr/bin/tclsh
proc speedcheck {} {
global gouttraf ginctraf
set cache [open "/proc/net/dev" "r"]
set rfile [read $cache]
close $cache
foreach line [split $rfile "\n"] {
if {[string match -nocase "ppp0" [lindex [split [lindex $line 0] \x3A] 0]]} {
set inctraf [lindex [split [lindex $line 0] \x3A] 1]
set outtraf [lindex $line 8]
}
}
if {![info exists ginctraf]} {
set ginctraf "$inctraf"
}
if {![info exists gouttraf]} {
set gouttraf "$outtraf"
}
if {[info exists gouttraf] && [info exists ginctraf]} {
set sinctraf [expr [expr $inctraf-$ginctraf]/1000]
set souttraf [expr [expr $outtraf-$gouttraf]/1000]
set gouttraf "$outtraf"
set ginctraf "$inctraf"
puts "Incoming $sinctraf kb/s"
puts "Outgoing $souttraf kb/s"
}
after 1000
speedcheck
}
speedcheck
Code: Select all
#!/usr/bin/tclsh
proc speedcheck {} {
foreach line [split [exec "/bin/cat" "/proc/net/dev"] "\n"] {
if {[string match -nocase "ppp0" [lindex [split [lindex $line 0] \x3A] 0]]} {
set ginctraf [lindex [split [lindex $line 0] \x3A] 1]
set gouttraf [lindex $line 8]
}
}
after 500
foreach line [split [exec "/bin/cat" "/proc/net/dev"] "\n"] {
if {[string match -nocase "ppp0" [lindex [split [lindex $line 0] \x3A] 0]]} {
set inctraf [lindex [split [lindex $line 0] \x3A] 1]
set outtraf [lindex $line 8]
}
}
set sinctraf [expr [expr $inctraf-$ginctraf]/500.0]
set souttraf [expr [expr $outtraf-$gouttraf]/500.0]
puts "Incoming: $sinctraf kb/s"
puts "Outgoing: $souttraf kb/s"
}
speedcheck