… | |
… | |
133 | } |
133 | } |
134 | } |
134 | } |
135 | } |
135 | } |
136 | |
136 | |
137 | sub format_time { |
137 | sub format_time { |
138 | sprintf "%02dd %02d:%02d:%02d", |
138 | sprintf "%02dd %02d:%02d:%02d", |
139 | int ($_[0] / (60 * 60 * 24)), |
139 | int ($_[0] / (60 * 60 * 24)), |
140 | int ($_[0] / (60 * 60)) % 24, |
140 | int ($_[0] / (60 * 60)) % 24, |
141 | int ($_[0] / 60) % 60, |
141 | int ($_[0] / 60) % 60, |
142 | int ($_[0]) % 60; |
142 | int ($_[0]) % 60; |
143 | } |
143 | } |
… | |
… | |
197 | </body> |
197 | </body> |
198 | </html> |
198 | </html> |
199 | EOF |
199 | EOF |
200 | } |
200 | } |
201 | |
201 | |
202 | $::internal{status} = sub { |
202 | sub statuspage { |
203 | my $self = shift; |
203 | my ($self, $verbose) = @_; |
204 | |
204 | |
205 | my $uptime = format_time ($::NOW - $::starttime); |
205 | my $uptime = format_time ($::NOW - $::starttime); |
206 | |
206 | |
207 | my $content = <<EOF; |
207 | my $content = <<EOF; |
208 | <html> |
208 | <html> |
209 | <head><title>Server Status Page</title></head> |
209 | <head><title>Server Status Page</title></head> |
210 | <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#000080" alink="#ff0000"> |
210 | <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#000080" alink="#ff0000"> |
211 | <h1>Server Status Page</h1> |
211 | <h1>Server Status Page</h1> |
212 | <h2>Myhttpd</h2> |
212 | <h2>Myhttpd</h2> |
213 | version <b>$VERSION</b>; current/max connection count: <b>$::conns</b>:<b>$::maxconns</b>; uptime: <b>$uptime</b>;<br /> |
213 | version <b>$VERSION</b>; current:max connection count: <b>$::conns</b>:<b>$::maxconns</b>; uptime: <b>$uptime</b>;<br /> |
214 | client-id <b>$self->{remote_id}</b>, client country <b>$self->{country}</b>;<br /> |
214 | client-id <b>$self->{remote_id}</b>, client country <b>$self->{country}</b>;<br /> |
215 | <h2>Queue Statistics</h2> |
215 | <h2>Queue Statistics</h2> |
216 | <ul> |
216 | <ul> |
217 | EOF |
217 | EOF |
218 | |
218 | |
219 | for ( |
219 | for ( |
220 | ["small files queue", $queue_small], |
|
|
221 | ["large files queue", $queue_large], |
220 | ["download queue", $queue_file], |
222 | ["misc files queue" , $queue_index], |
221 | ["other queue", $queue_index], |
223 | ) { |
222 | ) { |
224 | my ($name, $queue) = @$_; |
223 | my ($name, $queue) = @$_; |
|
|
224 | my @waiters = $queue->waiters; |
225 | if ($queue->waiters) { |
225 | if (@waiters) { |
|
|
226 | $content .= "<li>$name<br />".(scalar @waiters)." client(s)"; |
|
|
227 | |
|
|
228 | $content .= "<p>Waiting time until download starts, estimated:<ul>"; |
|
|
229 | for ( |
|
|
230 | ["by most recently started transfer", $queue->{lastspb}], |
|
|
231 | ["by next client in queue", $waiters[0]{spb}], |
226 | if (0) { |
232 | ) { |
|
|
233 | my ($by, $spb) = @$_; |
|
|
234 | $content .= "<li>$by<br />"; |
|
|
235 | if ($spb) { |
|
|
236 | $content .= sprintf "100 KB file: <b>%s</b>; 1 MB file: <b>%s</b>; 100MB file: <b>%s</b>;", |
|
|
237 | format_time($spb* 100_000), |
|
|
238 | format_time($spb* 1_000_000), |
|
|
239 | format_time($spb*100_000_000); |
|
|
240 | } else { |
|
|
241 | $content .= "(unavailable)"; |
|
|
242 | } |
|
|
243 | $content .= "</li>"; |
|
|
244 | } |
|
|
245 | $content .= "</ul></p>"; |
|
|
246 | |
|
|
247 | if ($verbose) { |
227 | $content .= "<li>$name<table border='1' width='100%'><tr><th>Remote ID</th><th>CN</th><th>Waiting</th><th>URI</th></tr>"; |
248 | $content .= "<table border='1' width='100%'><tr><th>Remote ID</th><th>CN</th><th>Size</th><th>Waiting</th><th>SPB</th><th>URI</th></tr>"; |
228 | for ($queue->waiters) { |
249 | for (@waiters) { |
229 | if (defined $queue) { |
|
|
230 | my $conn = $queue->{conn}; |
250 | my $conn = $_->{coro}{conn}; |
231 | my $time = format_time ($::NOW - $conn->{time}); |
251 | my $time = format_time ($::NOW - $_->{time}); |
232 | $content .= "<tr>". |
252 | $content .= "<tr>". |
233 | "<td>$conn->{remote_id}</td>". |
253 | "<td>$conn->{remote_id}</td>". |
234 | "<td>$conn->{country}</td>". |
254 | "<td>$conn->{country}</td>". |
|
|
255 | "<td>$_->{size}</td>". |
235 | "<td>$time</td>". |
256 | "<td>$time</td>". |
|
|
257 | "<td>$_->{spb}</td>". |
236 | "<td>".escape_html($conn->{name})."</td>". |
258 | "<td>".escape_html($conn->{name})."</td>". |
237 | "</tr>"; |
259 | "</tr>"; |
238 | } else { |
|
|
239 | $content .= "<tr><td colspan='4'>premature ejaculation</td></tr>"; |
|
|
240 | } |
|
|
241 | } |
260 | } |
242 | $content .= "</table></li>"; |
261 | $content .= "</table></li>"; |
243 | } else { |
|
|
244 | my @waiters = grep defined $_, $queue->waiters; |
|
|
245 | $content .= "<li>$name<br />(".(scalar @waiters). |
|
|
246 | " client(s), waiting for " |
|
|
247 | .(format_time $::NOW - ($waiters[0]{conn}{time} || $::NOW)). |
|
|
248 | ")</li>"; |
|
|
249 | } |
262 | } |
|
|
263 | $content .= "</li>"; |
250 | } else { |
264 | } else { |
251 | $content .= "<li>$name<br />(empty)</li>"; |
265 | $content .= "<li>$name<br />(empty)</li>"; |
252 | } |
266 | } |
253 | } |
267 | } |
254 | |
268 | |
… | |
… | |
264 | "Content-Length" => length $content, |
278 | "Content-Length" => length $content, |
265 | }, |
279 | }, |
266 | $content); |
280 | $content); |
267 | }; |
281 | }; |
268 | |
282 | |
|
|
283 | $::internal{status} = sub { statuspage($_[0], 0) }; |
|
|
284 | $::internal{queue} = sub { statuspage($_[0], 1) }; |
|
|
285 | |
269 | 1; |
286 | 1; |