[113] | 1 | <?php |
---|
[225] | 2 | /* |
---|
| 3 | * |
---|
| 4 | * This file is part of Jobmonarch |
---|
| 5 | * |
---|
[732] | 6 | * Copyright (C) 2006-2013 Ramon Bastiaans |
---|
[225] | 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 | * |
---|
[231] | 22 | * SVN $Id: overview.php 757 2013-03-26 20:54:43Z ramonb $ |
---|
[225] | 23 | */ |
---|
| 24 | |
---|
[753] | 25 | global $GANGLIA_PATH, $clustername, $tpl_data, $filter, $cluster, $get_metric_string, $cluster_url, $sh; |
---|
[299] | 26 | global $hosts_up, $m, $start, $end, $filterorder, $COLUMN_REQUESTED_MEMORY, $COLUMN_QUEUED, $COLUMN_NODES, $hostname, $piefilter; |
---|
[409] | 27 | global $longtitle, $title, $range; |
---|
[114] | 28 | |
---|
[753] | 29 | include_once "./dwoo/dwooAutoload.php"; |
---|
[116] | 30 | |
---|
[753] | 31 | global $dwoo; |
---|
| 32 | |
---|
| 33 | $tpl = new Dwoo_Template_File("templates/overview.tpl"); |
---|
| 34 | $tpl_data = new Dwoo_Data(); |
---|
| 35 | |
---|
| 36 | $tpl_data->assign( "clustername", $clustername ); |
---|
| 37 | |
---|
[206] | 38 | if( $JOB_ARCHIVE ) |
---|
[328] | 39 | { |
---|
[753] | 40 | $tpl_data->assign( "cluster_url", rawurlencode($clustername) ); |
---|
[328] | 41 | } |
---|
[129] | 42 | |
---|
[738] | 43 | $rjqj_start = null; |
---|
[732] | 44 | $ds = new DataSource(); |
---|
| 45 | $myxml_data = $ds->getData(); |
---|
[328] | 46 | |
---|
[732] | 47 | $data_gatherer = new DataGatherer( $clustername ); |
---|
[326] | 48 | $data_gatherer->parseXML( $myxml_data ); |
---|
[117] | 49 | |
---|
[732] | 50 | $heartbeat = $data_gatherer->getHeartbeat(); |
---|
| 51 | $jobs = $data_gatherer->getJobs(); |
---|
| 52 | $gnodes = $data_gatherer->getNodes(); |
---|
| 53 | $cpus = $data_gatherer->getCpus(); |
---|
| 54 | $use_fqdn = $data_gatherer->getUsingFQDN(); |
---|
[114] | 55 | |
---|
[743] | 56 | //print_r( $gnodes ); |
---|
| 57 | |
---|
[328] | 58 | function setupFilterSettings() |
---|
| 59 | { |
---|
| 60 | |
---|
[753] | 61 | global $tpl_data, $filter, $clustername, $piefilter, $data_gatherer, $myxml_data, $filterorder, $_SESSION; |
---|
[122] | 62 | |
---|
[719] | 63 | $filter_image_url = ""; |
---|
[119] | 64 | |
---|
[719] | 65 | foreach( $filter as $filtername => $filtervalue ) |
---|
| 66 | { |
---|
[753] | 67 | $tpl_data->assign( $filtername, $filtervalue ); |
---|
[328] | 68 | |
---|
[719] | 69 | $filter_image_url .= "&$filtername=$filtervalue"; |
---|
| 70 | } |
---|
[114] | 71 | |
---|
[719] | 72 | session_start(); |
---|
[326] | 73 | |
---|
[719] | 74 | unset( $_SESSION["data"] ); |
---|
[732] | 75 | $_SESSION["data"] = &$myxml_data; |
---|
[328] | 76 | |
---|
[732] | 77 | $ic = new ClusterImage( $myxml_data, $clustername ); |
---|
[328] | 78 | |
---|
[743] | 79 | $ic->setJobs( $data_gatherer->getJobs() ); |
---|
| 80 | $ic->setNodes( $data_gatherer->getNodes() ); |
---|
[719] | 81 | $ic->setBig(); |
---|
| 82 | $ic->setNoimage(); |
---|
| 83 | $ic->draw(); |
---|
[326] | 84 | |
---|
[753] | 85 | $tpl_data->assign( "clusterimage", "./image.php?". session_name() . "=" . session_id() ."&c=".rawurlencode($clustername)."&j_view=big-clusterimage".$filter_image_url ); |
---|
[326] | 86 | |
---|
[753] | 87 | $tpl_data->assign( "node_clustermap", "yes" ); |
---|
| 88 | $tpl_data->assign( "node_area_map", $ic->getImagemapArea() ); |
---|
[326] | 89 | |
---|
[753] | 90 | $tpl_data->assign( "order", $filterorder ); |
---|
[114] | 91 | |
---|
[719] | 92 | if( array_key_exists( "id", $filter ) ) |
---|
| 93 | { |
---|
| 94 | $piefilter = 'id'; |
---|
| 95 | } |
---|
| 96 | else if( array_key_exists( "owner", $filter ) ) |
---|
| 97 | { |
---|
| 98 | $piefilter = 'owner'; |
---|
| 99 | } |
---|
| 100 | else if( array_key_exists( "queue", $filter ) ) |
---|
| 101 | { |
---|
| 102 | $piefilter = 'queue'; |
---|
| 103 | } |
---|
[122] | 104 | |
---|
[719] | 105 | $pie = drawPie(); |
---|
[328] | 106 | |
---|
[753] | 107 | $tpl_data->assign("pie", $pie ); |
---|
[263] | 108 | } |
---|
[122] | 109 | |
---|
[328] | 110 | function timeToEpoch( $time ) |
---|
| 111 | { |
---|
[732] | 112 | $time_fields = explode( ':', $time ); |
---|
[120] | 113 | |
---|
[719] | 114 | if( count( $time_fields ) == 3 ) |
---|
| 115 | { |
---|
[732] | 116 | $hours = $time_fields[0]; |
---|
| 117 | $minutes = $time_fields[1]; |
---|
| 118 | $seconds = $time_fields[2]; |
---|
[120] | 119 | |
---|
[719] | 120 | } |
---|
| 121 | else if( count( $time_fields ) == 2 ) |
---|
| 122 | { |
---|
[732] | 123 | $hours = 0; |
---|
| 124 | $minutes = $time_fields[0]; |
---|
| 125 | $seconds = $time_fields[1]; |
---|
[120] | 126 | |
---|
[719] | 127 | } |
---|
| 128 | else if( count( $time_fields ) == 1 ) |
---|
| 129 | { |
---|
[732] | 130 | $hours = 0; |
---|
| 131 | $minutes = 0; |
---|
| 132 | $seconds = $time_fields[0]; |
---|
[719] | 133 | } |
---|
[128] | 134 | |
---|
[732] | 135 | $myepoch = intval( $seconds + (intval( $minutes * 60 )) + (intval( $hours * 3600 )) ); |
---|
[128] | 136 | |
---|
[719] | 137 | return $myepoch; |
---|
[120] | 138 | } |
---|
| 139 | |
---|
[328] | 140 | function colorRed( $color ) |
---|
| 141 | { |
---|
[719] | 142 | return substr( $color, 0, 2 ); |
---|
[114] | 143 | } |
---|
[328] | 144 | |
---|
| 145 | function colorGreen( $color ) |
---|
| 146 | { |
---|
[719] | 147 | return substr( $color, 2, 2 ); |
---|
[114] | 148 | } |
---|
[328] | 149 | |
---|
| 150 | function colorBlue( $color ) |
---|
| 151 | { |
---|
[719] | 152 | return substr( $color, 4, 2 ); |
---|
[114] | 153 | } |
---|
| 154 | |
---|
[328] | 155 | function colorDiffer( $first, $second ) |
---|
| 156 | { |
---|
[719] | 157 | // Make sure these two colors differ atleast 50 R/G/B |
---|
| 158 | $min_diff = 50; |
---|
[114] | 159 | |
---|
[732] | 160 | $c1r = hexDec( colorRed( $first ) ); |
---|
| 161 | $c1g = hexDec( colorGreen( $first ) ); |
---|
| 162 | $c1b = hexDec( colorBlue( $first ) ); |
---|
[114] | 163 | |
---|
[732] | 164 | $c2r = hexDec( colorRed( $second ) ); |
---|
| 165 | $c2g = hexDec( colorGreen( $second ) ); |
---|
| 166 | $c2b = hexDec( colorBlue( $second ) ); |
---|
[114] | 167 | |
---|
[732] | 168 | $rdiff = ($c1r >= $c2r) ? $c1r - $c2r : $c2r - $c1r; |
---|
| 169 | $gdiff = ($c1g >= $c2g) ? $c1g - $c2g : $c2g - $c1g; |
---|
| 170 | $bdiff = ($c1b >= $c2b) ? $c1b - $c2b : $c2b - $c1b; |
---|
[114] | 171 | |
---|
[719] | 172 | if( $rdiff >= $min_diff or $gdiff >= $min_diff or $bdiff >= $min_diff ) |
---|
| 173 | { |
---|
| 174 | return TRUE; |
---|
[328] | 175 | |
---|
[719] | 176 | } |
---|
| 177 | else |
---|
| 178 | { |
---|
| 179 | return FALSE; |
---|
| 180 | } |
---|
[114] | 181 | } |
---|
| 182 | |
---|
[328] | 183 | function randomColor( $known_colors ) |
---|
| 184 | { |
---|
[719] | 185 | // White (000000) would be invisible |
---|
[732] | 186 | $start = "004E00"; |
---|
[719] | 187 | |
---|
[732] | 188 | $start_red = colorRed( $start ); |
---|
| 189 | $start_green = colorGreen( $start ); |
---|
| 190 | $start_blue = colorBlue( $start ); |
---|
[719] | 191 | |
---|
[732] | 192 | $end = "FFFFFF"; |
---|
[114] | 193 | |
---|
[732] | 194 | $end_red = colorRed( $end ); |
---|
| 195 | $end_green = colorGreen( $end ); |
---|
[719] | 196 | $end_blue = colorBlue( $end ); |
---|
[114] | 197 | |
---|
[732] | 198 | $change_color= TRUE; |
---|
[114] | 199 | |
---|
[719] | 200 | while( $change_color ) |
---|
| 201 | { |
---|
[732] | 202 | $change_color= FALSE; |
---|
[114] | 203 | |
---|
[719] | 204 | $new_red = rand( hexDec( $start_red ), hexDec( $end_red ) ); |
---|
[732] | 205 | $new_green = rand( hexDec( $start_green ), hexDec( $end_green ) ); |
---|
| 206 | $new_blue = rand( hexDec( $start_blue ), hexDec( $end_blue ) ); |
---|
[114] | 207 | |
---|
[719] | 208 | $new = decHex( $new_red ) . decHex( $new_green ) . decHex( $new_blue ); |
---|
[114] | 209 | |
---|
[719] | 210 | foreach( $known_colors as $old ) |
---|
| 211 | { |
---|
| 212 | if( !colorDiffer( $new, $old ) ) |
---|
| 213 | { |
---|
| 214 | $change_color = TRUE; |
---|
| 215 | } |
---|
| 216 | } |
---|
| 217 | } |
---|
[114] | 218 | |
---|
[719] | 219 | // Whoa! Actually found a good color ;) |
---|
| 220 | return $new; |
---|
[114] | 221 | } |
---|
| 222 | |
---|
[328] | 223 | // Code these some day |
---|
| 224 | function drawJobPie() { } |
---|
[114] | 225 | |
---|
[328] | 226 | function drawUserPie() { } |
---|
[124] | 227 | |
---|
[328] | 228 | function drawQueuePie() { } |
---|
[126] | 229 | |
---|
[328] | 230 | function drawPie() |
---|
| 231 | { |
---|
[719] | 232 | global $jobs, $gnodes, $piefilter, $filter, $metrics; |
---|
[114] | 233 | |
---|
[732] | 234 | $nodes = $gnodes; |
---|
[127] | 235 | |
---|
[719] | 236 | if( isset($piefilter) ) |
---|
| 237 | { |
---|
[732] | 238 | $pie_args = "title=" . rawurlencode("Cluster ".$piefilter." usage"); |
---|
[719] | 239 | } |
---|
| 240 | else |
---|
| 241 | { |
---|
[732] | 242 | $pie_args = "title=" . rawurlencode("Cluster queue usage"); |
---|
[719] | 243 | } |
---|
[328] | 244 | |
---|
[732] | 245 | $pie_args .= "&size=250x150"; |
---|
[114] | 246 | |
---|
[732] | 247 | $queues = array(); |
---|
| 248 | $nr_jobs = count( $jobs ); |
---|
| 249 | $nr_nodes = count( $nodes ); |
---|
[114] | 250 | |
---|
[732] | 251 | $nr_cpus = cluster_sum("cpu_num", $metrics); |
---|
[114] | 252 | |
---|
[732] | 253 | $empty_cpus= 0; |
---|
| 254 | $used_cpus = 0; |
---|
[123] | 255 | |
---|
[732] | 256 | $job_weight= array(); |
---|
[315] | 257 | |
---|
[719] | 258 | foreach( $nodes as $node ) |
---|
| 259 | { |
---|
[732] | 260 | $myjobs = $node->getJobs(); |
---|
| 261 | $myhost = $node->getHostname(); |
---|
| 262 | $node_cpus = $metrics[$myhost]["cpu_num"]['VAL']; |
---|
| 263 | $job_cpu = 0; |
---|
[114] | 264 | |
---|
[719] | 265 | foreach( $myjobs as $myjob ) |
---|
| 266 | { |
---|
[732] | 267 | $job_cpu += isset( $jobs[$myjob]['ppn'] ) ? $jobs[$myjob]['ppn'] : 1; |
---|
[719] | 268 | } |
---|
[315] | 269 | |
---|
[732] | 270 | $node_freecpu= $node_cpus - $job_cpu; |
---|
[315] | 271 | |
---|
[732] | 272 | $empty_cpus += $node_freecpu; |
---|
[719] | 273 | } |
---|
[114] | 274 | |
---|
[732] | 275 | $empty_cpus = ( $empty_cpus >= 0 ) ? $empty_cpus : 0; |
---|
| 276 | $used_cpus = $nr_cpus - $empty_cpus; |
---|
[114] | 277 | |
---|
[732] | 278 | $empty_percentage= $empty_cpus; |
---|
[114] | 279 | |
---|
[732] | 280 | $qcolors = array(); |
---|
| 281 | $color = randomColor( $qcolors ); |
---|
| 282 | $qcolors[] = $color; |
---|
| 283 | $pie_args .= "&free=$empty_percentage,$color"; |
---|
[315] | 284 | |
---|
[719] | 285 | if( isset( $piefilter ) ) |
---|
| 286 | { |
---|
| 287 | $filterpie = array(); |
---|
| 288 | } |
---|
[127] | 289 | |
---|
[719] | 290 | foreach( $nodes as $node ) |
---|
| 291 | { |
---|
[732] | 292 | $node_jobs = $node->getJobs(); |
---|
| 293 | $nr_node_jobs = count( $node_jobs ); |
---|
| 294 | $myhost = $node->getHostname(); |
---|
[719] | 295 | $node_cpus = $metrics[$myhost]["cpu_num"]['VAL']; |
---|
[114] | 296 | |
---|
[719] | 297 | foreach( $node_jobs as $myjob ) |
---|
| 298 | { |
---|
[732] | 299 | $job_cpu = isset( $jobs[$myjob]['ppn'] ) ? $jobs[$myjob]['ppn'] : 1; |
---|
[315] | 300 | |
---|
[719] | 301 | // Determine the weight of this job |
---|
| 302 | // - what percentage of the cpus is in use by this job |
---|
| 303 | // |
---|
| 304 | //$job_weight[$myjob] = ( $job_cpu / $nr_cpus ); |
---|
| 305 | $job_weight[$myjob] = $job_cpu; |
---|
[123] | 306 | |
---|
[719] | 307 | if( isset( $piefilter ) ) { |
---|
[328] | 308 | |
---|
[719] | 309 | $countjob = 1; |
---|
[328] | 310 | |
---|
[719] | 311 | if( $piefilter == 'id' ) |
---|
| 312 | { |
---|
| 313 | if( $myjob != $filter[$piefilter] ) |
---|
| 314 | { |
---|
| 315 | $countjob = 0; |
---|
| 316 | } |
---|
| 317 | } |
---|
| 318 | else if( $piefilter == 'owner' ) |
---|
| 319 | { |
---|
| 320 | if( $jobs[$myjob]['owner'] != $filter[$piefilter] ) |
---|
| 321 | { |
---|
| 322 | $countjob = 0; |
---|
| 323 | } |
---|
| 324 | } |
---|
| 325 | else |
---|
| 326 | { |
---|
| 327 | if( $jobs[$myjob][$piefilter] != $filter[$piefilter] ) |
---|
| 328 | { |
---|
| 329 | $countjob = 0; |
---|
| 330 | } |
---|
| 331 | } |
---|
[127] | 332 | |
---|
[719] | 333 | if( $countjob ) |
---|
| 334 | { |
---|
[127] | 335 | |
---|
[719] | 336 | if( !isset( $filterpie[$filter[$piefilter]] ) ) |
---|
| 337 | { |
---|
| 338 | $filterpie[$filter[$piefilter]] = $job_weight[$myjob]; |
---|
| 339 | } |
---|
| 340 | else |
---|
| 341 | { |
---|
[328] | 342 | |
---|
[719] | 343 | $filterpie[$filter[$piefilter]] = $filterpie[$filter[$piefilter]] + $job_weight[$myjob]; |
---|
| 344 | } |
---|
| 345 | } |
---|
| 346 | else |
---|
| 347 | { |
---|
| 348 | if( !isset( $filterpie["other"] ) ) |
---|
| 349 | { |
---|
| 350 | $filterpie["other"] = $job_weight[$myjob]; |
---|
| 351 | } |
---|
| 352 | else |
---|
| 353 | { |
---|
| 354 | $filterpie["other"] = $filterpie["other"] + $job_weight[$myjob]; |
---|
| 355 | } |
---|
[127] | 356 | |
---|
[719] | 357 | } |
---|
| 358 | |
---|
| 359 | } |
---|
| 360 | else |
---|
| 361 | { |
---|
[127] | 362 | |
---|
[732] | 363 | $qname = $jobs[$myjob]['queue']; |
---|
[315] | 364 | |
---|
[719] | 365 | if( !isset( $queues[$qname] ) ) |
---|
| 366 | { |
---|
| 367 | $queues[$qname] = $job_weight[$myjob]; |
---|
| 368 | } |
---|
| 369 | else |
---|
| 370 | { |
---|
| 371 | $queues[$qname] = $queues[$qname] + $job_weight[$myjob]; |
---|
| 372 | } |
---|
| 373 | } |
---|
| 374 | } |
---|
| 375 | } |
---|
[114] | 376 | |
---|
[719] | 377 | if( isset( $piefilter ) ) |
---|
| 378 | { |
---|
| 379 | $graphvals = $filterpie; |
---|
| 380 | } |
---|
| 381 | else |
---|
| 382 | { |
---|
| 383 | $graphvals = $queues; |
---|
| 384 | } |
---|
[114] | 385 | |
---|
[719] | 386 | foreach( $graphvals as $name => $totalweight) |
---|
| 387 | { |
---|
[732] | 388 | $percentage = $totalweight; |
---|
[719] | 389 | |
---|
| 390 | $color = randomColor( $qcolors ); |
---|
| 391 | $qcolors[] = $color; |
---|
| 392 | $pie_args .= "&$name=$percentage,$color"; |
---|
| 393 | } |
---|
| 394 | $pie = "../../pie.php?$pie_args"; |
---|
[114] | 395 | |
---|
[719] | 396 | return $pie; |
---|
[114] | 397 | } |
---|
| 398 | |
---|
| 399 | |
---|
[328] | 400 | function sortJobs( $jobs, $sortby, $sortorder ) |
---|
| 401 | { |
---|
[719] | 402 | $sorted = array(); |
---|
[114] | 403 | |
---|
[719] | 404 | $cmp = create_function( '$a, $b', |
---|
| 405 | "global \$sortby, \$sortorder;". |
---|
[116] | 406 | |
---|
[719] | 407 | "if( \$a == \$b ) return 0;". |
---|
[116] | 408 | |
---|
[719] | 409 | "if (\$sortorder==\"desc\")". |
---|
| 410 | "return ( \$a < \$b ) ? 1 : -1;". |
---|
| 411 | "else if (\$sortorder==\"asc\")". |
---|
| 412 | "return ( \$a > \$b ) ? 1 : -1;" ); |
---|
[117] | 413 | |
---|
[719] | 414 | if( isset( $jobs ) && count( $jobs ) > 0 ) |
---|
| 415 | { |
---|
| 416 | foreach( $jobs as $jobid => $jobattrs ) |
---|
| 417 | { |
---|
[732] | 418 | $state = $jobattrs['status']; |
---|
| 419 | $owner = $jobattrs['owner']; |
---|
| 420 | $queue = $jobattrs['queue']; |
---|
| 421 | $name = $jobattrs['name']; |
---|
| 422 | $req_cpu = $jobattrs['requested_time']; |
---|
| 423 | $req_memory= $jobattrs['requested_memory']; |
---|
[117] | 424 | |
---|
[719] | 425 | if( $state == 'R' ) |
---|
| 426 | { |
---|
| 427 | $nodes = count( $jobattrs['nodes'] ); |
---|
| 428 | } |
---|
| 429 | else |
---|
| 430 | { |
---|
| 431 | $nodes = $jobattrs['nodes']; |
---|
| 432 | } |
---|
[117] | 433 | |
---|
[719] | 434 | $ppn = (int) $jobattrs['ppn'] ? $jobattrs['ppn'] : 1; |
---|
[731] | 435 | $cpus = $nodes * $ppn; |
---|
| 436 | $queued_time = (int) $jobattrs['queued_timestamp']; |
---|
| 437 | $start_time = (int) $jobattrs['start_timestamp']; |
---|
| 438 | $runningtime = $report_time - $start_time; |
---|
[117] | 439 | |
---|
[719] | 440 | switch( $sortby ) |
---|
| 441 | { |
---|
| 442 | case "id": |
---|
| 443 | $sorted[$jobid] = $jobid; |
---|
| 444 | break; |
---|
[117] | 445 | |
---|
[719] | 446 | case "state": |
---|
| 447 | $sorted[$jobid] = $state; |
---|
| 448 | break; |
---|
[117] | 449 | |
---|
[719] | 450 | case "owner": |
---|
| 451 | $sorted[$jobid] = $owner; |
---|
| 452 | break; |
---|
[117] | 453 | |
---|
[719] | 454 | case "queue": |
---|
| 455 | $sorted[$jobid] = $queue; |
---|
| 456 | break; |
---|
[117] | 457 | |
---|
[719] | 458 | case "name": |
---|
| 459 | $sorted[$jobid] = $name; |
---|
| 460 | break; |
---|
[117] | 461 | |
---|
[719] | 462 | case "req_cpu": |
---|
| 463 | $sorted[$jobid] = timeToEpoch( $req_cpu ); |
---|
| 464 | break; |
---|
[117] | 465 | |
---|
[719] | 466 | case "req_mem": |
---|
| 467 | $sorted[$jobid] = $req_memory; |
---|
| 468 | break; |
---|
[117] | 469 | |
---|
[719] | 470 | case "nodes": |
---|
| 471 | $sorted[$jobid] = $nodes; |
---|
| 472 | break; |
---|
[117] | 473 | |
---|
[719] | 474 | case "cpus": |
---|
| 475 | $sorted[$jobid] = $cpus; |
---|
| 476 | break; |
---|
[245] | 477 | |
---|
[719] | 478 | case "queued": |
---|
| 479 | $sorted[$jobid] = $queued_time; |
---|
| 480 | break; |
---|
[117] | 481 | |
---|
[719] | 482 | case "start": |
---|
| 483 | $sorted[$jobid] = $start_time; |
---|
| 484 | break; |
---|
[117] | 485 | |
---|
[719] | 486 | case "runningtime": |
---|
| 487 | $sorted[$jobid] = $runningtime; |
---|
| 488 | break; |
---|
[117] | 489 | |
---|
[719] | 490 | default: |
---|
| 491 | break; |
---|
| 492 | } |
---|
| 493 | } |
---|
| 494 | } |
---|
[301] | 495 | |
---|
[719] | 496 | if( $sortorder == "asc" ) |
---|
| 497 | { |
---|
| 498 | arsort( $sorted ); |
---|
| 499 | } |
---|
| 500 | else if( $sortorder == "desc" ) |
---|
| 501 | { |
---|
| 502 | asort( $sorted ); |
---|
| 503 | } |
---|
[117] | 504 | |
---|
[719] | 505 | return $sorted; |
---|
[117] | 506 | } |
---|
| 507 | |
---|
[328] | 508 | function makeOverview() |
---|
| 509 | { |
---|
[753] | 510 | global $dwoo, $tpl, $tpl_data, $jobs, $nodes, $heartbeat, $clustername, $tpl_data; |
---|
[719] | 511 | global $sortorder, $sortby, $filter, $sh, $hc, $m, $range; |
---|
| 512 | global $cluster_url, $get_metric_string, $host_url, $metrics; |
---|
| 513 | global $start, $end, $reports, $gnodes, $default_showhosts; |
---|
| 514 | global $COLUMN_QUEUED, $COLUMN_REQUESTED_MEMORY, $COLUMN_NODES, $hostname; |
---|
| 515 | global $cluster, $use_fqdn; |
---|
[126] | 516 | |
---|
[719] | 517 | $metricname = $m; |
---|
[731] | 518 | if( isset($conf['default_metric']) and ($metricname =='') ) |
---|
| 519 | $metricname = $conf['default_metric']; |
---|
| 520 | else |
---|
| 521 | if( isset( $m ) ) |
---|
| 522 | $metricname = $m; |
---|
| 523 | else |
---|
| 524 | $metricname = "load_one"; |
---|
[328] | 525 | |
---|
[753] | 526 | $tpl_data->assign("sortorder", $sortorder ); |
---|
| 527 | $tpl_data->assign("sortby", $sortby ); |
---|
[117] | 528 | |
---|
[732] | 529 | $sorted_jobs = sortJobs( $jobs, $sortby, $sortorder ); |
---|
[117] | 530 | |
---|
[732] | 531 | $even = 1; |
---|
[118] | 532 | |
---|
[732] | 533 | $used_jobs = 0; |
---|
| 534 | $used_cpus = 0; |
---|
[719] | 535 | $used_nodes = 0; |
---|
[124] | 536 | |
---|
[732] | 537 | $queued_jobs = 0; |
---|
| 538 | $queued_nodes = 0; |
---|
| 539 | $queued_cpus = 0; |
---|
[208] | 540 | |
---|
[732] | 541 | $total_nodes = 0; |
---|
[719] | 542 | $total_cpus = 0; |
---|
| 543 | $total_jobs = 0; |
---|
[208] | 544 | |
---|
[719] | 545 | $all_used_nodes = array(); |
---|
[732] | 546 | $total_used_nodes = array(); |
---|
[124] | 547 | |
---|
[732] | 548 | $running_name_nodes = array(); |
---|
[208] | 549 | |
---|
[732] | 550 | $running_nodes = 0; |
---|
| 551 | $running_jobs = 0; |
---|
| 552 | $running_cpus = 0; |
---|
[208] | 553 | |
---|
[732] | 554 | $avail_nodes = count( $gnodes ); |
---|
[719] | 555 | $avail_cpus = cluster_sum("cpu_num", $metrics); |
---|
[135] | 556 | |
---|
[732] | 557 | $view_cpus = 0; |
---|
| 558 | $view_jobs = 0; |
---|
[719] | 559 | $view_nodes = 0; |
---|
[135] | 560 | |
---|
[732] | 561 | $all_nodes = 0; |
---|
| 562 | $all_jobs = 0; |
---|
| 563 | $all_cpus = 0; |
---|
[135] | 564 | |
---|
[732] | 565 | $view_name_nodes = array(); |
---|
[208] | 566 | |
---|
[719] | 567 | // Is the "requested memory" column enabled in the config |
---|
| 568 | // |
---|
| 569 | if( $COLUMN_REQUESTED_MEMORY ) |
---|
| 570 | { |
---|
[753] | 571 | $tpl_data->assign( "column_header_req_mem", "yes" ); |
---|
[719] | 572 | } |
---|
[241] | 573 | |
---|
[719] | 574 | // Is the "nodes hostnames" column enabled in the config |
---|
| 575 | // |
---|
| 576 | if( $COLUMN_NODES ) |
---|
| 577 | { |
---|
[753] | 578 | $tpl_data->assign( "column_header_nodes", "yes" ); |
---|
[719] | 579 | } |
---|
[299] | 580 | |
---|
[719] | 581 | // Is the "queued time" column enabled in the config |
---|
| 582 | // |
---|
| 583 | if( $COLUMN_QUEUED ) |
---|
| 584 | { |
---|
[753] | 585 | $tpl_data->assign( "column_header_queued", "yes" ); |
---|
[719] | 586 | } |
---|
[242] | 587 | |
---|
[732] | 588 | $last_displayed_job = null; |
---|
[263] | 589 | |
---|
[732] | 590 | $rjqj_host = null; |
---|
[406] | 591 | |
---|
[732] | 592 | $na_nodes = 0; |
---|
| 593 | $na_cpus = 0; |
---|
[512] | 594 | |
---|
[719] | 595 | foreach( $metrics as $bhost => $bmetric ) |
---|
| 596 | { |
---|
| 597 | foreach( $bmetric as $mname => $mval ) |
---|
| 598 | { |
---|
[726] | 599 | if( ( $mname == 'zplugin_monarch_rj' ) || ($mname == 'zplugin_monarch_qj') ) |
---|
[719] | 600 | { |
---|
[732] | 601 | $rjqj_host = $bhost; |
---|
[719] | 602 | } |
---|
| 603 | } |
---|
| 604 | } |
---|
[409] | 605 | |
---|
[719] | 606 | foreach( $gnodes as $ghost => $gnode ) |
---|
| 607 | { |
---|
| 608 | if( $gnode->isDown() || $gnode->isOffline() ) |
---|
| 609 | { |
---|
[732] | 610 | $na_nodes += 1; |
---|
| 611 | $na_cpus += $metrics[$ghost]['cpu_num']['VAL']; |
---|
[719] | 612 | } |
---|
| 613 | } |
---|
[516] | 614 | |
---|
[753] | 615 | $node_list = array(); |
---|
[409] | 616 | |
---|
[719] | 617 | foreach( $sorted_jobs as $jobid => $sortdec ) |
---|
| 618 | { |
---|
| 619 | $report_time = $jobs[$jobid]['reported']; |
---|
[117] | 620 | |
---|
[719] | 621 | if( $jobs[$jobid]['status'] == 'R' ) |
---|
| 622 | { |
---|
| 623 | $nodes = count( $jobs[$jobid]['nodes'] ); |
---|
| 624 | } |
---|
| 625 | else if( $jobs[$jobid]['status'] == 'Q' ) |
---|
| 626 | { |
---|
| 627 | $nodes = $jobs[$jobid]['nodes']; |
---|
| 628 | } |
---|
[208] | 629 | |
---|
[732] | 630 | $ppn = isset( $jobs[$jobid]['ppn'] ) ? $jobs[$jobid]['ppn'] : 1; |
---|
| 631 | $cpus = $nodes * $ppn; |
---|
[124] | 632 | |
---|
[719] | 633 | if( $report_time == $heartbeat ) |
---|
| 634 | { |
---|
| 635 | $display_job = 1; |
---|
[124] | 636 | |
---|
[719] | 637 | if( $jobs[$jobid]['status'] == 'R' ) |
---|
| 638 | { |
---|
| 639 | foreach( $jobs[$jobid]['nodes'] as $tempnode ) |
---|
| 640 | { |
---|
| 641 | $all_used_nodes[] = $tempnode; |
---|
| 642 | } |
---|
| 643 | } |
---|
[208] | 644 | |
---|
[719] | 645 | $used_cpus += $cpus; |
---|
[135] | 646 | |
---|
[719] | 647 | if( $jobs[$jobid]['status'] == 'R' ) |
---|
| 648 | { |
---|
| 649 | $running_cpus += $cpus; |
---|
[328] | 650 | |
---|
[719] | 651 | $running_jobs++; |
---|
[117] | 652 | |
---|
[719] | 653 | $found_node_job = 0; |
---|
[268] | 654 | |
---|
[719] | 655 | foreach( $jobs[$jobid]['nodes'] as $tempnode ) |
---|
| 656 | { |
---|
| 657 | $running_name_nodes[] = $tempnode; |
---|
[263] | 658 | |
---|
[719] | 659 | if( isset( $hostname ) && $hostname != '' ) |
---|
| 660 | { |
---|
| 661 | $domain_len = 0 - strlen( $jobs[$jobid]['domain'] ); |
---|
| 662 | $hostnode = $tempnode; |
---|
[328] | 663 | |
---|
[719] | 664 | if( $use_fqdn == 1) |
---|
| 665 | { |
---|
| 666 | if( substr( $hostnode, $domain_len ) != $jobs[$jobid]['domain'] ) |
---|
| 667 | { |
---|
| 668 | $hostnode = $hostnode. '.'. $jobs[$jobid]['domain']; |
---|
| 669 | } |
---|
| 670 | } |
---|
[263] | 671 | |
---|
[719] | 672 | if( $hostname == $hostnode ) |
---|
| 673 | { |
---|
| 674 | $found_node_job = 1; |
---|
| 675 | $display_job = 1; |
---|
| 676 | } |
---|
| 677 | else if( !$found_node_job ) |
---|
| 678 | { |
---|
| 679 | $display_job = 0; |
---|
| 680 | } |
---|
| 681 | } |
---|
| 682 | } |
---|
| 683 | } |
---|
[117] | 684 | |
---|
[719] | 685 | if( $jobs[$jobid]['status'] == 'Q' ) |
---|
| 686 | { |
---|
| 687 | if( isset( $hostname ) && $hostname != '' ) |
---|
| 688 | { |
---|
| 689 | $display_job = 0; |
---|
| 690 | } |
---|
[263] | 691 | |
---|
[732] | 692 | $queued_cpus += $cpus; |
---|
| 693 | $queued_nodes += $nodes; |
---|
[328] | 694 | |
---|
[719] | 695 | $queued_jobs++; |
---|
| 696 | } |
---|
[208] | 697 | |
---|
[719] | 698 | foreach( $filter as $filtername=>$filtervalue ) |
---|
| 699 | { |
---|
| 700 | if( $filtername == 'id' && $jobid != $filtervalue ) |
---|
| 701 | { |
---|
| 702 | $display_job = 0; |
---|
| 703 | } |
---|
| 704 | else if( $filtername == 'state' && $jobs[$jobid]['status'] != $filtervalue ) |
---|
| 705 | { |
---|
| 706 | $display_job = 0; |
---|
| 707 | } |
---|
| 708 | else if( $filtername == 'queue' && $jobs[$jobid]['queue'] != $filtervalue ) |
---|
| 709 | { |
---|
| 710 | $display_job = 0; |
---|
| 711 | } |
---|
| 712 | else if( $filtername == 'owner' && $jobs[$jobid]['owner'] != $filtervalue ) |
---|
| 713 | { |
---|
| 714 | $display_job = 0; |
---|
| 715 | } |
---|
| 716 | } |
---|
[118] | 717 | |
---|
[753] | 718 | |
---|
[719] | 719 | if( $display_job ) |
---|
| 720 | { |
---|
[753] | 721 | $job_loop = array(); |
---|
| 722 | $job_loop["clustername"] = $clustername; |
---|
[263] | 723 | |
---|
[753] | 724 | $job_loop["id"] = $jobid; |
---|
| 725 | |
---|
[719] | 726 | $last_displayed_job = $jobid; |
---|
[263] | 727 | |
---|
[753] | 728 | $job_loop["state"] = $jobs[$jobid]['status']; |
---|
[240] | 729 | |
---|
[719] | 730 | $fullstate = ''; |
---|
[328] | 731 | |
---|
[719] | 732 | if( $jobs[$jobid]['status'] == 'R' ) |
---|
| 733 | { |
---|
| 734 | $fullstate = "Running"; |
---|
| 735 | } |
---|
| 736 | else if( $jobs[$jobid]['status'] == 'Q' ) |
---|
| 737 | { |
---|
| 738 | $fullstate = "Queued"; |
---|
| 739 | } |
---|
[240] | 740 | |
---|
[753] | 741 | $job_loop["fullstate"] = $fullstate; |
---|
[719] | 742 | |
---|
[753] | 743 | $job_loop["owner"] = $jobs[$jobid]['owner']; |
---|
| 744 | $job_loop["queue"] = $jobs[$jobid]['queue']; |
---|
[240] | 745 | |
---|
[719] | 746 | $fulljobname = $jobs[$jobid]['name']; |
---|
[753] | 747 | $shortjobname = ''; |
---|
[240] | 748 | |
---|
[753] | 749 | $job_loop["fulljobname"] = $fulljobname; |
---|
[240] | 750 | |
---|
[719] | 751 | $fulljobname_fields = explode( ' ', $fulljobname ); |
---|
[311] | 752 | |
---|
[719] | 753 | $capjobname = 0; |
---|
[311] | 754 | |
---|
[719] | 755 | if( strlen( $fulljobname_fields[0] ) > 10 ) |
---|
| 756 | { |
---|
| 757 | $capjobname = 1; |
---|
| 758 | } |
---|
[311] | 759 | |
---|
[719] | 760 | if( $capjobname ) |
---|
| 761 | { |
---|
[753] | 762 | //$tpl_data->assign( "jobname_hint_start", "yes" ); |
---|
| 763 | $job_loop[ "jobname_hint_start" ] = "yes"; |
---|
[240] | 764 | |
---|
[719] | 765 | $shortjobname = substr( $fulljobname, 0, 10 ) . '..'; |
---|
| 766 | } |
---|
| 767 | else |
---|
| 768 | { |
---|
| 769 | $shortjobname = $fulljobname; |
---|
| 770 | } |
---|
| 771 | |
---|
[753] | 772 | $job_loop["name"] = $shortjobname; |
---|
[240] | 773 | |
---|
[719] | 774 | if( $capjobname ) |
---|
| 775 | { |
---|
[753] | 776 | //$tpl_data->assign( "jobname_hint_end", "yes" ); |
---|
| 777 | $job_loop[ "jobname_hint_end" ] = "yes"; |
---|
[719] | 778 | } |
---|
[240] | 779 | |
---|
[719] | 780 | $domain = $jobs[$jobid]['domain']; |
---|
[135] | 781 | |
---|
[753] | 782 | $job_loop["req_cpu"] = makeTime( timeToEpoch( $jobs[$jobid]['requested_time'] ) ); |
---|
[328] | 783 | |
---|
[719] | 784 | if( $COLUMN_REQUESTED_MEMORY ) |
---|
| 785 | { |
---|
[753] | 786 | //$tpl_data->assign( "column_req_mem", "yes" ); |
---|
| 787 | $job_loop[ "column_req_mem" ] = "yes"; |
---|
| 788 | $job_loop["req_memory"] = $jobs[$jobid]['requested_memory']; |
---|
[719] | 789 | } |
---|
[135] | 790 | |
---|
[299] | 791 | |
---|
[719] | 792 | if( $COLUMN_QUEUED ) |
---|
| 793 | { |
---|
[753] | 794 | //$tpl_data->assign( "column_queued", "yes" ); |
---|
| 795 | $job_loop[ "column_queued" ] = "yes"; |
---|
| 796 | $job_loop["queued"] = makeDate( $jobs[$jobid]['queued_timestamp'] ); |
---|
[719] | 797 | } |
---|
| 798 | if( $COLUMN_NODES ) |
---|
| 799 | { |
---|
[753] | 800 | //$tpl_data->assign( "column_nodes", "yes" ); |
---|
| 801 | $job_loop[ "column_nodes" ] = "yes"; |
---|
| 802 | //echo "colum nodes"; |
---|
[719] | 803 | } |
---|
[242] | 804 | |
---|
[732] | 805 | $ppn = isset( $jobs[$jobid]['ppn'] ) ? $jobs[$jobid]['ppn'] : 1; |
---|
| 806 | $cpus = $nodes * $ppn; |
---|
[119] | 807 | |
---|
[753] | 808 | $job_loop["nodes"] = $nodes; |
---|
| 809 | $job_loop["cpus"] = $cpus; |
---|
[328] | 810 | |
---|
[732] | 811 | $start_time= (int) $jobs[$jobid]['start_timestamp']; |
---|
| 812 | $job_start = $start_time; |
---|
[328] | 813 | |
---|
[738] | 814 | |
---|
[732] | 815 | $view_cpus += $cpus; |
---|
[328] | 816 | |
---|
[719] | 817 | $view_jobs++; |
---|
[124] | 818 | |
---|
[719] | 819 | if( $jobs[$jobid]['status'] == 'R' ) |
---|
| 820 | { |
---|
[738] | 821 | if( $rjqj_start == null ) |
---|
| 822 | { |
---|
| 823 | $rjqj_start = $start_time; |
---|
| 824 | } |
---|
| 825 | else if( $start_time < $rjqj_start ) |
---|
| 826 | { |
---|
| 827 | $rjqj_start = $start_time; |
---|
| 828 | } |
---|
| 829 | |
---|
[719] | 830 | foreach( $jobs[$jobid]['nodes'] as $tempnode ) |
---|
| 831 | { |
---|
| 832 | $view_name_nodes[] = $tempnode; |
---|
| 833 | } |
---|
[299] | 834 | |
---|
[719] | 835 | if( $COLUMN_NODES ) |
---|
| 836 | { |
---|
[753] | 837 | //$tpl_data->assign( "column_nodes", "yes" ); |
---|
| 838 | $job_loop[ "column_nodes" ] = "yes"; |
---|
[328] | 839 | |
---|
[719] | 840 | $mynodehosts = array(); |
---|
[328] | 841 | |
---|
[730] | 842 | foreach( $jobs[$jobid]['nodes'] as $shortnode ) |
---|
[719] | 843 | { |
---|
| 844 | if( $use_fqdn == 1) |
---|
| 845 | { |
---|
[732] | 846 | $mynode = $shortnode.".".$jobs[$jobid]['domain']; |
---|
[719] | 847 | } |
---|
[732] | 848 | $myhost_href = "./?c=".$clustername."&h=".$mynode; |
---|
| 849 | $mynodehosts[] = "<A HREF=\"".$myhost_href."\">".$shortnode."</A>"; |
---|
[719] | 850 | } |
---|
[328] | 851 | |
---|
[732] | 852 | $nodes_hostnames = implode( " ", $mynodehosts ); |
---|
[328] | 853 | |
---|
[753] | 854 | $job_loop["nodes_hostnames"] = $nodes_hostnames; |
---|
[719] | 855 | } |
---|
| 856 | } |
---|
| 857 | else if( $jobs[$jobid]['status'] == 'Q' ) |
---|
| 858 | { |
---|
| 859 | $view_nodes += (int) $jobs[$jobid]['nodes']; |
---|
| 860 | } |
---|
[135] | 861 | |
---|
[719] | 862 | if( $even ) |
---|
| 863 | { |
---|
[753] | 864 | $job_loop["nodeclass"] = "even"; |
---|
[119] | 865 | |
---|
[719] | 866 | $even = 0; |
---|
| 867 | } |
---|
| 868 | else |
---|
| 869 | { |
---|
[753] | 870 | $job_loop["nodeclass"] = "odd"; |
---|
[119] | 871 | |
---|
[719] | 872 | $even = 1; |
---|
| 873 | } |
---|
[119] | 874 | |
---|
[719] | 875 | if( $start_time ) |
---|
| 876 | { |
---|
[732] | 877 | $runningtime = makeTime( $report_time - $start_time ); |
---|
[719] | 878 | $job_runningtime = $heartbeat - $start_time; |
---|
[119] | 879 | |
---|
[753] | 880 | $job_loop["started"] = makeDate( $start_time ); |
---|
| 881 | $job_loop["runningtime"] = $runningtime; |
---|
[719] | 882 | } |
---|
[753] | 883 | $node_list[] = $job_loop; |
---|
[719] | 884 | } |
---|
[753] | 885 | $tpl_data->assign("node_list", $node_list ); |
---|
[719] | 886 | } |
---|
| 887 | } |
---|
[738] | 888 | // Running / queued amount jobs graph |
---|
| 889 | // |
---|
| 890 | if( $rjqj_host != null ) |
---|
| 891 | { |
---|
| 892 | $rjqj_graphargs = "?z=medium&c=$clustername&g=job_report&r=$range"; |
---|
| 893 | if( $range == 'job' ) |
---|
| 894 | { |
---|
| 895 | $rjqj_end = time(); |
---|
| 896 | $rjqj_graphargs .= "&period_start=$rjqj_start&period_stop=$rjqj_end"; |
---|
| 897 | } |
---|
| 898 | else |
---|
| 899 | { |
---|
| 900 | $rjqj_graphargs .= "&st=$cluster[LOCALTIME]"; |
---|
| 901 | } |
---|
[208] | 902 | |
---|
[738] | 903 | $rjqj_str = "<A HREF=\"./graph.php$rjqj_graphargs\">"; |
---|
[741] | 904 | $rjqj_str .= "<IMG BORDER=0 SRC=\"./graph.php$rjqj_graphargs\" WIDTH=381 HEIGHT=137>"; |
---|
[738] | 905 | $rjqj_str .= "</A>"; |
---|
| 906 | |
---|
[753] | 907 | $tpl_data->assign( "rjqj_graph", $rjqj_str ); |
---|
[738] | 908 | } |
---|
| 909 | |
---|
[719] | 910 | $all_used_nodes = array_unique( $all_used_nodes ); |
---|
[732] | 911 | $view_name_nodes = array_unique( $view_name_nodes ); |
---|
| 912 | $running_name_nodes = array_unique( $running_name_nodes ); |
---|
[124] | 913 | |
---|
[719] | 914 | $used_nodes = count( $all_used_nodes ); |
---|
[732] | 915 | $view_nodes += count( $view_name_nodes ); |
---|
| 916 | $running_nodes += count( $running_name_nodes ); |
---|
[208] | 917 | |
---|
[732] | 918 | $total_nodes = $queued_nodes + $running_nodes; |
---|
[719] | 919 | $total_cpus = $queued_cpus + $running_cpus; |
---|
| 920 | $total_jobs = $queued_jobs + $running_jobs; |
---|
[135] | 921 | |
---|
[719] | 922 | $free_nodes = $avail_nodes - $running_nodes - $na_nodes; |
---|
[732] | 923 | $free_nodes = ( $free_nodes >= 0 ) ? $free_nodes : 0; |
---|
| 924 | $free_cpus = $avail_cpus - $running_cpus - $na_cpus; |
---|
| 925 | $free_cpus = ( $free_cpus >= 0 ) ? $free_cpus : 0; |
---|
[208] | 926 | |
---|
[753] | 927 | $tpl_data->assign( "avail_nodes", $avail_nodes ); |
---|
| 928 | $tpl_data->assign( "avail_cpus", $avail_cpus ); |
---|
[208] | 929 | |
---|
[753] | 930 | $tpl_data->assign( "queued_nodes", $queued_nodes ); |
---|
| 931 | $tpl_data->assign( "queued_jobs", $queued_jobs ); |
---|
| 932 | $tpl_data->assign( "queued_cpus", $queued_cpus ); |
---|
[208] | 933 | |
---|
[719] | 934 | // Only display "Unavailable" in count overview there are any |
---|
| 935 | // |
---|
| 936 | if( $na_nodes > 0 ) |
---|
| 937 | { |
---|
[753] | 938 | $tpl_data->assign( "na_nodes", "yes"); |
---|
[512] | 939 | |
---|
[753] | 940 | $tpl_data->assign( "na_nodes", $na_nodes ); |
---|
| 941 | $tpl_data->assign( "na_cpus", $na_cpus ); |
---|
[719] | 942 | } |
---|
[517] | 943 | |
---|
[753] | 944 | $tpl_data->assign( "total_nodes", $total_nodes ); |
---|
| 945 | $tpl_data->assign( "total_jobs", $total_jobs ); |
---|
| 946 | $tpl_data->assign( "total_cpus", $total_cpus ); |
---|
[135] | 947 | |
---|
[753] | 948 | $tpl_data->assign( "running_nodes", $running_nodes ); |
---|
| 949 | $tpl_data->assign( "running_jobs", $running_jobs ); |
---|
| 950 | $tpl_data->assign( "running_cpus", $running_cpus ); |
---|
[208] | 951 | |
---|
[753] | 952 | $tpl_data->assign( "used_nodes", $used_nodes ); |
---|
| 953 | $tpl_data->assign( "used_jobs", $used_jobs ); |
---|
| 954 | $tpl_data->assign( "used_cpus", $used_cpus ); |
---|
[208] | 955 | |
---|
[753] | 956 | $tpl_data->assign( "free_nodes", $free_nodes ); |
---|
| 957 | $tpl_data->assign( "free_cpus", $free_cpus ); |
---|
[135] | 958 | |
---|
[753] | 959 | $tpl_data->assign( "view_nodes", $view_nodes ); |
---|
| 960 | $tpl_data->assign( "view_jobs", $view_jobs ); |
---|
| 961 | $tpl_data->assign( "view_cpus", $view_cpus ); |
---|
[126] | 962 | |
---|
[753] | 963 | $tpl_data->assign( "report_time", makeDate( $heartbeat) ); |
---|
[328] | 964 | |
---|
[719] | 965 | if( intval($view_jobs) == 1 and $start_time ) |
---|
| 966 | { |
---|
| 967 | if( $last_displayed_job != null ) |
---|
| 968 | { |
---|
| 969 | $filter['id'] = $last_displayed_job; |
---|
| 970 | } |
---|
| 971 | } |
---|
[263] | 972 | |
---|
[719] | 973 | global $longtitle, $title; |
---|
[406] | 974 | |
---|
[719] | 975 | $longtitle = "Batch Report :: Powered by Job Monarch!"; |
---|
| 976 | $title = "Batch Report"; |
---|
[406] | 977 | |
---|
[719] | 978 | makeHeader( 'overview', $title, $longtitle ); |
---|
[406] | 979 | |
---|
[719] | 980 | setupFilterSettings(); |
---|
[263] | 981 | |
---|
[719] | 982 | if( intval($view_jobs) == 1 and $start_time ) |
---|
| 983 | { |
---|
[753] | 984 | $tpl_data->assign( "showhosts", "yes" ); |
---|
[126] | 985 | |
---|
[719] | 986 | # Present a width list |
---|
| 987 | $cols_menu = "<SELECT NAME=\"hc\" OnChange=\"toga_form.submit();\">\n"; |
---|
[126] | 988 | |
---|
[719] | 989 | $hostcols = ($hc) ? $hc : 4; |
---|
[263] | 990 | |
---|
[719] | 991 | foreach( range( 1, 25 ) as $cols ) |
---|
| 992 | { |
---|
| 993 | $cols_menu .= "<OPTION VALUE=$cols "; |
---|
[126] | 994 | |
---|
[719] | 995 | if ($cols == $hostcols) |
---|
| 996 | { |
---|
| 997 | $cols_menu .= "SELECTED"; |
---|
| 998 | } |
---|
| 999 | $cols_menu .= ">$cols\n"; |
---|
| 1000 | } |
---|
| 1001 | $cols_menu .= "</SELECT>\n"; |
---|
[126] | 1002 | |
---|
[753] | 1003 | $tpl_data->assign( "metric","$metricname $units" ); |
---|
| 1004 | $tpl_data->assign( "id", $filter['id'] ); |
---|
[328] | 1005 | |
---|
[719] | 1006 | # Host columns menu defined in header.php |
---|
[753] | 1007 | $tpl_data->assign( "cols_menu", $cols_menu ); |
---|
[126] | 1008 | |
---|
[719] | 1009 | $showhosts = isset($sh) ? $sh : $default_showhosts; |
---|
[126] | 1010 | |
---|
[753] | 1011 | $tpl_data->assign( "checked$showhosts", "checked" ); |
---|
[126] | 1012 | |
---|
[753] | 1013 | $sorted_list = array(); |
---|
| 1014 | |
---|
[719] | 1015 | if( $showhosts ) |
---|
| 1016 | { |
---|
| 1017 | if( !isset( $start ) ) |
---|
| 1018 | { |
---|
| 1019 | $start ="jobstart"; |
---|
| 1020 | } |
---|
| 1021 | if( !isset( $stop ) ) |
---|
| 1022 | { |
---|
| 1023 | $stop ="now"; |
---|
| 1024 | } |
---|
[126] | 1025 | |
---|
[731] | 1026 | $sorted_hosts = array(); |
---|
[719] | 1027 | $hosts_up = $jobs[$filter['id']]['nodes']; |
---|
[126] | 1028 | |
---|
[731] | 1029 | $r = intval($job_runningtime * 1.2); |
---|
[126] | 1030 | |
---|
[719] | 1031 | $jobrange = -$r ; |
---|
| 1032 | $jobstart = $start_time; |
---|
[402] | 1033 | |
---|
[719] | 1034 | if ( $reports[$metricname] ) |
---|
| 1035 | { |
---|
| 1036 | $metricval = "g"; |
---|
| 1037 | } |
---|
| 1038 | else |
---|
| 1039 | { |
---|
| 1040 | $metricval = "m"; |
---|
| 1041 | } |
---|
| 1042 | |
---|
| 1043 | foreach ( $hosts_up as $host ) |
---|
| 1044 | { |
---|
| 1045 | $domain_len = 0 - strlen( $domain ); |
---|
[195] | 1046 | |
---|
[719] | 1047 | if( $use_fqdn ) |
---|
| 1048 | { |
---|
| 1049 | if( substr( $host, $domain_len ) != $domain ) |
---|
| 1050 | { |
---|
| 1051 | $host = $host . '.' . $domain; |
---|
| 1052 | } |
---|
| 1053 | } |
---|
[733] | 1054 | $cpus = 0; |
---|
[328] | 1055 | |
---|
[719] | 1056 | $cpus = $metrics[$host]["cpu_num"]["VAL"]; |
---|
[328] | 1057 | |
---|
[733] | 1058 | if( $cpus == 0 ) |
---|
[719] | 1059 | { |
---|
| 1060 | $cpus = 1; |
---|
| 1061 | } |
---|
[328] | 1062 | |
---|
[719] | 1063 | $load_one = $metrics[$host]["load_one"]['VAL']; |
---|
| 1064 | $load = ((float) $load_one) / $cpus; |
---|
[731] | 1065 | $host_load[$host] = $load; |
---|
[328] | 1066 | |
---|
[719] | 1067 | $percent_hosts[load_color($load)] ++; |
---|
[328] | 1068 | |
---|
[719] | 1069 | if ($metricname=="load_one") |
---|
| 1070 | { |
---|
| 1071 | $sorted_hosts[$host] = $load; |
---|
| 1072 | } |
---|
| 1073 | else |
---|
| 1074 | { |
---|
| 1075 | $sorted_hosts[$host] = $metrics[$host][$metricname]['VAL']; |
---|
| 1076 | } |
---|
| 1077 | } |
---|
[463] | 1078 | |
---|
[719] | 1079 | switch ( $sort ) |
---|
| 1080 | { |
---|
| 1081 | case "descending": |
---|
| 1082 | arsort( $sorted_hosts ); |
---|
| 1083 | break; |
---|
[328] | 1084 | |
---|
[719] | 1085 | case "by hostname": |
---|
| 1086 | ksort( $sorted_hosts ); |
---|
| 1087 | break; |
---|
[328] | 1088 | |
---|
[719] | 1089 | case "ascending": |
---|
| 1090 | asort( $sorted_hosts ); |
---|
| 1091 | break; |
---|
[328] | 1092 | |
---|
[719] | 1093 | default: |
---|
| 1094 | break; |
---|
| 1095 | } |
---|
[126] | 1096 | |
---|
[719] | 1097 | // First pass to find the max value in all graphs for this |
---|
| 1098 | // metric. The $start,$end variables comes from get_context.php, |
---|
| 1099 | // included in index.php. |
---|
| 1100 | // |
---|
| 1101 | list($min, $max) = find_limits($sorted_hosts, $metricname); |
---|
[126] | 1102 | |
---|
[719] | 1103 | // Second pass to output the graphs or metrics. |
---|
| 1104 | $i = 1; |
---|
[126] | 1105 | |
---|
[753] | 1106 | $metric_loop = array(); |
---|
[719] | 1107 | foreach ( $sorted_hosts as $host=>$value ) |
---|
| 1108 | { |
---|
[731] | 1109 | $host_url = rawurlencode( $host ); |
---|
| 1110 | $cluster_url = rawurlencode( $clustername ); |
---|
[193] | 1111 | |
---|
[719] | 1112 | $textval = ""; |
---|
[328] | 1113 | |
---|
[719] | 1114 | $val = $metrics[$host][$metricname]; |
---|
[731] | 1115 | $class = "metric"; |
---|
[328] | 1116 | |
---|
[719] | 1117 | if ( $val["TYPE"] == "timestamp" || $always_timestamp[$metricname] ) |
---|
| 1118 | { |
---|
| 1119 | $textval = date( "r", $val["VAL"] ); |
---|
| 1120 | } |
---|
| 1121 | elseif ( $val["TYPE"] == "string" || $val["SLOPE"] == "zero" || $always_constant[$metricname] || ($max_graphs > 0 and $i > $max_graphs )) |
---|
| 1122 | { |
---|
| 1123 | $textval = $val["VAL"] . " " . $val["UNITS"]; |
---|
| 1124 | } |
---|
| 1125 | else |
---|
| 1126 | { |
---|
[731] | 1127 | $job_start = $jobs[$last_displayed_job]['start_timestamp']; |
---|
| 1128 | $period_end = time(); |
---|
| 1129 | $runningtime = time() - intval( $job_start ); |
---|
[719] | 1130 | $load_color = load_color($host_load[$host]); |
---|
[731] | 1131 | $period_start = intval( $job_start - (intval( $runningtime * 0.10 ) ) ); |
---|
| 1132 | //printf("last job %s job start %s runningtime %s period start %s", $last_displayed_job, $jobstart, $job_runningtime, $period_start); |
---|
[719] | 1133 | $graphargs = ($reports[$metricname]) ? "g=$metricname&" : "m=$metricname&"; |
---|
[739] | 1134 | $graphargs .= "z=overview-medium&c=$cluster_url&r=$range&h=$host_url&l=$load_color&v=".$val['VAL']."&job_start=$job_start"; |
---|
| 1135 | $host_link = "?j_view=overview-host&c=$cluster_url&r=$range&h=$host_url&job_start=$jobstart"; |
---|
| 1136 | |
---|
| 1137 | if( $range == 'job' ) |
---|
| 1138 | { |
---|
| 1139 | $graphargs .= "&period_start=$period_start&period_stop=$period_end"; |
---|
| 1140 | $host_link .= "&period_start=$period_start&period_stop=$period_end"; |
---|
| 1141 | } |
---|
| 1142 | else |
---|
| 1143 | { |
---|
| 1144 | $graphargs .= "&st=$period_end"; |
---|
| 1145 | $host_link .= "&st=$period_end"; |
---|
| 1146 | } |
---|
[719] | 1147 | if( $max > 0 ) |
---|
| 1148 | { |
---|
| 1149 | $graphargs .= "&x=$max&n=$min"; |
---|
| 1150 | } |
---|
| 1151 | } |
---|
| 1152 | if ($textval) |
---|
| 1153 | { |
---|
| 1154 | $cell = "<td class=$class>". "<b><a href=$host_link>$host</a></b><br>". "<i>$metricname:</i> <b>$textval</b></td>"; |
---|
| 1155 | } else { |
---|
[757] | 1156 | $cell = "<A HREF=\"$host_link\">" . "<IMG SRC=\"./graph.php?$graphargs\" " . "ALT=\"$host\" BORDER=0 WIDTH=381 HEIGHT=148></A>"; |
---|
[719] | 1157 | } |
---|
[126] | 1158 | |
---|
[753] | 1159 | $metric_loop["metric_image"] = $cell; |
---|
[328] | 1160 | |
---|
[757] | 1161 | //if(! ($i++ % $hostcols) ) |
---|
| 1162 | //{ |
---|
| 1163 | // $metric_loop["br"] = "</tr><tr>"; |
---|
| 1164 | //} |
---|
[753] | 1165 | $sorted_list[] = $metric_loop; |
---|
[719] | 1166 | } |
---|
[753] | 1167 | $tpl_data->assign("sorted_list", $sorted_list ); |
---|
[719] | 1168 | } |
---|
| 1169 | } |
---|
[753] | 1170 | $dwoo->output($tpl, $tpl_data); |
---|
[114] | 1171 | } |
---|
[753] | 1172 | |
---|
[113] | 1173 | ?> |
---|