[130] | 1 | <?php |
---|
[225] | 2 | /* |
---|
| 3 | * |
---|
| 4 | * This file is part of Jobmonarch |
---|
| 5 | * |
---|
[713] | 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: search.php 880 2013-05-18 16:25:10Z ramonb $ |
---|
[225] | 23 | */ |
---|
[130] | 24 | |
---|
[776] | 25 | include_once "./dwoo/dwooAutoload.php"; |
---|
[130] | 26 | |
---|
[776] | 27 | global $dwoo; |
---|
| 28 | |
---|
| 29 | global $clustername, $m, $metric; |
---|
| 30 | |
---|
[138] | 31 | function validateFormInput() { |
---|
[776] | 32 | global $clustername, $dwoo, $id, $owner, $name, $start_from_time, $start_to_time, $queue; |
---|
| 33 | global $end_from_time, $end_to_time, $period_start, $period_stop, $tpl_data; |
---|
[138] | 34 | |
---|
[778] | 35 | $error = false; |
---|
[716] | 36 | $error_msg = "<FONT COLOR=\"red\"><B>"; |
---|
| 37 | $show_msg = 0; |
---|
[138] | 38 | |
---|
[716] | 39 | $none_set = 0; |
---|
[138] | 40 | |
---|
[716] | 41 | if( $id == '' and $owner== '' and $name == '' and $start_from_time == '' and $start_to_time == '' and $queue == '' and $end_from_time == '' and $end_to_time == '') { |
---|
[778] | 42 | $error = true; |
---|
[716] | 43 | $show_msg = 1; |
---|
| 44 | $error_msg .= "No search criteria set!"; |
---|
| 45 | } |
---|
[138] | 46 | |
---|
[716] | 47 | if( !$error and $period_start != '' ) |
---|
[713] | 48 | { |
---|
[716] | 49 | $pstart_epoch = datetimeToEpoch( $period_start ); |
---|
| 50 | if( $period_stop != '' ) |
---|
[713] | 51 | { |
---|
[157] | 52 | |
---|
[716] | 53 | $pstop_epoch = datetimeToEpoch( $period_stop ); |
---|
[157] | 54 | |
---|
[716] | 55 | if( $pstart_epoch > $pstop_epoch ) { |
---|
[157] | 56 | |
---|
[716] | 57 | $show_msg = 1; |
---|
[778] | 58 | $error = true; |
---|
[716] | 59 | $error_msg .= "Graph timeperiod reset: start date/time can't be later than end"; |
---|
| 60 | $period_stop = ''; |
---|
| 61 | $period_start = ''; |
---|
| 62 | } else if( $pstop_epoch == $pstart_epoch ) { |
---|
[157] | 63 | |
---|
[716] | 64 | $show_msg = 1; |
---|
[778] | 65 | $error = true; |
---|
[716] | 66 | $error_msg .= "Graph timeperiod reset: start and end date/time can't be the same"; |
---|
| 67 | $period_stop = ''; |
---|
| 68 | $period_start = ''; |
---|
| 69 | } |
---|
| 70 | } |
---|
| 71 | } |
---|
[157] | 72 | |
---|
[716] | 73 | $error_msg .= "</B></FONT>"; |
---|
[138] | 74 | |
---|
[778] | 75 | return array( $error_msg, $error); |
---|
[138] | 76 | } |
---|
| 77 | |
---|
[142] | 78 | function datetimeToEpoch( $datetime ) { |
---|
| 79 | |
---|
[716] | 80 | $datetime_fields = explode( ' ', $datetime ); |
---|
[142] | 81 | |
---|
[716] | 82 | $date = $datetime_fields[0]; |
---|
| 83 | $time = $datetime_fields[1]; |
---|
[142] | 84 | |
---|
[716] | 85 | $date_fields = explode( '-', $date ); |
---|
[142] | 86 | |
---|
[716] | 87 | $days = $date_fields[0]; |
---|
| 88 | $months = $date_fields[1]; |
---|
| 89 | $years = $date_fields[2]; |
---|
[142] | 90 | |
---|
[716] | 91 | $time_fields = explode( ':', $time ); |
---|
[142] | 92 | |
---|
[716] | 93 | $hours = $time_fields[0]; |
---|
| 94 | $minutes = $time_fields[1]; |
---|
| 95 | $seconds = $time_fields[2]; |
---|
[142] | 96 | |
---|
[716] | 97 | $timestamp = mktime( $hours, $minutes, $seconds, $months, $days, $years ); |
---|
[142] | 98 | |
---|
[716] | 99 | return $timestamp; |
---|
[142] | 100 | } |
---|
| 101 | |
---|
[141] | 102 | function timeToEpoch( $time ) { |
---|
| 103 | |
---|
| 104 | $time_fields = explode( ':', $time ); |
---|
| 105 | |
---|
| 106 | if( count($time_fields) == 3 ) { |
---|
| 107 | |
---|
| 108 | $hours = $time_fields[0]; |
---|
| 109 | $minutes = $time_fields[1]; |
---|
| 110 | $seconds = $time_fields[2]; |
---|
| 111 | |
---|
| 112 | } else if( count($time_fields) == 2 ) { |
---|
| 113 | |
---|
| 114 | $hours = 0; |
---|
| 115 | $minutes = $time_fields[0]; |
---|
| 116 | $seconds = $time_fields[1]; |
---|
| 117 | |
---|
| 118 | } else if( count($time_fields) == 1 ) { |
---|
| 119 | |
---|
| 120 | $hours = 0; |
---|
| 121 | $minutes = 0; |
---|
| 122 | $seconds = $time_fields[0]; |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | $myepoch = intval( $seconds + (intval( $minutes * 60 )) + (intval( $hours * 3600 )) ); |
---|
| 126 | |
---|
| 127 | return $myepoch; |
---|
| 128 | } |
---|
| 129 | |
---|
[180] | 130 | function sortJobs( $jobs, $nodes, $sortby, $sortorder ) { |
---|
| 131 | |
---|
| 132 | $sorted = array(); |
---|
| 133 | |
---|
| 134 | $cmp = create_function( '$a, $b', |
---|
| 135 | "global \$sortby, \$sortorder;". |
---|
| 136 | |
---|
| 137 | "if( \$a == \$b ) return 0;". |
---|
| 138 | |
---|
| 139 | "if (\$sortorder==\"desc\")". |
---|
| 140 | "return ( \$a < \$b ) ? 1 : -1;". |
---|
| 141 | "else if (\$sortorder==\"asc\")". |
---|
| 142 | "return ( \$a > \$b ) ? 1 : -1;" ); |
---|
| 143 | |
---|
| 144 | foreach( $jobs as $jobid => $jobattrs ) { |
---|
| 145 | |
---|
[712] | 146 | $state = $jobattrs['status']; |
---|
| 147 | $owner = $jobattrs['owner']; |
---|
| 148 | $queue = $jobattrs['queue']; |
---|
| 149 | $name = $jobattrs['name']; |
---|
| 150 | $req_cpu = $jobattrs['requested_time']; |
---|
| 151 | $req_memory = $jobattrs['requested_memory']; |
---|
[180] | 152 | |
---|
[712] | 153 | $mynodes = count( $nodes[$jobid] ); |
---|
[180] | 154 | |
---|
[712] | 155 | $ppn = (int) $jobattrs['ppn'] ? $jobattrs['ppn'] : 1; |
---|
[180] | 156 | $cpus = $mynodes * $ppn; |
---|
[712] | 157 | $start_time = (int) $jobattrs['start_timestamp']; |
---|
| 158 | $stop_time = (int) $jobattrs['stop_timestamp']; |
---|
[180] | 159 | $runningtime = $stop_time - $start_time; |
---|
| 160 | |
---|
| 161 | switch( $sortby ) { |
---|
| 162 | case "id": |
---|
| 163 | $sorted[$jobid] = $jobid; |
---|
| 164 | break; |
---|
| 165 | |
---|
| 166 | case "state": |
---|
| 167 | $sorted[$jobid] = $state; |
---|
| 168 | break; |
---|
| 169 | |
---|
[711] | 170 | case "owner": |
---|
| 171 | $sorted[$jobid] = $owner; |
---|
[180] | 172 | break; |
---|
| 173 | |
---|
| 174 | case "queue": |
---|
| 175 | $sorted[$jobid] = $queue; |
---|
| 176 | break; |
---|
| 177 | |
---|
| 178 | case "name": |
---|
| 179 | $sorted[$jobid] = $name; |
---|
| 180 | break; |
---|
| 181 | |
---|
| 182 | case "req_cpu": |
---|
| 183 | $sorted[$jobid] = timeToEpoch( $req_cpu ); |
---|
| 184 | break; |
---|
| 185 | |
---|
| 186 | case "req_mem": |
---|
| 187 | $sorted[$jobid] = $req_memory; |
---|
| 188 | break; |
---|
| 189 | |
---|
| 190 | case "nodes": |
---|
| 191 | $sorted[$jobid] = $mynodes; |
---|
| 192 | break; |
---|
| 193 | |
---|
| 194 | case "cpus": |
---|
| 195 | $sorted[$jobid] = $cpus; |
---|
| 196 | break; |
---|
| 197 | |
---|
| 198 | case "start": |
---|
| 199 | $sorted[$jobid] = $start_time; |
---|
| 200 | break; |
---|
| 201 | |
---|
[716] | 202 | case "finished": |
---|
| 203 | $sorted[$jobid] = $stop_time; |
---|
| 204 | break; |
---|
[181] | 205 | |
---|
[180] | 206 | case "runningtime": |
---|
| 207 | $sorted[$jobid] = $runningtime; |
---|
| 208 | break; |
---|
| 209 | |
---|
| 210 | default: |
---|
| 211 | break; |
---|
| 212 | |
---|
| 213 | } |
---|
| 214 | } |
---|
| 215 | |
---|
| 216 | if( $sortorder == "asc" ) |
---|
| 217 | arsort( $sorted ); |
---|
| 218 | else if( $sortorder == "desc" ) |
---|
| 219 | asort( $sorted ); |
---|
| 220 | |
---|
| 221 | return array_keys( $sorted ); |
---|
| 222 | } |
---|
| 223 | |
---|
[130] | 224 | function makeSearchPage() { |
---|
[776] | 225 | global $clustername, $dwoo, $id, $owner, $name, $start_from_time, $start_to_time, $queue; |
---|
[716] | 226 | global $end_from_time, $end_to_time, $filter, $default_showhosts, $m, $hosts_up, $hc; |
---|
| 227 | global $period_start, $period_stop, $sortby, $sortorder, $COLUMN_REQUESTED_MEMORY; |
---|
[880] | 228 | global $SEARCH_RESULT_LIMIT, $COLUMN_NODES, $metricname, $self, $conf, $include_running; |
---|
[130] | 229 | |
---|
[880] | 230 | |
---|
[716] | 231 | $longtitle = "Batch Archive Search :: Powered by Job Monarch!"; |
---|
| 232 | $title = "Batch Archive Search"; |
---|
[410] | 233 | |
---|
[716] | 234 | makeHeader( 'search', $title, $longtitle ); |
---|
[410] | 235 | |
---|
[776] | 236 | $tpl = new Dwoo_Template_File("templates/search.tpl"); |
---|
| 237 | $tpl_data = new Dwoo_Data(); |
---|
[138] | 238 | |
---|
[880] | 239 | if( in_array( $include_running, array('on','checked','true','yes') ) ) |
---|
| 240 | { |
---|
| 241 | $include_running = true; |
---|
| 242 | $tpl_data->assign( "running_checked", "checked='on'" ); |
---|
| 243 | } |
---|
[805] | 244 | $tpl_data->assign( "self", $self ); |
---|
[776] | 245 | $tpl_data->assign( "cluster", $clustername ); |
---|
| 246 | $tpl_data->assign( "id_value", $id ); |
---|
| 247 | $tpl_data->assign( "owner_value", $owner); |
---|
| 248 | $tpl_data->assign( "queue_value", $queue ); |
---|
| 249 | $tpl_data->assign( "name_value", $name ); |
---|
| 250 | $tpl_data->assign( "start_from_value", rawurldecode( $start_from_time ) ); |
---|
| 251 | $tpl_data->assign( "start_to_value", rawurldecode( $start_to_time ) ); |
---|
| 252 | $tpl_data->assign( "end_from_value", rawurldecode( $end_from_time ) ); |
---|
| 253 | $tpl_data->assign( "end_to_value", rawurldecode( $end_to_time ) ); |
---|
| 254 | |
---|
[778] | 255 | list( $form_error_msg, $form_error ) = validateFormInput(); |
---|
[138] | 256 | |
---|
[778] | 257 | if( $form_error == true ) |
---|
| 258 | { |
---|
| 259 | $tpl_data->assign( "form_error_msg", $form_error_msg ); |
---|
| 260 | } |
---|
| 261 | else if( $form_error == false ) |
---|
| 262 | { |
---|
[776] | 263 | $tpl_data->assign( "search_results", "yes" ); |
---|
| 264 | $tpl_data->assign( "sortby", $sortby); |
---|
| 265 | $tpl_data->assign( "sortorder", $sortorder); |
---|
[810] | 266 | $tpl_data->assign( "form_name", "archive_search_form" ); |
---|
[716] | 267 | $tdb = new TarchDbase( "127.0.0.1" ); |
---|
| 268 | if( $start_from_time ) $start_from_time = datetimeToEpoch( $start_from_time ); |
---|
| 269 | if( $start_to_time ) $start_to_time = datetimeToEpoch( $start_to_time ); |
---|
| 270 | if( $end_from_time ) $end_from_time = datetimeToEpoch( $end_from_time ); |
---|
| 271 | if( $end_to_time ) $end_to_time = datetimeToEpoch( $end_to_time ); |
---|
[880] | 272 | $search_ids = $tdb->searchDbase( $id, $queue, $owner, $name, $start_from_time, $start_to_time, $end_from_time, $end_to_time, $include_running ); |
---|
[138] | 273 | |
---|
[778] | 274 | //print_r( $search_ids ); |
---|
[716] | 275 | if( ($tdb->resultcount) > (int) $SEARCH_RESULT_LIMIT ) { |
---|
[778] | 276 | |
---|
[776] | 277 | $tpl_data->assign( "form_error_msg", "Got " . $tdb->resultcount . " search results, output limited to last " . $SEARCH_RESULT_LIMIT . " jobs." ); |
---|
[716] | 278 | } |
---|
[248] | 279 | |
---|
[716] | 280 | $jobs = array(); |
---|
| 281 | $nodes = array(); |
---|
[140] | 282 | |
---|
[716] | 283 | $even = 1; |
---|
[237] | 284 | |
---|
[716] | 285 | foreach( $search_ids as $myid ) { |
---|
[180] | 286 | |
---|
[716] | 287 | $jobs[$myid] = $tdb->getJobArray( $myid ); |
---|
| 288 | $nodes[$myid] = $tdb->getNodesForJob( $myid ); |
---|
| 289 | } |
---|
[180] | 290 | |
---|
[716] | 291 | if( $COLUMN_REQUESTED_MEMORY ) { |
---|
[776] | 292 | $tpl_data->assign( "column_header_req_mem", "yes" ); |
---|
[716] | 293 | } |
---|
| 294 | if( $COLUMN_NODES ) { |
---|
[776] | 295 | $tpl_data->assign( "column_header_nodes", "yes" ); |
---|
[716] | 296 | } |
---|
[247] | 297 | |
---|
[716] | 298 | $sorted_search = sortJobs( $jobs, $nodes, $sortby, $sortorder ); |
---|
[180] | 299 | |
---|
[776] | 300 | $node_loop = array(); |
---|
[716] | 301 | foreach( $sorted_search as $sortid ) { |
---|
[180] | 302 | |
---|
[716] | 303 | $job = $jobs[$sortid]; |
---|
| 304 | $foundid = $job['id']; |
---|
[180] | 305 | |
---|
[776] | 306 | $node_list = array(); |
---|
| 307 | $node_list["id"]= $job['id']; |
---|
| 308 | $node_list["state"]= $job['status']; |
---|
| 309 | $node_list["owner"]= $job['owner']; |
---|
| 310 | $node_list["queue"]= $job['queue']; |
---|
| 311 | $node_list["name"]= $job['name']; |
---|
| 312 | $node_list["req_cpu"]= makeTime( TimeToEpoch( $job['requested_time'] ) ); |
---|
[141] | 313 | |
---|
[780] | 314 | if( $COLUMN_REQUESTED_MEMORY ) |
---|
| 315 | { |
---|
[776] | 316 | $node_list["column_req_mem"] = "yes"; |
---|
| 317 | $node_list["req_memory"]= $job['requested_memory']; |
---|
[716] | 318 | } |
---|
[780] | 319 | if( $COLUMN_NODES) |
---|
| 320 | { |
---|
[247] | 321 | |
---|
[716] | 322 | $job_nodes = array(); |
---|
[356] | 323 | |
---|
[716] | 324 | foreach( $nodes[$foundid] as $mynode ) |
---|
[780] | 325 | { |
---|
| 326 | if( strpos( $mynode['hostname'], "." ) !== false ) |
---|
| 327 | { |
---|
| 328 | $shorthost = explode( '.', $mynode['hostname'] ); |
---|
| 329 | $job_nodes[] = $shorthost[0]; |
---|
| 330 | } |
---|
| 331 | else |
---|
| 332 | { |
---|
| 333 | $job_nodes[] = $mynode['hostname']; |
---|
| 334 | } |
---|
| 335 | } |
---|
[299] | 336 | |
---|
[780] | 337 | $node_list["column_nodes_hostnames"] = "yes"; |
---|
[716] | 338 | $nodes_hostnames = implode( " ", $job_nodes ); |
---|
[776] | 339 | $node_list["nodes_hostnames"]= $nodes_hostnames; |
---|
[716] | 340 | } |
---|
[299] | 341 | |
---|
[716] | 342 | $nodes_nr = count( $nodes[$foundid] ); |
---|
[145] | 343 | |
---|
[716] | 344 | if( $even ) { |
---|
[237] | 345 | |
---|
[776] | 346 | $node_list["nodeclass"]= "even"; |
---|
[716] | 347 | $even = 0; |
---|
| 348 | } else { |
---|
[237] | 349 | |
---|
[776] | 350 | $node_list["nodeclass"]= "odd"; |
---|
[716] | 351 | $even = 1; |
---|
| 352 | } |
---|
[237] | 353 | |
---|
[716] | 354 | $ppn = (int) $job['ppn'] ? $job['ppn'] : 1; |
---|
| 355 | $cpus = $nodes_nr * $ppn; |
---|
[141] | 356 | |
---|
[776] | 357 | $node_list["nodes"]= $nodes_nr; |
---|
| 358 | $node_list["cpus"]= $cpus; |
---|
[141] | 359 | |
---|
[716] | 360 | $job_start = $job['start_timestamp']; |
---|
| 361 | $job_stop = $job['stop_timestamp']; |
---|
[880] | 362 | |
---|
| 363 | if( $job['status'] == 'R' ) |
---|
| 364 | { |
---|
| 365 | $period_stop = time(); |
---|
| 366 | $runningtime = $period_stop - intval( $job_start ); |
---|
| 367 | $period_start = intval( $job_start - (intval( $runningtime * 0.10 ) ) ); |
---|
| 368 | $node_list["finished"]= ''; |
---|
| 369 | } |
---|
| 370 | else |
---|
| 371 | { |
---|
| 372 | $runningtime = intval( $job_stop - $job_start ); |
---|
| 373 | $node_list["finished"]= makeDate( $job_stop ); |
---|
| 374 | } |
---|
| 375 | |
---|
[776] | 376 | $node_list["started"]= makeDate( $job_start ); |
---|
| 377 | $node_list["runningtime"]= makeTime( $runningtime ); |
---|
[716] | 378 | |
---|
[776] | 379 | $node_loop[]=$node_list; |
---|
[716] | 380 | } |
---|
[778] | 381 | //print_r( $node_loop ); |
---|
| 382 | $tpl_data->assign("node_list", $node_loop ); |
---|
[140] | 383 | |
---|
[716] | 384 | if( count( $search_ids ) == 1 ) { |
---|
[140] | 385 | |
---|
[776] | 386 | $tpl_data->assign( "showhosts", "yes" ); |
---|
[143] | 387 | |
---|
[716] | 388 | $showhosts = isset($sh) ? $sh : $default_showhosts; |
---|
[776] | 389 | $tpl_data->assign("checked$showhosts", "checked"); |
---|
[143] | 390 | |
---|
[880] | 391 | if( $showhosts ) |
---|
| 392 | { |
---|
| 393 | if( $job['status'] == 'R' ) |
---|
| 394 | { |
---|
| 395 | $period_stop = time(); |
---|
| 396 | $runningtime = $period_stop - intval( $job_start ); |
---|
[716] | 397 | $period_start = intval( $job_start - (intval( $runningtime * 0.10 ) ) ); |
---|
[880] | 398 | } |
---|
[716] | 399 | else |
---|
[880] | 400 | { |
---|
| 401 | if( !$period_start ) // Add an extra 10% to graphstart |
---|
| 402 | { |
---|
| 403 | $period_start = intval( $job_start - (intval( $runningtime * 0.10 ) ) ); |
---|
| 404 | } |
---|
| 405 | else |
---|
| 406 | { |
---|
| 407 | $period_start = datetimeToEpoch( $period_start ); |
---|
| 408 | } |
---|
[143] | 409 | |
---|
[880] | 410 | if( !$period_stop ) // Add an extra 10% to graphend |
---|
| 411 | { |
---|
| 412 | $period_stop = intval( $job_stop + (intval( $runningtime * 0.10 ) ) ); |
---|
| 413 | } |
---|
| 414 | else |
---|
| 415 | { |
---|
| 416 | $period_stop = datetimeToEpoch( $period_stop ); |
---|
| 417 | } |
---|
| 418 | } |
---|
[143] | 419 | |
---|
[880] | 420 | |
---|
[780] | 421 | $tpl_data->assign( "timeperiod", "yes" ); |
---|
[189] | 422 | |
---|
[780] | 423 | $tpl_data->assign("period_start", epochToDatetime( $period_start ) ); |
---|
| 424 | $tpl_data->assign("period_stop", epochToDatetime( $period_stop ) ); |
---|
[143] | 425 | |
---|
[716] | 426 | $hosts_up = array(); |
---|
[145] | 427 | |
---|
[716] | 428 | foreach( $nodes[$id] as $mynode ) |
---|
| 429 | $hosts_up[] = $mynode['hostname']; |
---|
[145] | 430 | |
---|
[716] | 431 | $sorted_hosts = array(); |
---|
[145] | 432 | |
---|
[716] | 433 | foreach ($hosts_up as $host ) { |
---|
| 434 | $cpus = $metrics[$host]["cpu_num"]['VAL']; |
---|
| 435 | if (!$cpus) $cpus=1; |
---|
| 436 | $load_one = $metrics[$host]["load_one"]['VAL']; |
---|
| 437 | $load = ((float) $load_one)/$cpus; |
---|
| 438 | $host_load[$host] = $load; |
---|
| 439 | $percent_hosts['load_color'.($load)] += 1; |
---|
| 440 | if ($metricname=="load_one") |
---|
| 441 | $sorted_hosts[$host] = $load; |
---|
| 442 | else |
---|
| 443 | $sorted_hosts[$host] = $metrics[$host][$metricname]['VAL']; |
---|
| 444 | } |
---|
| 445 | switch ($sort) { |
---|
| 446 | case "descending": |
---|
| 447 | arsort($sorted_hosts); |
---|
| 448 | break; |
---|
| 449 | case "by hostname": |
---|
| 450 | ksort($sorted_hosts); |
---|
| 451 | break; |
---|
| 452 | default: |
---|
| 453 | case "ascending": |
---|
| 454 | asort($sorted_hosts); |
---|
| 455 | break; |
---|
| 456 | } |
---|
[143] | 457 | |
---|
[811] | 458 | $trd = new TarchRrdGraph( $clustername, $host ); |
---|
| 459 | $rrd_dirs = $trd->getRrdDirs( $period_start, $period_stop ); |
---|
| 460 | |
---|
| 461 | $metric_menu = "<B>Metric</B> " |
---|
| 462 | ."<SELECT NAME=\"m\" OnChange=\"toga_form.submit();\">\n"; |
---|
| 463 | |
---|
| 464 | $archive_reports = array( "load_report", "cpu_report", "network_report", "packet_report", "mem_report" ); |
---|
| 465 | $file_metrics = $trd->dirList( $rrd_dirs[0] ); |
---|
| 466 | |
---|
| 467 | $archive_metrics = array(); |
---|
| 468 | |
---|
| 469 | foreach( $file_metrics as $k ) |
---|
| 470 | { |
---|
| 471 | $a_metric_file = explode( '.', $k); |
---|
| 472 | $archive_metrics[] = $a_metric_file[0]; |
---|
| 473 | } |
---|
| 474 | |
---|
| 475 | $sorted_metrics = array_merge( $archive_reports, $archive_metrics ); |
---|
| 476 | |
---|
| 477 | asort( $sorted_metrics ); |
---|
| 478 | |
---|
| 479 | $selected_metric = $conf['default_metric']; |
---|
| 480 | |
---|
| 481 | if( $metricname != '') |
---|
| 482 | { |
---|
| 483 | $selected_metric = $metricname; |
---|
| 484 | } |
---|
| 485 | |
---|
| 486 | foreach( $sorted_metrics as $k ) |
---|
| 487 | { |
---|
| 488 | $url = rawurlencode($k); |
---|
| 489 | $metric_menu .= "<OPTION VALUE=\"$url\" "; |
---|
| 490 | if ($k == $selected_metric ) |
---|
| 491 | $metric_menu .= "SELECTED"; |
---|
| 492 | $metric_menu .= ">$k\n"; |
---|
| 493 | } |
---|
| 494 | $metric_menu .= "</SELECT>\n"; |
---|
| 495 | |
---|
| 496 | $tpl_data->assign("metric_menu", $metric_menu ); |
---|
| 497 | |
---|
[716] | 498 | # First pass to find the max value in all graphs for this |
---|
| 499 | # metric. The $start,$end variables comes from get_context.php, |
---|
| 500 | # included in index.php. |
---|
[817] | 501 | #list($min, $max) = find_limits($sorted_hosts, $metricname); |
---|
[143] | 502 | |
---|
[776] | 503 | $sorted_loop = array(); |
---|
[716] | 504 | # Second pass to output the graphs or metrics. |
---|
| 505 | $i = 1; |
---|
| 506 | foreach ( $sorted_hosts as $host=>$value ) { |
---|
[776] | 507 | $sorted_list = array(); |
---|
[716] | 508 | $host_url = rawurlencode($host); |
---|
| 509 | $cluster_url = rawurlencode($clustername); |
---|
[143] | 510 | |
---|
[716] | 511 | $textval = ""; |
---|
| 512 | $val = $metrics[$host][$metricname]; |
---|
| 513 | $class = "metric"; |
---|
[805] | 514 | $host_link="\"?j_view=host&self=$self&c=$cluster_url&h=$host_url&job_start=$job_start&job_stop=$job_stop&period_start=$period_start&period_stop=$period_stop\""; |
---|
[143] | 515 | |
---|
[716] | 516 | if ($val['TYPE']=="timestamp" or $always_timestamp[$metricname]) { |
---|
| 517 | $textval = date("r", $val['VAL']); |
---|
| 518 | } elseif ($val['TYPE']=="string" or $val['SLOPE']=="zero" or $always_constant[$metricname] or ($max_graphs > 0 and $i > $max_graphs )) { |
---|
[776] | 519 | $textval = $val['VAL']." ".$val['UNITS']; |
---|
[716] | 520 | } else { |
---|
[817] | 521 | $graphargs = "z=medium&c=$cluster_url&m=$metricname&h=$host_url&v=".$val['VAL']."&job_start=$job_start&job_stop=$job_stop&period_start=$period_start&period_stop=$period_stop"; |
---|
[716] | 522 | } |
---|
| 523 | if ($textval) { |
---|
| 524 | $cell="<td class=$class>". "<b><a href=$host_link>$host</a></b><br>". "<i>$metricname:</i> <b>$textval</b></td>"; |
---|
| 525 | } else { |
---|
| 526 | $cell="<td><a href=$host_link>". "<img src=\"./graph.php?$graphargs\" ". "alt=\"$host\" border=0></a></td>"; |
---|
| 527 | } |
---|
[143] | 528 | |
---|
[776] | 529 | $sorted_list["metric_image"]= $cell; |
---|
[716] | 530 | if (! ($i++ % $hostcols) ) |
---|
[776] | 531 | $sorted_list["br"]= "</tr><tr>"; |
---|
| 532 | |
---|
| 533 | $sorted_loop[]=$sorted_list; |
---|
[716] | 534 | } |
---|
[778] | 535 | $tpl_data->assign("sorted_list", $sorted_loop ); |
---|
[716] | 536 | } |
---|
| 537 | } |
---|
[140] | 538 | |
---|
[716] | 539 | } |
---|
[776] | 540 | $dwoo->output($tpl, $tpl_data); |
---|
[130] | 541 | } |
---|
| 542 | ?> |
---|