Posted to tcl by schelte at Sat Mar 23 15:22:55 GMT 2013view raw
- #!/usr/bin/tclsh
- package require Tk
- wm title . "Load AVG"
- #wm resizable . 0 0
- entry .e1 -width 6 -state readonly -justify center -textvariable old(.e1)
- entry .e2 -width 6 -state readonly -justify center -textvariable old(.e2)
- entry .e3 -width 6 -state readonly -justify center -textvariable old(.e3)
- entry .e4 -width 6 -state readonly -justify center -textvariable old(.e4)
- entry .e5 -width 6 -state readonly -justify center -textvariable old(.e5)
- button .b1 -text {Exit} -state normal -command {exit}
- grid .e1 -row 0 -column 0
- grid .e2 -row 1 -column 0
- grid .e3 -row 2 -column 0
- grid .e4 -row 3 -column 0
- grid .e5 -row 4 -column 0
- grid .b1 -row 5 -column 0
- proc StatusInsert {name now} {
- global old
- if {$now > $old($name)} {
- puts "$now UP"
- $name configure -foreground red
- } elseif {$now == $old($name)} {
- puts "$now EQUAL"
- $name configure -foreground blue
- } else {
- puts "$now DOWN"
- $name configure -foreground darkgreen
- }
- set old($name) $now
- }
- proc avg_load {} {
- set lavgFile {/proc/loadavg}
- set lavgFD [open $lavgFile r]
- while {[gets $lavgFD line] >= 0} {
- set result $line
- }
- foreach w {.e1 .e2 .e3} value [lrange [split $result { }] 0 2] {
- StatusInsert $w $value
- }
- foreach w {.e4 .e5} value [split [lindex [split $result { }] 3] {/}] {
- StatusInsert $w $value
- }
- close $lavgFD
- }
- proc testcase {} {
- avg_load
- after 1000 testcase
- }
- testcase