2 # $Id: monitor.tcl 1074 2008-06-04 00:08:43Z hubert@u.washington.edu $
3 # ========================================================================
4 # Copyright 2006 University of Washington
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # ========================================================================
19 proc nicetime
{timeoutput
} {
20 if {[regexp {^
[0-9]+ } $timeoutput msec
]} {
21 return "[format {%d.%06d} [expr {$msec / 1000000}] [expr {$msec % 1000000}]] seconds"
27 # take process snapshot
28 #set cmd "/bin/ps -lC alpined --sort=cutime"
29 set cmd
"/bin/ps -auxww --sort=cutime"
30 if {[catch "exec $cmd" result
]} {
31 set prohdr
"ps error: $result"
34 set r
[split $result "\n"]
35 set prochdr
[lindex $r 0]
36 set proclist
[lrange $r 1 end
]
42 cgi_title
"Web Alpine Monitor"
43 cgi_puts
"<style type='text/css'>"
44 cgi_puts
".monsec { text-decoration: underline ; margin: 4}"
49 cgi_h2
"WebPine Status // [info hostname] // [clock format [clock seconds]]"
52 ## system performance monitor
56 set cmd
"/usr/ucb/uptime"
57 if {[catch "exec $cmd" result
]} {
58 cgi_puts
"uptime unavailable: $result"
60 cgi_puts
[cgi_span class
=monsec
"Server uptime"]
61 foreach l
[split $result "\n"] {
68 # list alpined adapters
70 if {[regexp $_wp(servlet
) $l] ||
[regexp $_wp(pc_servlet
) $l]} {
75 cgi_puts
[cgi_span class
=monsec
"WebPine Adapters ([llength $adapters])"]
84 cgi_puts
[cgi_span class
=monsec
"Temp Directory Usage ($_wp(tmpdir))"]
85 set cmd
"/bin/df $_wp(tmpdir)"
86 if {[catch "exec $cmd" result
]} {
87 cgi_puts
"usage unavailable: $result"
89 foreach l
[split $result "\n"] {
96 # detach staging usage
97 cgi_puts
[cgi_span class
=monsec
"Detach Staging Usage ($_wp(tmpdir))"]
98 set cmd
"/bin/df $_wp(detachpath)"
99 if {[catch "exec $cmd" result
]} {
100 cgi_puts
"usage unavailable: $result"
102 foreach l
[split $result "\n"] {
107 if {[info exists report_env
]} {
110 cgi_puts
[cgi_span class
=monsec
"Environment:"]
134 if {[info exists env
($v)]} {
135 cgi_puts
" $v: $env($v)"
142 ## session specific feedback
144 if {[info exists _wp
(monitors
)]
145 && [info exists env
(REMOTE_USER
)]
146 && [lsearch -exact $_wp(monitors
) $env(REMOTE_USER
)] >= 0} {
150 cgi_puts
[cgi_span class
=monsec
"Kerberos ticket cache info"]
151 foreach l
[glob "[file join $_wp(tmpdir) krb]*"] {
152 set file [file join $_wp(tmpdir
) $l]
153 cgi_put
" [exec /bin/ls -l $file]"
154 if {[catch {expr {[clock seconds
] - [file mtime
$file]}} d
]} {
156 cgi_puts
" ([expr {$d / 3600}] hours, [expr {($d % 3600) / 60}] minutes old)"
162 cgi_puts
[cgi_span class
=monsec
"uid_mapper Process"]
163 # Condition of uid_mapper
165 foreach l
$proclist {
166 if {[regexp uidmapper
$l]} {
171 if {[info exists umlist
]} {
176 cgi_puts
" HELP!!! NO UIDMAPPER RUNNING!!!"
181 if {[info exists _wp
(hosts
)] && [llength $_wp(hosts
)]} {
182 cgi_puts
[cgi_span class
=monsec
"Session Performance (netid: $env(REMOTE_USER))"]
184 set sdata
[lindex $_wp(hosts
) 0]
185 set User
$env(REMOTE_USER
)
186 set env
(IMAP_SERVER
) "[subst [lindex $sdata 1]]/user=$env(REMOTE_USER)"
188 if {[llength $sdata] > 2 && [string length
[lindex $sdata 2]]} {
189 set defconf
[subst [lindex $sdata 2]]
190 set confloc
"\{$env(IMAP_SERVER)\}$_wp(config)"
191 cgi_puts
" User Config: $confloc"
194 cgi_put
" alpined Launch: "
196 if {[catch {exec [file join $_wp(bin
) launch.tcl
]} _wp
(sessid
)]} {
197 set err
"FAILURE: $_wp(sessid)"
199 WPValidId
$_wp(sessid
)
203 if {[info exists err
]} {
206 cgi_puts
[nicetime
$ct]
208 cgi_put
" Open Inbox: "
210 if {[catch {WPCmd PESession
open $env(REMOTE_USER
) "" $confloc $defconf} answer
]} {
212 if {[info exists answer
]} {
213 if {[string length
$answer] == 0} {
214 append err
"Unknown Username or Incorrect Password"
219 append err
"Unknown reason"
224 if {[info exists err
]} {
227 cgi_puts
[nicetime
$ct]
229 cgi_put
" Fetch First Message: "
233 set msg
[WPCmd PEMailbox first
]
234 set uid
[WPCmd PEMailbox uid
$msg]
235 set txt
[WPCmd PEMessage
$uid text]
241 if {[info exists err
]} {
242 cgi_puts
"FAILURE: $err"
244 cgi_puts
[nicetime
$ct]
246 cgi_put
" Fetch Last Message: "
250 set msg
[WPCmd PEMailbox last
]
251 set uid
[WPCmd PEMailbox uid
$msg]
252 set txt
[WPCmd PEMessage
$uid text]
258 if {[info exists err
]} {
259 cgi_puts
"FAILURE: $err"
261 cgi_puts
[nicetime
$ct]
267 catch {WPCmd PESession
close}
271 cgi_puts
" Close Session: [nicetime $ct]"
274 cgi_puts
"Invalid host configuration"