Specifications
APPENDIX H: TCL PROGRAMMING GUIDE 157
#clear any previous data in the read buffer
ampclear $port
#write to the console
ampwrite "vmstat -n\n" $port
#ignore the first 8 lines to read the cpu usage params.
for {set i 0 } {$i < 9} {incr i +1} {
set cpu [ampread 1 "\n" $port]
}
#unlock the console
ampunlock $port
#set the user's cpu usage
scan $cpu "%d %d %d" us sy id
#Trigger event if user process utilization has gone beyond threshold
if { $us > $thr } {
amptriggerevent event.alarm.cpu "User Process CPU utilization goes beyond threshold
$thr on port$port"
}
}
#listen to command inputs from user - QUIT/THR/INTR
proc ListenCmds { } {
global thr incr
set cmd [amplisten]
if { [string compare $cmd "QUIT"] == 0 } {
puts "Quitting"
ampresponse
return 1
} elseif [string match THR* $cmd] {
scan $cmd "%s %d" c thr
puts "Threshold is $thr"
ampresponse
} elseif [string match INTR* $cmd] {
scan $cmd "%s %d" c intr
puts "Interval now is $intr"
ampresponse
}
ampresponse
}
set ports 1
set noOfPorts 2