blob: 70edf61f05cc120e2ee6d63110abcb44c866a2bb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
|
#!./tclsh
# $Id: monitor.tcl 1074 2008-06-04 00:08:43Z hubert@u.washington.edu $
# ========================================================================
# Copyright 2006 University of Washington
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# ========================================================================
# monitor.tcl
# read config
source ./alpine.tcl
proc nicetime {timeoutput} {
if {[regexp {^[0-9]+ } $timeoutput msec]} {
return "[format {%d.%06d} [expr {$msec / 1000000}] [expr {$msec % 1000000}]] seconds"
} else {
return $timeoutput
}
}
# take process snapshot
#set cmd "/bin/ps -lC alpined --sort=cutime"
set cmd "/bin/ps -auxww --sort=cutime"
if {[catch "exec $cmd" result]} {
set prohdr "ps error: $result"
set proclist {}
} else {
set r [split $result "\n"]
set prochdr [lindex $r 0]
set proclist [lrange $r 1 end]
}
cgi_eval {
cgi_html {
cgi_head {
cgi_title "Web Alpine Monitor"
cgi_puts "<style type='text/css'>"
cgi_puts ".monsec { text-decoration: underline ; margin: 4}"
cgi_puts "</style>"
}
cgi_body {
cgi_h2 "WebPine Status // [info hostname] // [clock format [clock seconds]]"
##
## system performance monitor
##n
cgi_preformatted {
# simple server load
set cmd "/usr/ucb/uptime"
if {[catch "exec $cmd" result]} {
cgi_puts "uptime unavailable: $result"
} else {
cgi_puts [cgi_span class=monsec "Server uptime"]
foreach l [split $result "\n"] {
cgi_puts " $l"
}
}
cgi_br
# list alpined adapters
foreach l $proclist {
if {[regexp $_wp(servlet) $l] || [regexp $_wp(pc_servlet) $l]} {
lappend adapters $l
}
}
cgi_puts [cgi_span class=monsec "WebPine Adapters ([llength $adapters])"]
cgi_puts " $prochdr"
foreach l $adapters {
cgi_puts " $l"
}
cgi_br
# tmp disc usage
cgi_puts [cgi_span class=monsec "Temp Directory Usage ($_wp(tmpdir))"]
set cmd "/bin/df $_wp(tmpdir)"
if {[catch "exec $cmd" result]} {
cgi_puts "usage unavailable: $result"
} else {
foreach l [split $result "\n"] {
cgi_puts " $l"
}
}
cgi_br
# detach staging usage
cgi_puts [cgi_span class=monsec "Detach Staging Usage ($_wp(tmpdir))"]
set cmd "/bin/df $_wp(detachpath)"
if {[catch "exec $cmd" result]} {
cgi_puts "usage unavailable: $result"
} else {
foreach l [split $result "\n"] {
cgi_puts " $l"
}
}
if {[info exists report_env]} {
cgi_br
cgi_puts [cgi_span class=monsec "Environment:"]
set cgiv {
SERVER_SOFTWARE
SERVER_NAME
GATEWAY_INTERFACE
SERVER_PROTOCOL
SERVER_PORT
REQUEST_METHOD
PATH_INFO
PATH_TRANSLATED
SCRIPT_NAME
QUERY_STRING
REMOTE_HOST
REMOTE_ADDR
AUTH_TYPE
REMOTE_USER
REMOTE_IDENT
CONTENT_TYPE
CONTENT_LENGTH
HTTP_ACCEPT
HTTP_USER_AGENT
}
foreach v $cgiv {
if {[info exists env($v)]} {
cgi_puts " $v: $env($v)"
}
}
}
##
## session specific feedback
##
if {[info exists _wp(monitors)]
&& [info exists env(REMOTE_USER)]
&& [lsearch -exact $_wp(monitors) $env(REMOTE_USER)] >= 0} {
cgi_br
cgi_puts [cgi_span class=monsec "Kerberos ticket cache info"]
foreach l [glob "[file join $_wp(tmpdir) krb]*"] {
set file [file join $_wp(tmpdir) $l]
cgi_put " [exec /bin/ls -l $file]"
if {[catch {expr {[clock seconds] - [file mtime $file]}} d]} {
} else {
cgi_puts " ([expr {$d / 3600}] hours, [expr {($d % 3600) / 60}] minutes old)"
}
}
cgi_br
cgi_puts [cgi_span class=monsec "uid_mapper Process"]
# Condition of uid_mapper
cgi_puts " $prochdr"
foreach l $proclist {
if {[regexp uidmapper $l]} {
lappend umlist $l
}
}
if {[info exists umlist]} {
foreach l $umlist {
cgi_puts " $l"
}
} else {
cgi_puts " HELP!!! NO UIDMAPPER RUNNING!!!"
}
cgi_br
if {[info exists _wp(hosts)] && [llength $_wp(hosts)]} {
cgi_puts [cgi_span class=monsec "Session Performance (netid: $env(REMOTE_USER))"]
set sdata [lindex $_wp(hosts) 0]
set User $env(REMOTE_USER)
set env(IMAP_SERVER) "[subst [lindex $sdata 1]]/user=$env(REMOTE_USER)"
if {[llength $sdata] > 2 && [string length [lindex $sdata 2]]} {
set defconf [subst [lindex $sdata 2]]
set confloc "\{$env(IMAP_SERVER)\}$_wp(config)"
cgi_puts " User Config: $confloc"
# launch session
cgi_put " alpined Launch: "
set ct [time {
if {[catch {exec [file join $_wp(bin) launch.tcl]} _wp(sessid)]} {
set err "FAILURE: $_wp(sessid)"
} else {
WPValidId $_wp(sessid)
}
}]
if {[info exists err]} {
cgi_puts $err
} else {
cgi_puts [nicetime $ct]
cgi_put " Open Inbox: "
set ct [time {
if {[catch {WPCmd PESession open $env(REMOTE_USER) "" $confloc $defconf} answer]} {
set err "FAILURE: "
if {[info exists answer]} {
if {[string length $answer] == 0} {
append err "Unknown Username or Incorrect Password"
} else {
append err $answer
}
} else {
append err "Unknown reason"
}
}
}]
if {[info exists err]} {
cgi_puts $err
} else {
cgi_puts [nicetime $ct]
cgi_put " Fetch First Message: "
set ct [time {
if {[catch {
set msg [WPCmd PEMailbox first]
set uid [WPCmd PEMailbox uid $msg]
set txt [WPCmd PEMessage $uid text]
} txt]} {
set err $txt
}
}]
if {[info exists err]} {
cgi_puts "FAILURE: $err"
} else {
cgi_puts [nicetime $ct]
cgi_put " Fetch Last Message: "
set ct [time {
if {[catch {
set msg [WPCmd PEMailbox last]
set uid [WPCmd PEMailbox uid $msg]
set txt [WPCmd PEMessage $uid text]
} txt]} {
set err $txt
}
}]
if {[info exists err]} {
cgi_puts "FAILURE: $err"
} else {
cgi_puts [nicetime $ct]
}
}
}
set ct [time {
catch {WPCmd PESession close}
catch {WPCmd exit}
}]
cgi_puts " Close Session: [nicetime $ct]"
}
} else {
cgi_puts "Invalid host configuration"
}
}
}
}
}
}
}
|