1 | <?php |
---|
2 | /* |
---|
3 | * |
---|
4 | * This file is part of Jobmonarch |
---|
5 | * |
---|
6 | * Copyright (C) 2006 Ramon Bastiaans |
---|
7 | * |
---|
8 | * Jobmonarch is free software; you can redistribute it and/or modify |
---|
9 | * it under the terms of the GNU General Public License as published by |
---|
10 | * the Free Software Foundation; either version 2 of the License, or |
---|
11 | * (at your option) any later version. |
---|
12 | * |
---|
13 | * Jobmonarch is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this program; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
21 | * |
---|
22 | * SVN $Id: libtoga.php 331 2007-04-22 18:32:32Z bastiaans $ |
---|
23 | * |
---|
24 | */ |
---|
25 | |
---|
26 | |
---|
27 | class HTTPVariables { |
---|
28 | |
---|
29 | var $clustername, $metricname; |
---|
30 | var $restvars, $httpvars; |
---|
31 | |
---|
32 | function HTTPVariables( $httpvars, $getvars ) { |
---|
33 | |
---|
34 | $this->restvars = array(); |
---|
35 | |
---|
36 | $this->clustername = $httpvars["c"] ? $httpvars["c"] : $getvars["c"]; |
---|
37 | $this->metricname = $httpvars["m"] ? $httpvars["m"] : $getvars["m"]; |
---|
38 | |
---|
39 | foreach( $httpvars as $httpvar => $httpval ) { |
---|
40 | |
---|
41 | if( $httpval ) { |
---|
42 | $this->restvars[$httpvar] = $httpval; |
---|
43 | } |
---|
44 | } |
---|
45 | |
---|
46 | foreach( $getvars as $getvar => $getval ) { |
---|
47 | |
---|
48 | if( $getval ) { |
---|
49 | $this->restvars[$getvar] = $getval; |
---|
50 | } |
---|
51 | } |
---|
52 | } |
---|
53 | |
---|
54 | function getClusterName() { |
---|
55 | return $this->clustername; |
---|
56 | } |
---|
57 | |
---|
58 | function getMetricName() { |
---|
59 | return $this->metricname; |
---|
60 | } |
---|
61 | |
---|
62 | function getHttpVar( $var ) { |
---|
63 | if( isset( $this->restvars[$var] ) ) |
---|
64 | return $this->restvars[$var]; |
---|
65 | else |
---|
66 | return null; |
---|
67 | } |
---|
68 | } |
---|
69 | |
---|
70 | // Toga's conf |
---|
71 | // |
---|
72 | include_once "./conf.php"; |
---|
73 | include_once "./version.php"; |
---|
74 | |
---|
75 | global $GANGLIA_PATH; |
---|
76 | global $RRDTOOL; |
---|
77 | global $JOB_ARCHIVE_DIR; |
---|
78 | global $JOB_ARCHIVE_DBASE; |
---|
79 | global $SORTBY_HOSTNAME; |
---|
80 | global $SORT_ORDER; |
---|
81 | global $skan_str; |
---|
82 | global $x_first, $y_first; |
---|
83 | global $SORT_XLABEL, $SORT_YLABEL; |
---|
84 | |
---|
85 | $my_dir = getcwd(); |
---|
86 | |
---|
87 | // Load Ganglia's PHP |
---|
88 | chdir( $GANGLIA_PATH ); |
---|
89 | |
---|
90 | include_once "./conf.php"; |
---|
91 | include_once "./functions.php"; |
---|
92 | include_once "./ganglia.php"; |
---|
93 | include_once "./get_context.php"; |
---|
94 | unset( $start ); |
---|
95 | $context = 'cluster'; |
---|
96 | include_once "./get_ganglia.php"; |
---|
97 | |
---|
98 | // Back to our PHP |
---|
99 | chdir( $my_dir ); |
---|
100 | |
---|
101 | global $SMALL_CLUSTERIMAGE_MAXWIDTH, $SMALL_CLUSTERIMAGE_NODEWIDTH, $DATA_SOURCE, $HTTP_GET_VARS, $_GET; |
---|
102 | $httpvars = new HTTPVariables( $HTTP_GET_VARS, $_GET ); |
---|
103 | |
---|
104 | // Set cluster context so that Ganglia will |
---|
105 | // provide us with the correct metrics array |
---|
106 | // |
---|
107 | global $context, $clustername, $reports; |
---|
108 | |
---|
109 | //$clustername = $httpvars->getClusterName(); |
---|
110 | |
---|
111 | global $default_metric; |
---|
112 | |
---|
113 | // Ganglia's array of host metrics |
---|
114 | // |
---|
115 | global $metrics, $hosts_up; |
---|
116 | |
---|
117 | global $DATETIME_FORMAT; |
---|
118 | |
---|
119 | function makeDate( $time ) { |
---|
120 | global $DATETIME_FORMAT; |
---|
121 | return strftime( $DATETIME_FORMAT, $time ); |
---|
122 | } |
---|
123 | |
---|
124 | class TarchDbase { |
---|
125 | |
---|
126 | var $ip, $dbase, $conn; |
---|
127 | |
---|
128 | function TarchDbase( $ip = null, $dbase = null ) { |
---|
129 | |
---|
130 | global $JOB_ARCHIVE_DBASE; |
---|
131 | |
---|
132 | $db_fields = explode( '/', $JOB_ARCHIVE_DBASE ); |
---|
133 | |
---|
134 | $this->ip = $db_fields[0]; |
---|
135 | $this->dbase = $db_fields[1]; |
---|
136 | $this->conn = null; |
---|
137 | } |
---|
138 | |
---|
139 | function connect() { |
---|
140 | |
---|
141 | if( $this->ip == null ) |
---|
142 | $this->conn = pg_connect( "dbname=".$this->dbase ); |
---|
143 | else |
---|
144 | $this->conn = pg_connect( "host=".$this->ip." dbname=".$this->dbase ); |
---|
145 | } |
---|
146 | |
---|
147 | function searchDbase( $id = null, $queue = null, $user = null, $name = null, $start_from_time = null, $start_to_time = null, $end_from_time = null, $end_to_time = null ) { |
---|
148 | |
---|
149 | global $SEARCH_RESULT_LIMIT; |
---|
150 | |
---|
151 | if( $id ) { |
---|
152 | $select_query = "SELECT job_id FROM jobs WHERE job_id = '$id' AND job_status = 'F'"; |
---|
153 | $this->resultcount = 1; |
---|
154 | } else { |
---|
155 | $query_args = array(); |
---|
156 | |
---|
157 | if( $queue ) |
---|
158 | $query_args[] = "job_queue ='$queue'"; |
---|
159 | if( $user ) |
---|
160 | $query_args[] = "job_owner ='$user'"; |
---|
161 | if( $name ) |
---|
162 | $query_args[] = "job_name = '$name'"; |
---|
163 | if( $start_from_time ) |
---|
164 | $query_args[] = "job_start_timestamp >= $start_from_time"; |
---|
165 | if( $start_to_time ) |
---|
166 | $query_args[] = "job_start_timestamp <= $start_to_time"; |
---|
167 | if( $end_from_time ) |
---|
168 | $query_args[] = "job_stop_timestamp >= $end_from_time"; |
---|
169 | if( $end_to_time ) |
---|
170 | $query_args[] = "job_stop_timestamp <= $end_to_time"; |
---|
171 | |
---|
172 | $query = "FROM jobs WHERE job_status = 'F' AND "; |
---|
173 | $extra_query_args = ''; |
---|
174 | |
---|
175 | foreach( $query_args as $myquery ) { |
---|
176 | |
---|
177 | if( $extra_query_args == '' ) |
---|
178 | $extra_query_args = $myquery; |
---|
179 | else |
---|
180 | $extra_query_args .= " AND ".$myquery; |
---|
181 | } |
---|
182 | $query .= $extra_query_args; |
---|
183 | |
---|
184 | $count_result_idname = "COUNT(job_id)"; |
---|
185 | $select_result_idname = "job_id"; |
---|
186 | |
---|
187 | $count_query = "SELECT " . $count_result_idname . " " . $query; |
---|
188 | |
---|
189 | $count_result = $this->queryDbase( $count_query ); |
---|
190 | $this->resultcount = (int) $count_result[0][count]; |
---|
191 | |
---|
192 | $select_query = "SELECT " . $select_result_idname . " " . $query . " ORDER BY job_id LIMIT " . $SEARCH_RESULT_LIMIT; |
---|
193 | } |
---|
194 | |
---|
195 | $ids = $this->queryDbase( $select_query ); |
---|
196 | |
---|
197 | $ret = array(); |
---|
198 | |
---|
199 | foreach( $ids as $crow) |
---|
200 | $ret[] = $crow[job_id]; |
---|
201 | |
---|
202 | return $ret; |
---|
203 | } |
---|
204 | |
---|
205 | function getNodesForJob( $jobid ) { |
---|
206 | |
---|
207 | $result = $this->queryDbase( "SELECT node_id FROM job_nodes WHERE job_id = '$jobid'" ); |
---|
208 | |
---|
209 | $nodes = array(); |
---|
210 | |
---|
211 | foreach( $result as $result_row ) |
---|
212 | |
---|
213 | $nodes[] = $this->getNodeArray( $result_row[node_id] ); |
---|
214 | |
---|
215 | return $nodes; |
---|
216 | } |
---|
217 | |
---|
218 | function getJobsForNode( $nodeid ) { |
---|
219 | |
---|
220 | $result = $this->queryDbase( "SELECT job_id FROM job_nodes WHERE node_id = '$nodeid'" ); |
---|
221 | |
---|
222 | $jobs = array(); |
---|
223 | |
---|
224 | foreach( $result as $result_row ) |
---|
225 | |
---|
226 | $jobs[] = $this->getJobArray( $result_row[job_id] ); |
---|
227 | |
---|
228 | return $jobs; |
---|
229 | } |
---|
230 | |
---|
231 | function getJobArray( $id ) { |
---|
232 | $result = $this->queryDbase( "SELECT * FROM jobs WHERE job_id = '$id'" ); |
---|
233 | |
---|
234 | return ( $this->makeArray( $result[0] ) ); |
---|
235 | } |
---|
236 | |
---|
237 | function getNodeArray( $id ) { |
---|
238 | |
---|
239 | $result = $this->queryDbase( "SELECT * FROM nodes WHERE node_id = '$id'" ); |
---|
240 | |
---|
241 | return ( $this->makeArray( $result[0] ) ); |
---|
242 | } |
---|
243 | |
---|
244 | function makeArray( $result_row ) { |
---|
245 | |
---|
246 | $myar = array(); |
---|
247 | |
---|
248 | foreach( $result_row as $mykey => $myval ) { |
---|
249 | |
---|
250 | $map_key = explode( '_', $mykey ); |
---|
251 | |
---|
252 | $rmap_key = array_reverse( $map_key ); |
---|
253 | array_pop( $rmap_key ); |
---|
254 | $map_key = array_reverse( $rmap_key ); |
---|
255 | |
---|
256 | $newkey = implode( '_', $map_key ); |
---|
257 | |
---|
258 | $myar[$newkey] = $result_row[$mykey]; |
---|
259 | } |
---|
260 | |
---|
261 | return $myar; |
---|
262 | } |
---|
263 | |
---|
264 | function queryDbase( $query ) { |
---|
265 | |
---|
266 | $result_rows = array(); |
---|
267 | |
---|
268 | if( !$this->conn ) |
---|
269 | $this->connect(); |
---|
270 | |
---|
271 | //printf( "query = [%s]\n", $query ); |
---|
272 | $result = pg_query( $this->conn, $query ); |
---|
273 | |
---|
274 | while ($row = pg_fetch_assoc($result)) |
---|
275 | $result_rows[] = $row; |
---|
276 | |
---|
277 | return $result_rows; |
---|
278 | } |
---|
279 | } |
---|
280 | |
---|
281 | class TarchRrdGraph { |
---|
282 | var $rrdbin, $rrdvalues, $clustername, $hostname, $tempdir, $tarchdir, $metrics; |
---|
283 | |
---|
284 | function TarchRrdGraph( $clustername, $hostname ) { |
---|
285 | |
---|
286 | global $RRDTOOL; |
---|
287 | global $JOB_ARCHIVE_DIR; |
---|
288 | |
---|
289 | $this->rrdbin = $RRDTOOL; |
---|
290 | $this->rrdvalues = array(); |
---|
291 | $this->tarchdir = $JOB_ARCHIVE_DIR; |
---|
292 | $this->clustername = $clustername; |
---|
293 | $this->hostname = $hostname; |
---|
294 | } |
---|
295 | |
---|
296 | function doCmd( $command ) { |
---|
297 | |
---|
298 | printf( "command = %s\n", $command ); |
---|
299 | $pipe = popen( $command . ' 2>&1', 'r' ); |
---|
300 | |
---|
301 | if (!$pipe) { |
---|
302 | print "pipe failed."; |
---|
303 | return ""; |
---|
304 | } |
---|
305 | |
---|
306 | $output = ''; |
---|
307 | while(!feof($pipe)) |
---|
308 | $output .= fread($pipe, 1024); |
---|
309 | |
---|
310 | pclose($pipe); |
---|
311 | |
---|
312 | $output = explode( "\n", $output ); |
---|
313 | //print_r( $output ); |
---|
314 | return $output; |
---|
315 | } |
---|
316 | |
---|
317 | function dirList( $dir ) { |
---|
318 | |
---|
319 | $dirlist = array(); |
---|
320 | |
---|
321 | if ($handle = opendir( $dir )) { |
---|
322 | while (false !== ($file = readdir($handle))) { |
---|
323 | if ($file != "." && $file != "..") { |
---|
324 | $dirlist[] = $file; |
---|
325 | } |
---|
326 | } |
---|
327 | closedir($handle); |
---|
328 | } |
---|
329 | |
---|
330 | return $dirlist; |
---|
331 | } |
---|
332 | |
---|
333 | function getTimePeriods( $start, $end ) { |
---|
334 | |
---|
335 | //printf("start = %s end = %s\n", $start, $end ); |
---|
336 | $times = array(); |
---|
337 | $dirlist = $this->dirList( $this->tarchdir . '/' . $this->clustername . '/' . $this->hostname ); |
---|
338 | |
---|
339 | //print_r( $dirlist ); |
---|
340 | |
---|
341 | $first = 0; |
---|
342 | $last = 9999999999999; |
---|
343 | |
---|
344 | foreach( $dirlist as $dir ) { |
---|
345 | |
---|
346 | if( $dir > $first and $dir <= $start ) |
---|
347 | $first = $dir; |
---|
348 | if( $dir < $last and $dir >= $end ) |
---|
349 | $last = $dir; |
---|
350 | } |
---|
351 | |
---|
352 | //printf( "first = %s last = %s\n", $first, $last ); |
---|
353 | |
---|
354 | foreach( $dirlist as $dir ) { |
---|
355 | |
---|
356 | //printf( "dir %s ", $dir ); |
---|
357 | |
---|
358 | if( $dir >= $first and $dir <= $last and !array_key_exists( $dir, $times ) ) { |
---|
359 | |
---|
360 | $times[] = $dir; |
---|
361 | //printf("newtime %s ", $dir ); |
---|
362 | |
---|
363 | } |
---|
364 | } |
---|
365 | |
---|
366 | //print_r( $times ); |
---|
367 | |
---|
368 | sort( $times ); |
---|
369 | |
---|
370 | //print_r( $times ); |
---|
371 | |
---|
372 | return $times; |
---|
373 | } |
---|
374 | |
---|
375 | function getRrdDirs( $start, $stop ) { |
---|
376 | |
---|
377 | //printf( "tarchdir = %s\n", $this->tarchdir ); |
---|
378 | $timess = $this->getTimePeriods( $start, $stop ); |
---|
379 | //print_r( $timess ); |
---|
380 | |
---|
381 | $rrd_files = array(); |
---|
382 | |
---|
383 | foreach( $timess as $time ) { |
---|
384 | |
---|
385 | $rrd_files[] = $this->tarchdir . '/' . $this->clustername . '/' . $this->hostname. '/'.$time; |
---|
386 | } |
---|
387 | |
---|
388 | return $rrd_files; |
---|
389 | } |
---|
390 | |
---|
391 | function getRrdFiles( $metric, $start, $stop ) { |
---|
392 | |
---|
393 | $times = $this->getTimePeriods( $start, $stop ); |
---|
394 | |
---|
395 | $rrd_files = array(); |
---|
396 | |
---|
397 | foreach( $times as $time ) { |
---|
398 | |
---|
399 | $rrd_files[] = $this->tarchdir . '/' . $this->clustername . '/' . $this->hostname . '/' .$time. '/' . $metric. '.rrd'; |
---|
400 | } |
---|
401 | |
---|
402 | return $rrd_files; |
---|
403 | } |
---|
404 | |
---|
405 | function graph( $descr ) { |
---|
406 | // monitor2:/data/toga/rrds/LISA Cluster/gb-r15n11.irc.sara.nl# rrdtool graph /var/www/ganglia/test1.png --start 1118683231 --end 1118750431 --width 300 --height 400 DEF:'1'='./1118647515/load_one.rrd':'sum':AVERAGE DEF:'2'='./1118690723/load_one.rrd':'sum':AVERAGE DEF:'3'='./1118733925/load_one.rrd':'sum':AVERAGE AREA:1#555555:"load_one" AREA:2#555555 AREA:3#555555 |
---|
407 | // 380x461 |
---|
408 | // monitor2:/data/toga/rrds/LISA Cluster/gb-r15n11.irc.sara.nl# |
---|
409 | //$command = $this->rrdbin . " graph - --start $start --end $end ". |
---|
410 | "--width $width --height $height $upper_limit $lower_limit ". |
---|
411 | "--title '$title' $vertical_label $extras $background ". $series; |
---|
412 | |
---|
413 | //$graph = $this->doCmd( $command ); |
---|
414 | |
---|
415 | //return $graph; |
---|
416 | return 0; |
---|
417 | } |
---|
418 | } |
---|
419 | |
---|
420 | class DataSource { |
---|
421 | |
---|
422 | var $data, $ip, $port; |
---|
423 | |
---|
424 | //function DataSource( $ip = '127.0.0.1', $port = 8649 ) { |
---|
425 | function DataSource() { |
---|
426 | |
---|
427 | global $DATA_SOURCE; |
---|
428 | |
---|
429 | $ds_fields = explode( ':', $DATA_SOURCE ); |
---|
430 | |
---|
431 | $ds_ip = $ds_fields[0]; |
---|
432 | $ds_port = $ds_fields[1]; |
---|
433 | |
---|
434 | $this->ip = $ds_ip; |
---|
435 | $this->port = $ds_port; |
---|
436 | |
---|
437 | } |
---|
438 | |
---|
439 | function getData() { |
---|
440 | |
---|
441 | $errstr; |
---|
442 | $errno = 0; |
---|
443 | $timeout = 3; |
---|
444 | |
---|
445 | $fp = fsockopen( $this->ip, $this->port, $errno, $errstr, $timeout ); |
---|
446 | |
---|
447 | if( !$fp ) { |
---|
448 | echo 'Unable to connect to '.$this->ip.':'.$this->port; // printf( 'Unable to connect to [%s:%.0f]', $this->ip, $this->port ); |
---|
449 | return; |
---|
450 | } |
---|
451 | |
---|
452 | stream_set_timeout( $fp, 30 ); |
---|
453 | |
---|
454 | while ( !feof( $fp ) ) { |
---|
455 | |
---|
456 | $data .= fread( $fp, 16384 ); |
---|
457 | } |
---|
458 | |
---|
459 | fclose( $fp ); |
---|
460 | |
---|
461 | return $data; |
---|
462 | } |
---|
463 | } |
---|
464 | |
---|
465 | class DataGatherer { |
---|
466 | |
---|
467 | var $xmlhandler, $data, $httpvars; |
---|
468 | |
---|
469 | function DataGatherer( $cluster ) { |
---|
470 | |
---|
471 | //global $DATA_SOURCE; |
---|
472 | |
---|
473 | //printf("dg cluster = %s\n", $cluster ); |
---|
474 | //$ds_fields = explode( ':', $DATA_SOURCE ); |
---|
475 | //$ds_ip = $ds_fields[0]; |
---|
476 | //$ds_port = $ds_fields[1]; |
---|
477 | |
---|
478 | //$this->source = new DataSource( $ds_ip, $ds_port ); |
---|
479 | |
---|
480 | $this->cluster = $cluster; |
---|
481 | $this->httpvars = $httpvars; |
---|
482 | } |
---|
483 | |
---|
484 | function parseXML( $data ) { |
---|
485 | |
---|
486 | //$src = &$this->source; |
---|
487 | //$this->data = $src->getData(); |
---|
488 | |
---|
489 | $this->parser = xml_parser_create(); |
---|
490 | $this->xmlhandler = new TorqueXMLHandler( $this->cluster ); |
---|
491 | |
---|
492 | xml_set_element_handler( $this->parser, array( &$this->xmlhandler, 'startElement' ), array( &$this->xmlhandler, 'stopElement' ) ); |
---|
493 | //if ( !xml_parse( $this->parser, $this->data ) ) |
---|
494 | if ( !xml_parse( $this->parser, $data ) ) |
---|
495 | $error = sprintf( 'XML error: %s at %d', xml_error_string( xml_get_error_code( $this->parser ) ), xml_get_current_line_number( $this->parser ) ); |
---|
496 | } |
---|
497 | |
---|
498 | function printInfo() { |
---|
499 | $handler = $this->xmlhandler; |
---|
500 | $handler->printInfo(); |
---|
501 | } |
---|
502 | |
---|
503 | function getNodes() { |
---|
504 | $handler = $this->xmlhandler; |
---|
505 | return $handler->getNodes(); |
---|
506 | } |
---|
507 | |
---|
508 | function getNode( $node ) { |
---|
509 | $handler = $this->xmlhandler; |
---|
510 | return $handler->getNode( $node ); |
---|
511 | } |
---|
512 | |
---|
513 | function getCpus() { |
---|
514 | $handler = $this->xmlhandler; |
---|
515 | return $handler->getCpus(); |
---|
516 | } |
---|
517 | |
---|
518 | function getJobs() { |
---|
519 | $handler = $this->xmlhandler; |
---|
520 | return $handler->getJobs(); |
---|
521 | } |
---|
522 | |
---|
523 | function getJob( $job ) { |
---|
524 | $handler = $this->xmlhandler; |
---|
525 | return $handler->getJob( $job ); |
---|
526 | } |
---|
527 | |
---|
528 | function getHeartbeat() { |
---|
529 | $handler = $this->xmlhandler; |
---|
530 | return $handler->getHeartbeat(); |
---|
531 | } |
---|
532 | |
---|
533 | function isJobmonRunning() { |
---|
534 | $handler = $this->xmlhandler; |
---|
535 | return $handler->isJobmonRunning(); |
---|
536 | } |
---|
537 | } |
---|
538 | |
---|
539 | class TorqueXMLHandler { |
---|
540 | |
---|
541 | var $clusters, $heartbeat, $nodes, $jobs, $clustername, $proc_cluster; |
---|
542 | |
---|
543 | function TorqueXMLHandler( $clustername ) { |
---|
544 | $jobs = array(); |
---|
545 | $clusters = array(); |
---|
546 | $this->nodes = array(); |
---|
547 | $heartbeat = array(); |
---|
548 | $this->clustername = $clustername; |
---|
549 | //printf(" cluster set to %s \n", $this->clustername ); |
---|
550 | } |
---|
551 | |
---|
552 | function getCpus() { |
---|
553 | |
---|
554 | $cpus = 0; |
---|
555 | |
---|
556 | if( isset( $this->jobs ) && count( $this->jobs ) > 0 ) { |
---|
557 | |
---|
558 | foreach( $this->jobs as $jobid=>$jobattrs ) { |
---|
559 | |
---|
560 | $nodes = count( $jobattrs[nodes] ); |
---|
561 | $ppn = (int) $jobattrs[ppn] ? $jobattrs[ppn] : 1; |
---|
562 | $mycpus = $nodes * $ppn; |
---|
563 | |
---|
564 | $cpus = $cpus + $mycpus; |
---|
565 | } |
---|
566 | } |
---|
567 | } |
---|
568 | |
---|
569 | function isJobmonRunning() { |
---|
570 | |
---|
571 | if (isset( $this->heartbeat['time'] )) |
---|
572 | return 1; |
---|
573 | else |
---|
574 | return 0; |
---|
575 | } |
---|
576 | |
---|
577 | function startElement( $parser, $name, $attrs ) { |
---|
578 | |
---|
579 | $jobs = $this->jobs; |
---|
580 | $nodes = $this->nodes; |
---|
581 | |
---|
582 | if ( $attrs[TN] ) { |
---|
583 | |
---|
584 | // Ignore dead metrics. Detect and mask failures. |
---|
585 | if ( $attrs[TN] > $attrs[TMAX] * 4 ) |
---|
586 | return; |
---|
587 | } |
---|
588 | |
---|
589 | $jobid = null; |
---|
590 | |
---|
591 | //printf( '%s=%s', $attrs[NAME], $attrs[VAL] ); |
---|
592 | |
---|
593 | //printf( "clustername = %s proc_cluster = %s\n", $this->clustername, $this->proc_cluster ); |
---|
594 | |
---|
595 | if( $name == 'CLUSTER' ) { |
---|
596 | |
---|
597 | $this->proc_cluster = $attrs[NAME]; |
---|
598 | //printf( "Found cluster %s\n", $attrs[NAME] ); |
---|
599 | //print_r( $attrs ); |
---|
600 | |
---|
601 | //if( !isset( $clusters[$clustername] ) ) |
---|
602 | // $clusters[$clustername] = array(); |
---|
603 | |
---|
604 | } else if( $name == 'HOST' and $this->proc_cluster == $this->clustername) { |
---|
605 | |
---|
606 | $hostname = $attrs[NAME]; |
---|
607 | $location = $attrs[LOCATION]; |
---|
608 | //printf( "Found node %s\n", $hostname ); |
---|
609 | |
---|
610 | if( !isset( $nodes[$hostname] ) ) |
---|
611 | $nodes[$hostname] = new NodeImage( $this->proc_cluster, $hostname ); |
---|
612 | |
---|
613 | } else if( $name == 'METRIC' and strstr( $attrs[NAME], 'MONARCH' ) and $this->proc_cluster == $this->clustername ) { |
---|
614 | |
---|
615 | if( strstr( $attrs[NAME], 'MONARCH-HEARTBEAT' ) ) { |
---|
616 | |
---|
617 | $this->heartbeat['time'] = $attrs[VAL]; |
---|
618 | //printf( "heartbeat %s\n", $heartbeat['time'] ); |
---|
619 | |
---|
620 | } else if( strstr( $attrs[NAME], 'MONARCH-JOB' ) ) { |
---|
621 | |
---|
622 | sscanf( $attrs[NAME], 'MONARCH-JOB-%d-%d', $jobid, $monincr ); |
---|
623 | |
---|
624 | //printf( "jobid %s\n", $jobid ); |
---|
625 | |
---|
626 | if( !isset( $jobs[$jobid] ) ) |
---|
627 | $jobs[$jobid] = array(); |
---|
628 | |
---|
629 | $fields = explode( ' ', $attrs[VAL] ); |
---|
630 | |
---|
631 | foreach( $fields as $f ) { |
---|
632 | $togavalues = explode( '=', $f ); |
---|
633 | |
---|
634 | $toganame = $togavalues[0]; |
---|
635 | $togavalue = $togavalues[1]; |
---|
636 | |
---|
637 | //printf( "\t%s\t= %s\n", $toganame, $togavalue ); |
---|
638 | |
---|
639 | if( $toganame == 'nodes' ) { |
---|
640 | |
---|
641 | if( $jobs[$jobid][status] == 'R' ) { |
---|
642 | |
---|
643 | if( !isset( $jobs[$jobid][$toganame] ) ) |
---|
644 | $jobs[$jobid][$toganame] = array(); |
---|
645 | |
---|
646 | $mynodes = explode( ';', $togavalue ); |
---|
647 | |
---|
648 | //print_r($mynodes); |
---|
649 | |
---|
650 | foreach( $mynodes as $node ) { |
---|
651 | |
---|
652 | if( !in_array( $node, $jobs[$jobid][$toganame] ) ) { |
---|
653 | $jobs[$jobid][$toganame][] = $node; |
---|
654 | } |
---|
655 | } |
---|
656 | |
---|
657 | } else if( $jobs[$jobid][status] == 'Q' ) { |
---|
658 | |
---|
659 | $jobs[$jobid][$toganame] = $togavalue; |
---|
660 | } |
---|
661 | |
---|
662 | } else { |
---|
663 | |
---|
664 | $jobs[$jobid][$toganame] = $togavalue; |
---|
665 | } |
---|
666 | } |
---|
667 | |
---|
668 | if( isset( $jobs[$jobid][domain] ) and isset( $jobs[$jobid][nodes] ) ) { |
---|
669 | |
---|
670 | $nr_nodes = count( $jobs[$jobid][nodes] ); |
---|
671 | |
---|
672 | if( $jobs[$jobid][status] == 'R' ) { |
---|
673 | |
---|
674 | foreach( $jobs[$jobid][nodes] as $node ) { |
---|
675 | |
---|
676 | $domain = $jobs[$jobid][domain]; |
---|
677 | $domain_len = 0 - strlen( $domain ); |
---|
678 | |
---|
679 | if( substr( $node, $domain_len ) != $domain ) { |
---|
680 | $host = $node. '.'.$domain; |
---|
681 | } else { |
---|
682 | $host = $node; |
---|
683 | } |
---|
684 | |
---|
685 | //$host = $node.'.'.$jobs[$jobid][domain]; |
---|
686 | |
---|
687 | if( !isset( $nodes[$host] ) ) |
---|
688 | $my_node = new NodeImage( $this->proc_cluster, $host ); |
---|
689 | else |
---|
690 | $my_node = $nodes[$host]; |
---|
691 | |
---|
692 | if( !$my_node->hasJob( $jobid ) ) |
---|
693 | |
---|
694 | if( isset( $jobs[$jobid][ppn] ) ) |
---|
695 | $my_node->addJob( $jobid, ((int) $jobs[$jobid][ppn]) ); |
---|
696 | else |
---|
697 | $my_node->addJob( $jobid, 1 ); |
---|
698 | |
---|
699 | $nodes[$host] = $my_node; |
---|
700 | } |
---|
701 | } |
---|
702 | } |
---|
703 | } |
---|
704 | } |
---|
705 | $this->jobs = $jobs; |
---|
706 | //print_r( $nodes ); |
---|
707 | $this->nodes = $nodes; |
---|
708 | //print_r( $this->nodes ); |
---|
709 | } |
---|
710 | |
---|
711 | function stopElement( $parser, $name ) { |
---|
712 | } |
---|
713 | |
---|
714 | function printInfo() { |
---|
715 | |
---|
716 | $jobs = &$this->jobs; |
---|
717 | |
---|
718 | printf( "---jobs---\n" ); |
---|
719 | |
---|
720 | foreach( $jobs as $jobid => $job ) { |
---|
721 | |
---|
722 | printf( "job %s\n", $jobid ); |
---|
723 | |
---|
724 | if( isset( $job[nodes] ) ) { |
---|
725 | |
---|
726 | foreach( $job[nodes] as $node ) { |
---|
727 | |
---|
728 | $mynode = $this->nodes[$node]; |
---|
729 | $hostname = $mynode->getHostname(); |
---|
730 | $location = $mynode->getLocation(); |
---|
731 | |
---|
732 | printf( "\t- node %s\tlocation %s\n", $hostname, $location ); |
---|
733 | //$this->nodes[$hostname]->setLocation( "hier draait job ".$jobid ); |
---|
734 | } |
---|
735 | } |
---|
736 | } |
---|
737 | |
---|
738 | printf( "---nodes---\n" ); |
---|
739 | |
---|
740 | $nodes = &$this->nodes; |
---|
741 | |
---|
742 | foreach( $nodes as $node ) { |
---|
743 | |
---|
744 | $hostname = $node->getHostname(); |
---|
745 | $location = $node->getLocation(); |
---|
746 | $jobs = implode( ' ', $node->getJobs() ); |
---|
747 | printf( "* node %s\tlocation %s\tjobs %s\n", $hostname, $location, $jobs ); |
---|
748 | } |
---|
749 | } |
---|
750 | |
---|
751 | function getNodes() { |
---|
752 | //print_r( $this->nodes ); |
---|
753 | return $this->nodes; |
---|
754 | } |
---|
755 | |
---|
756 | function getNode( $node ) { |
---|
757 | |
---|
758 | $nodes = &$this->nodes; |
---|
759 | if( isset( $nodes[$node] ) ) |
---|
760 | return $nodes[$node]; |
---|
761 | else |
---|
762 | return NULL; |
---|
763 | } |
---|
764 | |
---|
765 | function getJobs() { |
---|
766 | return $this->jobs; |
---|
767 | } |
---|
768 | |
---|
769 | function getJob( $job ) { |
---|
770 | |
---|
771 | $jobs = &$this->jobs; |
---|
772 | if( isset( $jobs[$job] ) ) |
---|
773 | return $jobs[$job]; |
---|
774 | else |
---|
775 | return NULL; |
---|
776 | } |
---|
777 | |
---|
778 | function getHeartbeat() { |
---|
779 | return $this->heartbeat['time']; |
---|
780 | } |
---|
781 | } |
---|
782 | |
---|
783 | class NodeImage { |
---|
784 | |
---|
785 | var $image, $x, $y, $hostname, $jobs, $tasks, $showinfo; |
---|
786 | |
---|
787 | function NodeImage( $cluster, $hostname ) { |
---|
788 | |
---|
789 | global $SMALL_CLUSTERIMAGE_NODEWIDTH; |
---|
790 | |
---|
791 | $this->jobs = array(); |
---|
792 | //$this->image = $image; |
---|
793 | //$this->x = $x; |
---|
794 | //$this->y = $y; |
---|
795 | $this->tasks = 0; |
---|
796 | $this->hostname = $hostname; |
---|
797 | $this->cpus = $this->determineCpus(); |
---|
798 | $this->clustername = $cluster; |
---|
799 | $this->showinfo = 1; |
---|
800 | $this->size = $SMALL_CLUSTERIMAGE_NODEWIDTH; |
---|
801 | } |
---|
802 | |
---|
803 | function addJob( $jobid, $cpus ) { |
---|
804 | $jobs = &$this->jobs; |
---|
805 | |
---|
806 | $jobs[] = $jobid; |
---|
807 | $this->jobs = $jobs; |
---|
808 | |
---|
809 | $this->addTask( $cpus ); |
---|
810 | } |
---|
811 | |
---|
812 | function hasJob( $jobid ) { |
---|
813 | |
---|
814 | $jobfound = 0; |
---|
815 | |
---|
816 | if( count( $this->jobs ) > 0 ) |
---|
817 | foreach( $this->jobs as $job ) |
---|
818 | |
---|
819 | if( $job == $jobid ) |
---|
820 | $jobfound = 1; |
---|
821 | |
---|
822 | return $jobfound; |
---|
823 | } |
---|
824 | |
---|
825 | function addTask( $cpus ) { |
---|
826 | |
---|
827 | $this->tasks = $this->tasks + $cpus; |
---|
828 | } |
---|
829 | |
---|
830 | function setImage( $image ) { |
---|
831 | |
---|
832 | $this->image = $image; |
---|
833 | } |
---|
834 | |
---|
835 | function setCoords( $x, $y ) { |
---|
836 | |
---|
837 | $this->x = $x; |
---|
838 | $this->y = $y; |
---|
839 | } |
---|
840 | |
---|
841 | function getImagemapArea() { |
---|
842 | |
---|
843 | $area_topleft = $this->x . "," . $this->y; |
---|
844 | $area_bottomright = ($this->x + $this->size) . "," . ($this->y + $this->size); |
---|
845 | $area_coords = $area_topleft . "," . $area_bottomright; |
---|
846 | |
---|
847 | $area_href = "./?c=" . $this->clustername . "&h=" . $this->hostname; |
---|
848 | $area_tooltip = $this->hostname . ": " . implode( " ", $this->jobs ); |
---|
849 | |
---|
850 | $tag_href = "HREF=\"" . $area_href . "\""; |
---|
851 | $tag_coords = "COORDS=\"" . $area_coords . "\""; |
---|
852 | $tag_tooltip1 = "ALT=\"" . $area_tooltip . "\""; |
---|
853 | $tag_tooltip2 = "TITLE=\"" . $area_tooltip . "\""; |
---|
854 | |
---|
855 | return ("<AREA SHAPE=\"RECT\" " . $tag_coords . " " . $tag_href . " " . $tag_tooltip1 . " " . $tag_tooltip2 . ">"); |
---|
856 | } |
---|
857 | |
---|
858 | function colorHex( $color ) { |
---|
859 | |
---|
860 | $my_color = imageColorAllocate( $this->image, hexdec( substr( $color, 0, 2 )), hexdec( substr( $color, 2, 2 )), hexdec( substr( $color, 4, 2 )) ); |
---|
861 | |
---|
862 | return $my_color; |
---|
863 | } |
---|
864 | |
---|
865 | function setLoad( $load ) { |
---|
866 | $this->load = $load; |
---|
867 | } |
---|
868 | |
---|
869 | function setHostname( $hostname ) { |
---|
870 | $this->hostname = $hostname; |
---|
871 | } |
---|
872 | |
---|
873 | function getHostname() { |
---|
874 | return $this->hostname; |
---|
875 | } |
---|
876 | |
---|
877 | function getJobs() { |
---|
878 | return $this->jobs; |
---|
879 | } |
---|
880 | |
---|
881 | function setShowinfo( $showinfo ) { |
---|
882 | $this->showinfo = $showinfo; |
---|
883 | } |
---|
884 | |
---|
885 | function drawSmall() { |
---|
886 | |
---|
887 | global $SMALL_CLUSTERIMAGE_NODEWIDTH; |
---|
888 | |
---|
889 | $this->size = $SMALL_CLUSTERIMAGE_NODEWIDTH; |
---|
890 | |
---|
891 | $this->draw(); |
---|
892 | } |
---|
893 | |
---|
894 | function drawBig() { |
---|
895 | |
---|
896 | global $BIG_CLUSTERIMAGE_NODEWIDTH; |
---|
897 | |
---|
898 | $this->size = $BIG_CLUSTERIMAGE_NODEWIDTH; |
---|
899 | |
---|
900 | $this->draw(); |
---|
901 | } |
---|
902 | |
---|
903 | function draw() { |
---|
904 | |
---|
905 | global $JOB_NODE_MARKING; |
---|
906 | |
---|
907 | $black_color = imageColorAllocate( $this->image, 0, 0, 0 ); |
---|
908 | $size = $this->size; |
---|
909 | |
---|
910 | imageFilledRectangle( $this->image, $this->x, $this->y, $this->x+($size), $this->y+($size), $black_color ); |
---|
911 | |
---|
912 | if( $this->showinfo) { |
---|
913 | |
---|
914 | $this->load = $this->determineLoad(); |
---|
915 | |
---|
916 | if( !isset( $this->image ) or !isset( $this->x ) or !isset( $this->y ) ) { |
---|
917 | printf( "aborting\n" ); |
---|
918 | printf( "x %d y %d load %f\n", $this->x, $this->y, $load ); |
---|
919 | return; |
---|
920 | } |
---|
921 | |
---|
922 | |
---|
923 | // Convert Ganglias Hexadecimal load color to a Decimal one |
---|
924 | // |
---|
925 | $load = $this->determineLoad(); |
---|
926 | $usecolor = $this->colorHex( load_color($load) ); |
---|
927 | imageFilledRectangle( $this->image, $this->x+1, $this->y+1, $this->x+($size-1), $this->y+($size-1), $usecolor ); |
---|
928 | if( count( $this->jobs ) > 0 ) |
---|
929 | imageString( $this->image, 1, $this->x+(($size/2)-1), $this->y+(($size/2)-4), $JOB_NODE_MARKING, $black_color ); |
---|
930 | |
---|
931 | } else { |
---|
932 | |
---|
933 | // White |
---|
934 | $usecolor = imageColorAllocate( $this->image, 255, 255, 255 ); |
---|
935 | imageFilledRectangle( $this->image, $this->x+1, $this->y+1, $this->x+($size-1), $this->y+($size-1), $usecolor ); |
---|
936 | } |
---|
937 | |
---|
938 | |
---|
939 | } |
---|
940 | |
---|
941 | function determineCpus() { |
---|
942 | |
---|
943 | global $metrics; |
---|
944 | |
---|
945 | $cpus = $metrics[$this->hostname][cpu_num][VAL]; |
---|
946 | if (!$cpus) $cpus=1; |
---|
947 | |
---|
948 | return $cpus; |
---|
949 | } |
---|
950 | |
---|
951 | function determineLoad() { |
---|
952 | |
---|
953 | global $metrics; |
---|
954 | |
---|
955 | $load_one = $metrics[$this->hostname][load_one][VAL]; |
---|
956 | $load = ((float) $load_one)/$this->cpus; |
---|
957 | |
---|
958 | return $load; |
---|
959 | } |
---|
960 | } |
---|
961 | |
---|
962 | class ClusterImage { |
---|
963 | |
---|
964 | var $dataget, $image, $clustername; |
---|
965 | var $filtername, $filters; |
---|
966 | |
---|
967 | //function ClusterImage( $clustername ) { |
---|
968 | function ClusterImage( $data, $clustername ) { |
---|
969 | |
---|
970 | //$this->dataget = $dataget; |
---|
971 | $this->dataget = new DataGatherer( $clustername ); |
---|
972 | $this->data = $data; |
---|
973 | $this->clustername = $clustername; |
---|
974 | $this->filters = array(); |
---|
975 | $this->size = 's'; |
---|
976 | $this->width = 0; |
---|
977 | $this->height = 0; |
---|
978 | $this->output = 1; |
---|
979 | } |
---|
980 | |
---|
981 | function getWidth() { |
---|
982 | return $this->width; |
---|
983 | } |
---|
984 | function getHeight() { |
---|
985 | return $this->height; |
---|
986 | } |
---|
987 | |
---|
988 | function setSmall() { |
---|
989 | $this->size = 's'; |
---|
990 | } |
---|
991 | |
---|
992 | function setBig() { |
---|
993 | $this->size = 'b'; |
---|
994 | } |
---|
995 | |
---|
996 | function setNoimage() { |
---|
997 | $this->output = 0; |
---|
998 | } |
---|
999 | |
---|
1000 | function isSmall() { |
---|
1001 | return ($this->size == 's'); |
---|
1002 | } |
---|
1003 | |
---|
1004 | function isBig() { |
---|
1005 | return ($this->size == 'b'); |
---|
1006 | } |
---|
1007 | |
---|
1008 | function setFilter( $filtername, $filtervalue ) { |
---|
1009 | |
---|
1010 | $this->filters[$filtername] = $filtervalue; |
---|
1011 | } |
---|
1012 | |
---|
1013 | function filterNodes( $jobs, $nodes ) { |
---|
1014 | |
---|
1015 | $filtered_nodes = array(); |
---|
1016 | |
---|
1017 | foreach( $nodes as $node ) { |
---|
1018 | |
---|
1019 | $hostname = $node->getHostname(); |
---|
1020 | |
---|
1021 | $addhost = 1; |
---|
1022 | |
---|
1023 | if( count( $this->filters ) > 0 ) { |
---|
1024 | |
---|
1025 | $mynjobs = $node->getJobs(); |
---|
1026 | |
---|
1027 | if( count( $mynjobs ) > 0 ) { |
---|
1028 | |
---|
1029 | foreach( $mynjobs as $myjob ) { |
---|
1030 | |
---|
1031 | foreach( $this->filters as $filtername => $filtervalue ) { |
---|
1032 | |
---|
1033 | if( $filtername!=null && $filtername!='' ) { |
---|
1034 | |
---|
1035 | if( $filtername == 'jobid' && !$node->hasJob( $filtervalue) ) { |
---|
1036 | $addhost = 0; |
---|
1037 | } else if( $filtername != 'jobid' ) { |
---|
1038 | if( $jobs[$myjob][$filtername] != $filtervalue ) { |
---|
1039 | $addhost = 0; |
---|
1040 | } |
---|
1041 | } |
---|
1042 | } |
---|
1043 | } |
---|
1044 | } |
---|
1045 | } else |
---|
1046 | $addhost = 0; |
---|
1047 | } |
---|
1048 | |
---|
1049 | if( $addhost ) |
---|
1050 | $filtered_nodes[] = $hostname; |
---|
1051 | } |
---|
1052 | |
---|
1053 | return $filtered_nodes; |
---|
1054 | } |
---|
1055 | |
---|
1056 | function draw() { |
---|
1057 | |
---|
1058 | global $SMALL_CLUSTERIMAGE_MAXWIDTH, $SMALL_CLUSTERIMAGE_NODEWIDTH; |
---|
1059 | global $BIG_CLUSTERIMAGE_MAXWIDTH, $BIG_CLUSTERIMAGE_NODEWIDTH; |
---|
1060 | |
---|
1061 | global $SORTBY_HOSTNAME, $SORT_ORDER, $skan_str; |
---|
1062 | global $x_first, $y_first; |
---|
1063 | |
---|
1064 | global $SORT_XLABEL, $SORT_YLABEL; |
---|
1065 | |
---|
1066 | $mydatag = $this->dataget; |
---|
1067 | $mydatag->parseXML( $this->data ); |
---|
1068 | |
---|
1069 | if( $this->isSmall() ) { |
---|
1070 | $max_width = $SMALL_CLUSTERIMAGE_MAXWIDTH; |
---|
1071 | $node_width = $SMALL_CLUSTERIMAGE_NODEWIDTH; |
---|
1072 | } else if( $this->isBig() ) { |
---|
1073 | $max_width = $BIG_CLUSTERIMAGE_MAXWIDTH; |
---|
1074 | $node_width = $BIG_CLUSTERIMAGE_NODEWIDTH; |
---|
1075 | } |
---|
1076 | |
---|
1077 | $nodes = $mydatag->getNodes(); |
---|
1078 | $nodes_hosts = array_keys( $nodes ); |
---|
1079 | |
---|
1080 | $nodes_nr = count( $nodes ); |
---|
1081 | |
---|
1082 | $nodes_size = $nodes_nr*$node_width; |
---|
1083 | $node_rows = 0; |
---|
1084 | |
---|
1085 | if( $nodes_size > $max_width ) { |
---|
1086 | $nodes_per_row = ( (int) ($max_width/$node_width) ); |
---|
1087 | } else { |
---|
1088 | $nodes_per_row = $nodes_size; |
---|
1089 | $node_rows = 1; |
---|
1090 | } |
---|
1091 | |
---|
1092 | if( $nodes_per_row < $nodes_nr ) { |
---|
1093 | $node_rows = ( (int) ($nodes_nr/$nodes_per_row) ); |
---|
1094 | $node_rest = fmod( $nodes_nr, $nodes_per_row ); |
---|
1095 | //printf( "nodesnr %d noderest %f\n", $nodes_nr, $node_rest ); |
---|
1096 | if( $node_rest > 0 ) { |
---|
1097 | $node_rows++; |
---|
1098 | //printf( "noderows %d\n", $node_rows ); |
---|
1099 | } |
---|
1100 | } |
---|
1101 | |
---|
1102 | $y_offset = 0; |
---|
1103 | $font = 2; |
---|
1104 | $fontwidth = ImageFontWidth( $font ); |
---|
1105 | $fontheight = ImageFontHeight( $font ); |
---|
1106 | $fontspaceing = 2; |
---|
1107 | $y_offset = $fontheight + (2 * $fontspaceing); |
---|
1108 | |
---|
1109 | $this->width = $max_width; |
---|
1110 | $this->height = ($y_offset + (($node_rows*$node_width)+1) ); |
---|
1111 | |
---|
1112 | //$image = imageCreateTrueColor( $max_width, ($y_offset + (($node_rows*$node_width)+1) ) ); |
---|
1113 | //$colorwhite = imageColorAllocate( $image, 255, 255, 255 ); |
---|
1114 | //imageFill( $image, 0, 0, $colorwhite ); |
---|
1115 | |
---|
1116 | //if( $this->isSmall() ) { |
---|
1117 | |
---|
1118 | // $colorblue = imageColorAllocate( $image, 0, 0, 255 ); |
---|
1119 | |
---|
1120 | // imageString( $image, $font, 2, 2, "Monarch Joblist - cluster: ".$this->clustername, $colorblue ); |
---|
1121 | //} |
---|
1122 | |
---|
1123 | $jobs = $mydatag->getJobs(); |
---|
1124 | //printf("filtername = %s\n", $filtername ); |
---|
1125 | $filtered_nodes = $this->filterNodes( $jobs, $nodes ); |
---|
1126 | |
---|
1127 | //print_r($filtered_nodes); |
---|
1128 | |
---|
1129 | if( $SORTBY_HOSTNAME != "" ) |
---|
1130 | { |
---|
1131 | |
---|
1132 | $sorted = array(); |
---|
1133 | |
---|
1134 | $x_first = 0; |
---|
1135 | $y_first = 0; |
---|
1136 | |
---|
1137 | |
---|
1138 | if( strpos( $SORTBY_HOSTNAME, "{x}" ) < strpos( $SORTBY_HOSTNAME, "{y}" ) ) |
---|
1139 | { |
---|
1140 | |
---|
1141 | $x_first = 1; |
---|
1142 | } |
---|
1143 | else |
---|
1144 | { |
---|
1145 | $y_first = 1; |
---|
1146 | |
---|
1147 | } |
---|
1148 | |
---|
1149 | $skan_str = str_replace( "{x}", "%d", $SORTBY_HOSTNAME ); |
---|
1150 | $skan_str = str_replace( "{y}", "%d", $skan_str ); |
---|
1151 | |
---|
1152 | $x_min = null; |
---|
1153 | $x_max = null; |
---|
1154 | $y_min = null; |
---|
1155 | $y_max = null; |
---|
1156 | |
---|
1157 | foreach( $nodes as $hostname => $node ) |
---|
1158 | { |
---|
1159 | //$n = sscanf( $hostname, $skan_str, $i, $j ); |
---|
1160 | if( $x_first ) |
---|
1161 | { |
---|
1162 | $n = sscanf( $hostname, $skan_str, $x, $y ); |
---|
1163 | } |
---|
1164 | else if( $y_first ) |
---|
1165 | { |
---|
1166 | $n = sscanf( $hostname, $skan_str, $y, $x ); |
---|
1167 | } |
---|
1168 | |
---|
1169 | //printf( "n %s\n", $n ); |
---|
1170 | |
---|
1171 | // Remove nodes that don't match |
---|
1172 | // |
---|
1173 | if( $n < 2 ) |
---|
1174 | { |
---|
1175 | unset( $nodes[$hostname] ); |
---|
1176 | } |
---|
1177 | |
---|
1178 | if( !$x_min ) |
---|
1179 | { |
---|
1180 | $x_min = $x; |
---|
1181 | } |
---|
1182 | else if( $x < $x_min ) |
---|
1183 | { |
---|
1184 | $x_min = $x; |
---|
1185 | } |
---|
1186 | if( !$x_max ) |
---|
1187 | { |
---|
1188 | $x_max = $x; |
---|
1189 | } |
---|
1190 | else if( $x > $x_max ) |
---|
1191 | { |
---|
1192 | $x_max = $x; |
---|
1193 | } |
---|
1194 | if( !$y_min ) |
---|
1195 | { |
---|
1196 | $y_min = $y; |
---|
1197 | } |
---|
1198 | else if( $y < $y_min ) |
---|
1199 | { |
---|
1200 | $y_min = $y; |
---|
1201 | } |
---|
1202 | if( !$y_max ) |
---|
1203 | { |
---|
1204 | $y_max = $y; |
---|
1205 | } |
---|
1206 | else if( $y > $y_max ) |
---|
1207 | { |
---|
1208 | $y_max = $y; |
---|
1209 | } |
---|
1210 | } |
---|
1211 | |
---|
1212 | //printf( "ss %s\n", $skan_str); |
---|
1213 | $sorted_nodes = usort( $nodes, "cmp" ); |
---|
1214 | |
---|
1215 | $cur_node = 0; |
---|
1216 | |
---|
1217 | $x_offset = 0; |
---|
1218 | $y_offset = 0; |
---|
1219 | $font = 2; |
---|
1220 | $fontwidth = ImageFontWidth( $font ); |
---|
1221 | $fontheight = ImageFontHeight( $font ); |
---|
1222 | $fontspaceing = 2; |
---|
1223 | |
---|
1224 | if( $this->isBig() ) |
---|
1225 | { |
---|
1226 | |
---|
1227 | $y_offset = ($fontheight * (1 + strlen( $x_max) ) ) + ((2 + strlen( $x_max)) * $fontspaceing); |
---|
1228 | $x_offset = ($fontwidth * (1 + strlen( $y_max) ) ) + ((2 + strlen( $y_max)) * $fontspaceing); |
---|
1229 | |
---|
1230 | } |
---|
1231 | //$x_offset = ($fontwidth * 3) + (5 * $fontspaceing); |
---|
1232 | |
---|
1233 | //printf( "xmin %s xmax %s\n", $x_min, $x_max ); |
---|
1234 | //printf( "ymin %s ymax %s\n", $y_min, $y_max ); |
---|
1235 | |
---|
1236 | // werkt |
---|
1237 | //print_r( $nodes ); |
---|
1238 | |
---|
1239 | $image_width = $x_offset + ($node_width * ($x_max-$x_min+2)); |
---|
1240 | $image_width = ($image_width < $this->width) ? $image_width : $this->width; |
---|
1241 | $image_height = $y_offset + ($node_width * ($y_max-$y_min+2)); |
---|
1242 | |
---|
1243 | $this->width = $image_width; |
---|
1244 | $this->heigth = $image_heigth; |
---|
1245 | |
---|
1246 | $image = imageCreateTrueColor( $image_width, $image_height ); |
---|
1247 | $colorwhite = imageColorAllocate( $image, 255, 255, 255 ); |
---|
1248 | |
---|
1249 | imageFill( $image, 0, 0, $colorwhite ); |
---|
1250 | |
---|
1251 | if( $this->isBig() ) |
---|
1252 | { |
---|
1253 | $colorblue = imageColorAllocate( $image, 0, 0, 255 ); |
---|
1254 | |
---|
1255 | imageString( $image, $font, $x_offset, $fontspaceing, $SORT_XLABEL, $colorblue ); |
---|
1256 | |
---|
1257 | // Stupid php without imageStringDown function |
---|
1258 | // |
---|
1259 | imageStringDown( $image, $font, $fontspaceing, $y_offset, $SORT_YLABEL, $colorblue ); |
---|
1260 | } |
---|
1261 | |
---|
1262 | for( $n = $x_min; $n <= $x_max; $n++ ) |
---|
1263 | { |
---|
1264 | for( $m = $y_min; $m <= $y_max; $m++ ) |
---|
1265 | { |
---|
1266 | if( $x_min > 0 ) |
---|
1267 | { |
---|
1268 | $x = $x_offset + ( ($n-$x_min) * $node_width ); |
---|
1269 | } |
---|
1270 | if( $y_min > 0 ) |
---|
1271 | { |
---|
1272 | $y = $y_offset + ( ($m-$y_min) * $node_width ); |
---|
1273 | } |
---|
1274 | |
---|
1275 | if( $n == $x_min ) |
---|
1276 | { |
---|
1277 | $mfontspacing = 1; |
---|
1278 | $ylabel_x = $x - ( $fontwidth * strlen( $y_max ) ) - $mfontspacing; |
---|
1279 | $ylabel_y = $y; |
---|
1280 | |
---|
1281 | imageString( $image, $font, $ylabel_x, $ylabel_y, strval( $m ), $colorblue ); |
---|
1282 | } |
---|
1283 | if( $m == $y_min ) |
---|
1284 | { |
---|
1285 | $mfontspacing = 2; |
---|
1286 | $xlabel_y = $y - ( $fontheight * strlen( $x_max ) ); |
---|
1287 | $xlabel_x = $x + $mfontspacing; |
---|
1288 | |
---|
1289 | imageStringDown( $image, $font, $xlabel_x, $xlabel_y, strval( $n ), $colorblue ); |
---|
1290 | } |
---|
1291 | |
---|
1292 | if( isset( $nodes[$cur_node] ) ) |
---|
1293 | { |
---|
1294 | $host = $nodes[$cur_node]->getHostname(); |
---|
1295 | |
---|
1296 | if( $x_first ) |
---|
1297 | { |
---|
1298 | $nn = sscanf( $host, $skan_str, $rx, $ry ); |
---|
1299 | } |
---|
1300 | else if( $y_first ) |
---|
1301 | { |
---|
1302 | $nn = sscanf( $host, $skan_str, $ry, $rx ); |
---|
1303 | } |
---|
1304 | if ( $nn < 2 ) |
---|
1305 | { |
---|
1306 | continue; |
---|
1307 | } |
---|
1308 | if( ( $rx - $x_min ) > $n ) |
---|
1309 | { |
---|
1310 | $m = $y_max; |
---|
1311 | continue; |
---|
1312 | } |
---|
1313 | |
---|
1314 | if( !in_array( $host, $filtered_nodes ) ) |
---|
1315 | $nodes[$cur_node]->setShowinfo( 0 ); |
---|
1316 | |
---|
1317 | $nodes[$cur_node]->setCoords( $x, $y ); |
---|
1318 | $nodes[$cur_node]->setImage( $image ); |
---|
1319 | |
---|
1320 | //print_r( $nodes[$cur_node] ); |
---|
1321 | |
---|
1322 | if( $this->isSmall() ) |
---|
1323 | $nodes[$cur_node]->drawSmall(); |
---|
1324 | else if( $this->isBig() ) |
---|
1325 | $nodes[$cur_node]->drawBig(); |
---|
1326 | } |
---|
1327 | $cur_node++; |
---|
1328 | } |
---|
1329 | } |
---|
1330 | |
---|
1331 | } |
---|
1332 | else |
---|
1333 | { |
---|
1334 | $image = imageCreateTrueColor( $max_width, ($y_offset + (($node_rows*$node_width)+1) ) ); |
---|
1335 | $colorwhite = imageColorAllocate( $image, 255, 255, 255 ); |
---|
1336 | |
---|
1337 | imageFill( $image, 0, 0, $colorwhite ); |
---|
1338 | |
---|
1339 | if( $this->isSmall() ) { |
---|
1340 | |
---|
1341 | $colorblue = imageColorAllocate( $image, 0, 0, 255 ); |
---|
1342 | |
---|
1343 | imageString( $image, $font, 2, 2, "Monarch Joblist - cluster: ".$this->clustername, $colorblue ); |
---|
1344 | } |
---|
1345 | |
---|
1346 | for( $n = 0; $n < $node_rows; $n++ ) { |
---|
1347 | |
---|
1348 | for( $m = 0; $m < $nodes_per_row; $m++ ) { |
---|
1349 | |
---|
1350 | $x = ($m * $node_width); |
---|
1351 | $y = $y_offset + ($n * $node_width); |
---|
1352 | |
---|
1353 | $cur_node = ($n * $nodes_per_row) + ($m); |
---|
1354 | $host = $nodes_hosts[$cur_node]; |
---|
1355 | |
---|
1356 | if( isset( $nodes[$host] ) ) { |
---|
1357 | |
---|
1358 | $nodes[$host]->setCoords( $x, $y ); |
---|
1359 | $nodes[$host]->setImage( $image ); |
---|
1360 | |
---|
1361 | if( !in_array( $host, $filtered_nodes ) ) |
---|
1362 | $nodes[$host]->setShowinfo( 0 ); |
---|
1363 | |
---|
1364 | if( $this->isSmall() ) |
---|
1365 | $nodes[$host]->drawSmall(); |
---|
1366 | else if( $this->isBig() ) |
---|
1367 | $nodes[$host]->drawBig(); |
---|
1368 | } |
---|
1369 | } |
---|
1370 | } |
---|
1371 | } |
---|
1372 | |
---|
1373 | $this->nodes = &$nodes; |
---|
1374 | |
---|
1375 | if ($this->output) { |
---|
1376 | header( 'Content-type: image/png' ); |
---|
1377 | imagePNG( $image ); |
---|
1378 | imageDestroy( $image ); |
---|
1379 | } |
---|
1380 | } |
---|
1381 | |
---|
1382 | function getImagemapArea() { |
---|
1383 | |
---|
1384 | $clusterimage_map = ""; |
---|
1385 | |
---|
1386 | foreach( $this->nodes as $hostname => $node ) { |
---|
1387 | |
---|
1388 | $node_map = $node->getImagemapArea(); |
---|
1389 | $clusterimage_map .= $node_map; |
---|
1390 | } |
---|
1391 | |
---|
1392 | return $clusterimage_map; |
---|
1393 | } |
---|
1394 | } |
---|
1395 | |
---|
1396 | class EmptyImage { |
---|
1397 | |
---|
1398 | function draw() { |
---|
1399 | $image = imageCreateTrueColor( 1, 1 ); |
---|
1400 | $colorwhite = imageColorAllocate( $image, 255, 255, 255 ); |
---|
1401 | imageFill( $image, 0, 0, $colorwhite ); |
---|
1402 | |
---|
1403 | header( 'Content-type: image/png' ); |
---|
1404 | imagePNG( $image ); |
---|
1405 | imageDestroy( $image ); |
---|
1406 | } |
---|
1407 | } |
---|
1408 | |
---|
1409 | class HostImage { |
---|
1410 | |
---|
1411 | var $data_gather, $cluster, $host, $node, $image; |
---|
1412 | var $headerstrlen; |
---|
1413 | |
---|
1414 | function HostImage( $data_gather, $cluster, $host ) { |
---|
1415 | |
---|
1416 | $this->data_gather = $data_gather; |
---|
1417 | $this->cluster = $cluster; |
---|
1418 | $this->host = $host; |
---|
1419 | $this->y_offset = 0; |
---|
1420 | $this->font = 2; |
---|
1421 | $this->fontspaceing = 2; |
---|
1422 | $this->headerstrlen = array(); |
---|
1423 | |
---|
1424 | $this->fontheight = ImageFontHeight( $this->font ); |
---|
1425 | $this->fontwidth = ImageFontWidth( $this->font ); |
---|
1426 | |
---|
1427 | $dg = &$this->data_gather; |
---|
1428 | $this->node = &$dg->getNode( $this->host ); |
---|
1429 | $n = &$this->node; |
---|
1430 | $this->njobs = $n->getJobs(); |
---|
1431 | } |
---|
1432 | |
---|
1433 | function drawJobs() { |
---|
1434 | |
---|
1435 | $dg = &$this->data_gather; |
---|
1436 | $colorblack = imageColorAllocate( $this->image, 0, 0, 0 ); |
---|
1437 | |
---|
1438 | for( $n = 0; $n < count( $this->njobs ); $n++ ) { |
---|
1439 | |
---|
1440 | $jobid = $this->njobs[$n]; |
---|
1441 | $jobinfo = $dg->getJob( $jobid ); |
---|
1442 | |
---|
1443 | $xoffset = 5; |
---|
1444 | imageString( $this->image, $this->font, $xoffset, $this->y_offset, strval( $jobid ), $colorblack ); |
---|
1445 | |
---|
1446 | foreach( $this->headerstrlen as $headername => $headerlen ) { |
---|
1447 | |
---|
1448 | if( $headername == 'nodes' ) { |
---|
1449 | $attrval = strval( count( $jobinfo[nodes] ) ); |
---|
1450 | } else if( $headername == 'cpus' ) { |
---|
1451 | |
---|
1452 | if( !isset( $jobinfo[ppn] ) ) |
---|
1453 | $jobinfo[ppn] = 1; |
---|
1454 | |
---|
1455 | $attrval = strval( count( $jobinfo[nodes] ) * intval( $jobinfo[ppn] ) ); |
---|
1456 | |
---|
1457 | } else if( $headername == 'runningtime' ) { |
---|
1458 | $attrval = makeTime( intval( $jobinfo[reported] ) - intval( $jobinfo[start_timestamp] ) ); |
---|
1459 | } else { |
---|
1460 | $attrval = strval( $jobinfo[$headername] ); |
---|
1461 | } |
---|
1462 | |
---|
1463 | imageString( $this->image, $this->font, $xoffset, $this->y_offset, $attrval, $colorblack ); |
---|
1464 | |
---|
1465 | $xoffset = $xoffset + ($this->fontwidth * ( $headerlen + 1 ) ); |
---|
1466 | |
---|
1467 | } |
---|
1468 | |
---|
1469 | $this->newLineOffset(); |
---|
1470 | } |
---|
1471 | } |
---|
1472 | |
---|
1473 | function drawHeader() { |
---|
1474 | |
---|
1475 | $dg = &$this->data_gather; |
---|
1476 | |
---|
1477 | for( $n = 0; $n < count( $this->njobs ); $n++ ) { |
---|
1478 | |
---|
1479 | $jobid = $this->njobs[$n]; |
---|
1480 | $jobinfo = $dg->getJob( $jobid ); |
---|
1481 | |
---|
1482 | if( !isset( $this->headerstrlen[id] ) ) |
---|
1483 | $this->headerstrlen[id] = strlen( strval( $jobid ) ); |
---|
1484 | else |
---|
1485 | if( strlen( strval( $jobid ) ) > $this->headerstrlen[id] ) |
---|
1486 | $this->headerstrlen[id] = strlen( strval( $jobid ) ); |
---|
1487 | |
---|
1488 | if( !isset( $this->headerstrlen[owner] ) ) |
---|
1489 | $this->headerstrlen[owner] = strlen( strval( $jobinfo[owner] ) ); |
---|
1490 | else |
---|
1491 | if( strlen( strval( $jobinfo[owner] ) ) > $this->headerstrlen[owner] ) |
---|
1492 | $this->headerstrlen[owner] = strlen( strval( $jobinfo[owner] ) ); |
---|
1493 | |
---|
1494 | if( !isset( $this->headerstrlen[queue] ) ) |
---|
1495 | $this->headerstrlen[queue] = strlen( strval( $jobinfo[queue] ) ); |
---|
1496 | else |
---|
1497 | if( strlen( strval( $jobinfo[queue] ) ) > $this->headerstrlen[queue] ) |
---|
1498 | $this->headerstrlen[queue] = strlen( strval( $jobinfo[queue] ) ); |
---|
1499 | |
---|
1500 | if( !isset( $jobinfo[ppn] ) ) |
---|
1501 | $jobinfo[ppn] = 1; |
---|
1502 | |
---|
1503 | $cpus = count( $jobinfo[nodes] ) * intval( $jobinfo[ppn] ); |
---|
1504 | |
---|
1505 | if( !isset( $this->headerstrlen[cpus] ) ) |
---|
1506 | $this->headerstrlen[cpus] = strlen( strval( $cpus ) ); |
---|
1507 | else |
---|
1508 | if( strlen( strval( $cpus ) ) > $this->headerstrlen[cpus] ) |
---|
1509 | $this->headerstrlen[cpus] = strlen( strval( $cpus ) ); |
---|
1510 | |
---|
1511 | $nodes = count( $jobinfo[nodes] ); |
---|
1512 | |
---|
1513 | if( !isset( $this->headerstrlen[nodes] ) ) |
---|
1514 | $this->headerstrlen[nodes] = strlen( strval( $nodes ) ); |
---|
1515 | else |
---|
1516 | if( strlen( strval( $nodes) ) > $this->headerstrlen[nodes] ) |
---|
1517 | $this->headerstrlen[nodes] = strlen( strval( $nodes ) ); |
---|
1518 | |
---|
1519 | $runningtime = makeTime( intval( $jobinfo[reported] ) - intval( $jobinfo[start_timestamp] ) ); |
---|
1520 | |
---|
1521 | if( !isset( $this->headerstrlen[runningtime] ) ) |
---|
1522 | $this->headerstrlen[runningtime] = strlen( strval( $runningtime) ); |
---|
1523 | else |
---|
1524 | if( strlen( strval( $runningtime) ) > $this->headerstrlen[runningtime] ) |
---|
1525 | $this->headerstrlen[runningtime] = strlen( strval( $runningtime) ); |
---|
1526 | |
---|
1527 | if( !isset( $this->headerstrlen[name] ) ) |
---|
1528 | $this->headerstrlen[name] = strlen( strval( $jobinfo[name] ) ); |
---|
1529 | else |
---|
1530 | if( strlen( strval( $jobinfo[name] ) ) > $this->headerstrlen[name] ) |
---|
1531 | $this->headerstrlen[name] = strlen( strval( $jobinfo[name] ) ); |
---|
1532 | |
---|
1533 | } |
---|
1534 | |
---|
1535 | $xoffset = 5; |
---|
1536 | |
---|
1537 | foreach( $this->headerstrlen as $headername => &$headerlen ) { |
---|
1538 | |
---|
1539 | $colorgreen = imageColorAllocate( $this->image, 0, 200, 0 ); |
---|
1540 | |
---|
1541 | imageString( $this->image, $this->font, $xoffset, $this->y_offset, ucfirst( $headername ), $colorgreen ); |
---|
1542 | |
---|
1543 | if( $headerlen < strlen( $headername ) ) |
---|
1544 | $headerlen = strlen( $headername ); |
---|
1545 | |
---|
1546 | $xoffset = $xoffset + ($this->fontwidth * ( $headerlen + 1 ) ); |
---|
1547 | |
---|
1548 | } |
---|
1549 | $this->newLineOffset(); |
---|
1550 | } |
---|
1551 | |
---|
1552 | function newLineOffset() { |
---|
1553 | |
---|
1554 | $this->y_offset = $this->y_offset + $this->fontheight + $this->fontspaceing; |
---|
1555 | } |
---|
1556 | |
---|
1557 | function draw() { |
---|
1558 | |
---|
1559 | $xlen = 450; |
---|
1560 | $ylen = ( count( $this->njobs ) * ( $this->fontheight + $this->fontspaceing ) ) + (3 * $this->fontheight); |
---|
1561 | |
---|
1562 | $this->image = imageCreateTrueColor( $xlen, $ylen ); |
---|
1563 | $colorwhite = imageColorAllocate( $this->image, 255, 255, 255 ); |
---|
1564 | imageFill( $this->image, 0, 0, $colorwhite ); |
---|
1565 | |
---|
1566 | $colorblue = imageColorAllocate( $this->image, 0, 0, 255 ); |
---|
1567 | |
---|
1568 | imageString( $this->image, $this->font, 1, $this->y_offset, "Monarch Joblist - host: ".$this->host, $colorblue ); |
---|
1569 | $this->newLineOffset(); |
---|
1570 | |
---|
1571 | $this->drawHeader(); |
---|
1572 | $this->drawJobs(); |
---|
1573 | |
---|
1574 | header( 'Content-type: image/png' ); |
---|
1575 | imagePNG( $this->image ); |
---|
1576 | imageDestroy( $this->image ); |
---|
1577 | } |
---|
1578 | } |
---|
1579 | |
---|
1580 | function imageStringDown( &$image, $font, $x, $y, &$s, &$col ) |
---|
1581 | { |
---|
1582 | $fw = imagefontwidth( $font); |
---|
1583 | $fh = imagefontheight( $font); |
---|
1584 | |
---|
1585 | $fontspacing = 0; |
---|
1586 | |
---|
1587 | $fx = $x; |
---|
1588 | $fy = $y; |
---|
1589 | |
---|
1590 | for( $n=0; $n<strlen( $s ); $n++ ) |
---|
1591 | { |
---|
1592 | $myc = $s{$n}; |
---|
1593 | |
---|
1594 | imagestring( $image, $font, $fx, $fy, $myc, $col ); |
---|
1595 | |
---|
1596 | $fy += ($fontspacing + $fh ); |
---|
1597 | } |
---|
1598 | } |
---|
1599 | |
---|
1600 | function array_rem( $val, &$arr ) |
---|
1601 | { |
---|
1602 | // Delete val from arr |
---|
1603 | // |
---|
1604 | $i = array_search( $val, $arr ); |
---|
1605 | |
---|
1606 | if( $i == false ) return false; |
---|
1607 | |
---|
1608 | $arr = array_merge( array_slice( $arr, 0, $i ), array_slice( $arr, $i+1, count( $arr ) ) ); |
---|
1609 | |
---|
1610 | return true; |
---|
1611 | } |
---|
1612 | |
---|
1613 | function cmp( $a, $b ) |
---|
1614 | { |
---|
1615 | global $SORT_ORDER; |
---|
1616 | global $skan_str; |
---|
1617 | global $x_first, $y_first; |
---|
1618 | |
---|
1619 | $a_node = $a; |
---|
1620 | $b_node = $b; |
---|
1621 | $a = $a_node->getHostname(); |
---|
1622 | $b = $b_node->getHostname(); |
---|
1623 | |
---|
1624 | if( $a == $b ) return 0; |
---|
1625 | |
---|
1626 | if( $x_first ) |
---|
1627 | { |
---|
1628 | $n = sscanf( $a, $skan_str, $a_x, $a_y ); |
---|
1629 | $n = sscanf( $b, $skan_str, $b_x, $b_y ); |
---|
1630 | } |
---|
1631 | else if( $y_first ) |
---|
1632 | { |
---|
1633 | $n = sscanf( $a, $skan_str, $a_y, $a_x ); |
---|
1634 | $n = sscanf( $b, $skan_str, $b_y, $b_x ); |
---|
1635 | } |
---|
1636 | |
---|
1637 | if ( $SORT_ORDER=="desc" ) |
---|
1638 | { |
---|
1639 | |
---|
1640 | // 1 = a < b |
---|
1641 | // -1 = a > b |
---|
1642 | // |
---|
1643 | if ($a_x == $b_x) |
---|
1644 | { |
---|
1645 | if ($a_y < $b_y) |
---|
1646 | { |
---|
1647 | return 1; |
---|
1648 | } |
---|
1649 | else if ($a_y > $b_y) |
---|
1650 | { |
---|
1651 | return -1; |
---|
1652 | } |
---|
1653 | } |
---|
1654 | else if ($a_x < $b_x) |
---|
1655 | { |
---|
1656 | return 1; |
---|
1657 | } |
---|
1658 | else if ($a_x > $b_x) |
---|
1659 | { |
---|
1660 | return -1; |
---|
1661 | } |
---|
1662 | } |
---|
1663 | else if ( $SORT_ORDER == "asc" ) |
---|
1664 | { |
---|
1665 | |
---|
1666 | // 1 = a > b |
---|
1667 | // -1 = a < b |
---|
1668 | // |
---|
1669 | if ($a_x == $b_x) |
---|
1670 | { |
---|
1671 | if ($a_y > $b_y) |
---|
1672 | { |
---|
1673 | return 1; |
---|
1674 | } |
---|
1675 | else if ($a_y < $b_y) |
---|
1676 | { |
---|
1677 | return -1; |
---|
1678 | } |
---|
1679 | } |
---|
1680 | else if ($a_x > $b_x) |
---|
1681 | { |
---|
1682 | return 1; |
---|
1683 | } |
---|
1684 | else if ($a_x < $b_x) |
---|
1685 | { |
---|
1686 | return -1; |
---|
1687 | } |
---|
1688 | } |
---|
1689 | } |
---|
1690 | function makeTime( $time ) { |
---|
1691 | |
---|
1692 | $days = intval( $time / 86400 ); |
---|
1693 | $time = ($days>0) ? $time % ($days * 86400) : $time; |
---|
1694 | |
---|
1695 | //printf( "time = %s, days = %s\n", $time, $days ); |
---|
1696 | |
---|
1697 | $date_str = ''; |
---|
1698 | $day_str = ''; |
---|
1699 | |
---|
1700 | if( $days > 0 ) { |
---|
1701 | if( $days > 1 ) |
---|
1702 | $day_str .= $days . ' days'; |
---|
1703 | else |
---|
1704 | $day_str .= $days . ' day'; |
---|
1705 | } |
---|
1706 | |
---|
1707 | $hours = intval( $time / 3600 ); |
---|
1708 | $time = $hours ? $time % ($hours * 3600) : $time; |
---|
1709 | |
---|
1710 | //printf( "time = %s, days = %s, hours = %s\n", $time, $days, $hours ); |
---|
1711 | if( $hours > 0 ) { |
---|
1712 | $date_str .= $hours . ':'; |
---|
1713 | $date_unit = 'hours'; |
---|
1714 | } |
---|
1715 | |
---|
1716 | $minutes = intval( $time / 60 ); |
---|
1717 | $seconds = $minutes ? $time % ($minutes * 60) : $time; |
---|
1718 | |
---|
1719 | if( $minutes > 0 ) { |
---|
1720 | |
---|
1721 | if( $minutes >= 10 ) |
---|
1722 | $date_str .= $minutes . ':'; |
---|
1723 | else |
---|
1724 | $date_str .= '0' . $minutes . ':'; |
---|
1725 | |
---|
1726 | $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit; |
---|
1727 | } else { |
---|
1728 | if($hours > 0 ) { |
---|
1729 | $date_str .= '00:'; |
---|
1730 | $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit; |
---|
1731 | } |
---|
1732 | } |
---|
1733 | |
---|
1734 | |
---|
1735 | $date_unit = (!isset($date_unit)) ? 'seconds' : $date_unit; |
---|
1736 | |
---|
1737 | if( $seconds > 0 ) { |
---|
1738 | |
---|
1739 | if( $seconds >= 10 ) |
---|
1740 | $date_str .= $seconds . ' ' . $date_unit; |
---|
1741 | else |
---|
1742 | $date_str .= '0' . $seconds . ' ' . $date_unit; |
---|
1743 | |
---|
1744 | } else if ( $hours > 0 or $minutes > 0 ) |
---|
1745 | |
---|
1746 | $date_str .= '00 ' . $date_unit; |
---|
1747 | |
---|
1748 | if( $days > 0) { |
---|
1749 | |
---|
1750 | if( $hours > 0 or $minutes > 0 or $seconds > 0 ) |
---|
1751 | $date_str = $day_str . ' - ' . $date_str; |
---|
1752 | else |
---|
1753 | $date_str = $day_str; |
---|
1754 | } |
---|
1755 | |
---|
1756 | return $date_str; |
---|
1757 | } |
---|
1758 | ?> |
---|