482 |
|
|
483 |
proc ::tcldrop::traffic {{type {*}} {direction {}} {bytes {0}}} { |
proc ::tcldrop::traffic {{type {*}} {direction {}} {bytes {0}}} { |
484 |
variable Traffic |
variable Traffic |
485 |
if {$type != {*}} { |
if {$type != {}} { |
486 |
if {[info exists Traffic($type)]} { |
if {[info exists Traffic($type)]} { |
487 |
# Set the info array to the current counts. |
# Set the info array to the current counts. |
488 |
array set info $Traffic($type) |
array set info $Traffic($type) |
492 |
} |
} |
493 |
# Increase the counters: |
# Increase the counters: |
494 |
if {($bytes) && ($direction == {in} || $direction == {out})} { |
if {($bytes) && ($direction == {in} || $direction == {out})} { |
495 |
array set info [list total-$direction [incr info(total-$direction) $bytes] daily-$direction [incr info(daily-$direction) $bytes]] |
incr info(total-$direction) $bytes |
496 |
|
incr info(daily-$direction) $bytes |
497 |
} |
} |
498 |
# See if 24 hours have elapsed, and if it has then clear the daily counts. |
# See if 24 hours have elapsed, and if it has then clear the daily counts. |
499 |
if {[expr { [unixtime] - $info(restart) > 86400 }]} { |
if {[expr { [unixtime] - $info(restart) > 86400 }]} { |
510 |
} |
} |
511 |
} else { |
} else { |
512 |
# Show them all the traffic stats. |
# Show them all the traffic stats. |
513 |
set out [list] |
array set total [list total-out 0 total-in 0 daily-out 0 daily-in 0] |
514 |
foreach t [array names Traffic] { |
foreach t [array names Traffic] { |
515 |
array set info $Traffic($t) |
array set info $Traffic($t) |
516 |
lappend out [list $t $info(daily-in) $info(total-in) $info(daily-out) $info(total-out)] |
lappend out [list $t $info(daily-in) $info(total-in) $info(daily-out) $info(total-out)] |
517 |
|
incr total(total-out) $info(total-out) |
518 |
|
incr total(total-in) $info(total-in) |
519 |
|
incr total(daily-out) $info(daily-out) |
520 |
|
incr total(daily-in) $info(daily-in) |
521 |
} |
} |
522 |
|
lappend out [list Total $total(daily-in) $total(total-in) $total(daily-out) $total(total-out)] |
523 |
return $out |
return $out |
524 |
} |
} |
525 |
} |
} |