Changeset 732


Ignore:
Timestamp:
03/24/13 14:00:01 (11 years ago)
Author:
ramonb
Message:
  • cleanup
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/0.4/web/addons/job_monarch/overview.php

    r731 r732  
    44 * This file is part of Jobmonarch
    55 *
    6  * Copyright (C) 2006  Ramon Bastiaans
     6 * Copyright (C) 2006-2013  Ramon Bastiaans
    77 *
    88 * Jobmonarch is free software; you can redistribute it and/or modify
     
    3434}
    3535
    36 $ds        = new DataSource();
    37 $myxml_data    = $ds->getData();
    38 
    39 $data_gatherer    = new DataGatherer( $clustername );
     36$ds         = new DataSource();
     37$myxml_data = $ds->getData();
     38
     39$data_gatherer = new DataGatherer( $clustername );
    4040$data_gatherer->parseXML( $myxml_data );
    4141
    42 $heartbeat    = $data_gatherer->getHeartbeat();
    43 $jobs        = $data_gatherer->getJobs();
    44 $gnodes        = $data_gatherer->getNodes();
    45 $cpus        = $data_gatherer->getCpus();
    46 $use_fqdn    = $data_gatherer->getUsingFQDN();
     42$heartbeat = $data_gatherer->getHeartbeat();
     43$jobs      = $data_gatherer->getJobs();
     44$gnodes    = $data_gatherer->getNodes();
     45$cpus      = $data_gatherer->getCpus();
     46$use_fqdn  = $data_gatherer->getUsingFQDN();
    4747
    4848function setupFilterSettings()
     
    6565
    6666    unset( $_SESSION["data"] );
    67     $_SESSION["data"]    = &$myxml_data;
    68 
    69     $ic            = new ClusterImage( $myxml_data, $clustername );
     67    $_SESSION["data"] = &$myxml_data;
     68
     69    $ic = new ClusterImage( $myxml_data, $clustername );
    7070
    7171    $ic->setBig();
     
    101101function timeToEpoch( $time )
    102102{
    103     $time_fields    = explode( ':', $time );
     103    $time_fields = explode( ':', $time );
    104104
    105105    if( count( $time_fields ) == 3 )
    106106    {
    107         $hours        = $time_fields[0];
    108         $minutes    = $time_fields[1];
    109         $seconds    = $time_fields[2];
     107        $hours   = $time_fields[0];
     108        $minutes = $time_fields[1];
     109        $seconds = $time_fields[2];
    110110
    111111    }
    112112    else if( count( $time_fields ) == 2 )
    113113    {
    114         $hours         = 0;
    115         $minutes     = $time_fields[0];
    116         $seconds     = $time_fields[1];
     114        $hours   = 0;
     115        $minutes = $time_fields[0];
     116        $seconds = $time_fields[1];
    117117
    118118    }
    119119    else if( count( $time_fields ) == 1 )
    120120    {
    121         $hours         = 0;
    122         $minutes     = 0;
    123         $seconds     = $time_fields[0];
    124     }
    125 
    126     $myepoch     = intval( $seconds + (intval( $minutes * 60 )) + (intval( $hours * 3600 )) );
     121        $hours   = 0;
     122        $minutes = 0;
     123        $seconds = $time_fields[0];
     124    }
     125
     126    $myepoch = intval( $seconds + (intval( $minutes * 60 )) + (intval( $hours * 3600 )) );
    127127
    128128    return $myepoch;
     
    149149    $min_diff = 50;
    150150
    151     $c1r     = hexDec( colorRed( $first ) );
    152     $c1g     = hexDec( colorGreen( $first ) );
    153     $c1b     = hexDec( colorBlue( $first ) );
    154 
    155     $c2r     = hexDec( colorRed( $second ) );
    156     $c2g     = hexDec( colorGreen( $second ) );
    157     $c2b     = hexDec( colorBlue( $second ) );
    158 
    159     $rdiff     = ($c1r >= $c2r) ? $c1r - $c2r : $c2r - $c1r;
    160     $gdiff     = ($c1g >= $c2g) ? $c1g - $c2g : $c2g - $c1g;
    161     $bdiff     = ($c1b >= $c2b) ? $c1b - $c2b : $c2b - $c1b;
     151    $c1r   = hexDec( colorRed( $first ) );
     152    $c1g   = hexDec( colorGreen( $first ) );
     153    $c1b   = hexDec( colorBlue( $first ) );
     154
     155    $c2r   = hexDec( colorRed( $second ) );
     156    $c2g   = hexDec( colorGreen( $second ) );
     157    $c2b   = hexDec( colorBlue( $second ) );
     158
     159    $rdiff = ($c1r >= $c2r) ? $c1r - $c2r : $c2r - $c1r;
     160    $gdiff = ($c1g >= $c2g) ? $c1g - $c2g : $c2g - $c1g;
     161    $bdiff = ($c1b >= $c2b) ? $c1b - $c2b : $c2b - $c1b;
    162162
    163163    if( $rdiff >= $min_diff or $gdiff >= $min_diff or $bdiff >= $min_diff )
     
    175175{
    176176    // White (000000) would be invisible
    177     $start        = "004E00";
     177    $start       = "004E00";
    178178   
    179     $start_red    = colorRed( $start );
    180     $start_green    = colorGreen( $start );
    181     $start_blue    = colorBlue( $start );
     179    $start_red   = colorRed( $start );
     180    $start_green = colorGreen( $start );
     181    $start_blue  = colorBlue( $start );
    182182   
    183     $end        = "FFFFFF";
    184 
    185     $end_red    = colorRed( $end );
    186     $end_green    = colorGreen( $end );
     183    $end         = "FFFFFF";
     184
     185    $end_red     = colorRed( $end );
     186    $end_green   = colorGreen( $end );
    187187    $end_blue    = colorBlue( $end );
    188188
    189     $change_color     = TRUE;
     189    $change_color= TRUE;
    190190
    191191    while( $change_color )
    192192    {
    193         $change_color    = FALSE;
     193        $change_color= FALSE;
    194194
    195195        $new_red     = rand( hexDec( $start_red ), hexDec( $end_red ) );
    196         $new_green     = rand( hexDec( $start_green ), hexDec( $end_green ) );
    197         $new_blue     = rand( hexDec( $start_blue ), hexDec( $end_blue ) );
     196        $new_green   = rand( hexDec( $start_green ), hexDec( $end_green ) );
     197        $new_blue    = rand( hexDec( $start_blue ), hexDec( $end_blue ) );
    198198
    199199        $new         = decHex( $new_red ) . decHex( $new_green ) . decHex( $new_blue );
     
    219219function drawQueuePie() { }
    220220
    221 
    222221function drawPie()
    223222{
    224223    global $jobs, $gnodes, $piefilter, $filter, $metrics;
    225224
    226     $nodes         = $gnodes;
     225    $nodes = $gnodes;
    227226
    228227    if( isset($piefilter) )   
    229228    {
    230         $pie_args    = "title=" . rawurlencode("Cluster ".$piefilter." usage");
     229        $pie_args = "title=" . rawurlencode("Cluster ".$piefilter." usage");
    231230    }
    232231    else
    233232    {
    234         $pie_args     = "title=" . rawurlencode("Cluster queue usage");
    235     }
    236 
    237     $pie_args     .= "&size=250x150";
    238 
    239     $queues     = array();
    240     $nr_jobs     = count( $jobs );
    241     $nr_nodes     = count( $nodes );
    242 
    243     $nr_cpus     = cluster_sum("cpu_num", $metrics);
    244 
    245     $empty_cpus     = 0;
    246     $used_cpus     = 0;
    247 
    248     $job_weight     = array();
     233        $pie_args = "title=" . rawurlencode("Cluster queue usage");
     234    }
     235
     236    $pie_args .= "&size=250x150";
     237
     238    $queues    = array();
     239    $nr_jobs   = count( $jobs );
     240    $nr_nodes  = count( $nodes );
     241
     242    $nr_cpus   = cluster_sum("cpu_num", $metrics);
     243
     244    $empty_cpus= 0;
     245    $used_cpus = 0;
     246
     247    $job_weight= array();
    249248
    250249    foreach( $nodes as $node )
    251250    {
    252         $myjobs        = $node->getJobs();
    253         $myhost        = $node->getHostname();
    254         $node_cpus    = $metrics[$myhost]["cpu_num"]['VAL'];
    255         $job_cpu    = 0;
     251        $myjobs    = $node->getJobs();
     252        $myhost    = $node->getHostname();
     253        $node_cpus = $metrics[$myhost]["cpu_num"]['VAL'];
     254        $job_cpu   = 0;
    256255
    257256        foreach( $myjobs as $myjob )
    258257        {
    259             $job_cpu    += isset( $jobs[$myjob]['ppn'] ) ? $jobs[$myjob]['ppn'] : 1;
     258            $job_cpu += isset( $jobs[$myjob]['ppn'] ) ? $jobs[$myjob]['ppn'] : 1;
    260259        }
    261260
    262         $node_freecpu    = $node_cpus - $job_cpu;
    263 
    264         $empty_cpus    += $node_freecpu;
    265     }
    266 
    267     $empty_cpus        = ( $empty_cpus >= 0 ) ? $empty_cpus : 0;
    268     $used_cpus        = $nr_cpus - $empty_cpus;
    269 
    270     $empty_percentage     = $empty_cpus;
    271 
    272     $qcolors         = array();
    273     $color             = randomColor( $qcolors );
    274     $qcolors[]         = $color;
    275     $pie_args         .= "&free=$empty_percentage,$color";
     261        $node_freecpu= $node_cpus - $job_cpu;
     262
     263        $empty_cpus += $node_freecpu;
     264    }
     265
     266    $empty_cpus = ( $empty_cpus >= 0 ) ? $empty_cpus : 0;
     267    $used_cpus  = $nr_cpus - $empty_cpus;
     268
     269    $empty_percentage= $empty_cpus;
     270
     271    $qcolors   = array();
     272    $color     = randomColor( $qcolors );
     273    $qcolors[] = $color;
     274    $pie_args .= "&free=$empty_percentage,$color";
    276275
    277276    if( isset( $piefilter ) )
     
    282281    foreach( $nodes as $node )
    283282    {
    284         $node_jobs     = $node->getJobs();
    285         $nr_node_jobs     = count( $node_jobs );
    286         $myhost     = $node->getHostname();
     283        $node_jobs    = $node->getJobs();
     284        $nr_node_jobs = count( $node_jobs );
     285        $myhost       = $node->getHostname();
    287286        $node_cpus    = $metrics[$myhost]["cpu_num"]['VAL'];
    288287
    289288        foreach( $node_jobs as $myjob )
    290289        {
    291             $job_cpu        = isset( $jobs[$myjob]['ppn'] ) ? $jobs[$myjob]['ppn'] : 1;
     290            $job_cpu = isset( $jobs[$myjob]['ppn'] ) ? $jobs[$myjob]['ppn'] : 1;
    292291
    293292            // Determine the weight of this job
     
    353352            {
    354353
    355                 $qname        = $jobs[$myjob]['queue'];
     354                $qname = $jobs[$myjob]['queue'];
    356355
    357356                if( !isset( $queues[$qname] ) )
     
    378377    foreach( $graphvals as $name => $totalweight)
    379378    {
    380         $percentage     = $totalweight;
     379        $percentage    = $totalweight;
    381380       
    382381        $color         = randomColor( $qcolors );
     
    408407        foreach( $jobs as $jobid => $jobattrs )
    409408        {
    410                 $state        = $jobattrs['status'];
    411                 $owner      = $jobattrs['owner'];
    412                 $queue         = $jobattrs['queue'];
    413                 $name         = $jobattrs['name'];
    414                 $req_cpu     = $jobattrs['requested_time'];
    415                 $req_memory     = $jobattrs['requested_memory'];
     409                $state     = $jobattrs['status'];
     410                $owner     = $jobattrs['owner'];
     411                $queue     = $jobattrs['queue'];
     412                $name      = $jobattrs['name'];
     413                $req_cpu   = $jobattrs['requested_time'];
     414                $req_memory= $jobattrs['requested_memory'];
    416415
    417416                if( $state == 'R' )
     
    519518    $tpl->assign("sortby", $sortby );
    520519
    521     $sorted_jobs         = sortJobs( $jobs, $sortby, $sortorder );
    522 
    523     $even             = 1;
    524 
    525     $used_jobs         = 0;
    526     $used_cpus         = 0;
     520    $sorted_jobs        = sortJobs( $jobs, $sortby, $sortorder );
     521
     522    $even               = 1;
     523
     524    $used_jobs          = 0;
     525    $used_cpus          = 0;
    527526    $used_nodes         = 0;
    528527
    529     $queued_jobs         = 0;
    530     $queued_nodes         = 0;
    531     $queued_cpus         = 0;
    532 
    533     $total_nodes         = 0;
     528    $queued_jobs        = 0;
     529    $queued_nodes       = 0;
     530    $queued_cpus        = 0;
     531
     532    $total_nodes        = 0;
    534533    $total_cpus         = 0;
    535534    $total_jobs         = 0;
    536535
    537536    $all_used_nodes     = array();
    538     $total_used_nodes     = array();
    539 
    540     $running_name_nodes     = array();
    541 
    542     $running_nodes         = 0;
    543     $running_jobs         = 0;
    544     $running_cpus         = 0;
    545 
    546     $avail_nodes         = count( $gnodes );
     537    $total_used_nodes   = array();
     538
     539    $running_name_nodes = array();
     540
     541    $running_nodes      = 0;
     542    $running_jobs       = 0;
     543    $running_cpus       = 0;
     544
     545    $avail_nodes        = count( $gnodes );
    547546    $avail_cpus         = cluster_sum("cpu_num", $metrics);
    548547
    549     $view_cpus         = 0;
    550     $view_jobs         = 0;
     548    $view_cpus          = 0;
     549    $view_jobs          = 0;
    551550    $view_nodes         = 0;
    552551
    553     $all_nodes         = 0;
    554     $all_jobs         = 0;
    555     $all_cpus         = 0;
    556 
    557     $view_name_nodes     = array();
     552    $all_nodes          = 0;
     553    $all_jobs           = 0;
     554    $all_cpus           = 0;
     555
     556    $view_name_nodes    = array();
    558557
    559558    // Is the "requested memory" column enabled in the config
     
    578577    }
    579578
    580     $last_displayed_job     = null;
    581 
    582     $rjqj_host        = null;
    583 
    584     $na_nodes        = 0;
    585     $na_cpus        = 0;
     579    $last_displayed_job = null;
     580
     581    $rjqj_host = null;
     582
     583    $na_nodes  = 0;
     584    $na_cpus   = 0;
    586585
    587586    foreach( $metrics as $bhost => $bmetric )
     
    591590            if( ( $mname == 'zplugin_monarch_rj' ) || ($mname == 'zplugin_monarch_qj') )
    592591            {
    593                 $rjqj_host      = $bhost;
     592                $rjqj_host = $bhost;
    594593            }
    595594        }
     
    600599        if( $gnode->isDown() || $gnode->isOffline() )
    601600        {
    602             $na_nodes    += 1;
    603             $na_cpus    += $metrics[$ghost]['cpu_num']['VAL'];
     601            $na_nodes += 1;
     602            $na_cpus  += $metrics[$ghost]['cpu_num']['VAL'];
    604603        }
    605604    }
     
    632631        }
    633632
    634         $ppn         = isset( $jobs[$jobid]['ppn'] ) ? $jobs[$jobid]['ppn'] : 1;
    635         $cpus         = $nodes * $ppn;
     633        $ppn  = isset( $jobs[$jobid]['ppn'] ) ? $jobs[$jobid]['ppn'] : 1;
     634        $cpus = $nodes * $ppn;
    636635
    637636        if( $report_time == $heartbeat )
     
    694693                }
    695694
    696                 $queued_cpus     += $cpus;
    697                 $queued_nodes     += $nodes;
     695                $queued_cpus  += $cpus;
     696                $queued_nodes += $nodes;
    698697
    699698                $queued_jobs++;
     
    804803                }
    805804
    806                 $ppn             = isset( $jobs[$jobid]['ppn'] ) ? $jobs[$jobid]['ppn'] : 1;
    807                 $cpus             = $nodes * $ppn;
     805                $ppn       = isset( $jobs[$jobid]['ppn'] ) ? $jobs[$jobid]['ppn'] : 1;
     806                $cpus      = $nodes * $ppn;
    808807
    809808                $tpl->assign( "nodes", $nodes );
    810809                $tpl->assign( "cpus", $cpus );
    811810
    812                 $start_time         = (int) $jobs[$jobid]['start_timestamp'];
    813                 $job_start         = $start_time;
    814 
    815                 $view_cpus         += $cpus;
     811                $start_time= (int) $jobs[$jobid]['start_timestamp'];
     812                $job_start = $start_time;
     813
     814                $view_cpus += $cpus;
    816815
    817816                $view_jobs++;
     
    834833                            if( $use_fqdn == 1)
    835834                            {
    836                                 $mynode    = $shortnode.".".$jobs[$jobid]['domain'];
     835                                $mynode     = $shortnode.".".$jobs[$jobid]['domain'];
    837836                            }
    838                             $myhost_href     = "./?c=".$clustername."&h=".$mynode;
    839                             $mynodehosts[]     = "<A HREF=\"".$myhost_href."\">".$shortnode."</A>";
     837                            $myhost_href    = "./?c=".$clustername."&h=".$mynode;
     838                            $mynodehosts[]  = "<A HREF=\"".$myhost_href."\">".$shortnode."</A>";
    840839                        }
    841840
    842                         $nodes_hostnames     = implode( " ", $mynodehosts );
     841                        $nodes_hostnames    = implode( " ", $mynodehosts );
    843842
    844843                        $tpl->assign( "nodes_hostnames", $nodes_hostnames );
     
    866865                if( $start_time )
    867866                {
    868                     $runningtime         = makeTime( $report_time - $start_time );
     867                    $runningtime        = makeTime( $report_time - $start_time );
    869868                    $job_runningtime    = $heartbeat - $start_time;
    870869
     
    877876
    878877    $all_used_nodes     = array_unique( $all_used_nodes );
    879     $view_name_nodes     = array_unique( $view_name_nodes );
    880     $running_name_nodes     = array_unique( $running_name_nodes );
     878    $view_name_nodes    = array_unique( $view_name_nodes );
     879    $running_name_nodes = array_unique( $running_name_nodes );
    881880
    882881    $used_nodes         = count( $all_used_nodes );
    883     $view_nodes         += count( $view_name_nodes );
    884     $running_nodes         += count( $running_name_nodes );
    885 
    886     $total_nodes         = $queued_nodes + $running_nodes;
     882    $view_nodes        += count( $view_name_nodes );
     883    $running_nodes     += count( $running_name_nodes );
     884
     885    $total_nodes        = $queued_nodes + $running_nodes;
    887886    $total_cpus         = $queued_cpus + $running_cpus;
    888887    $total_jobs         = $queued_jobs + $running_jobs;
    889888
    890889    $free_nodes         = $avail_nodes - $running_nodes - $na_nodes;
    891     $free_nodes        = ( $free_nodes >= 0 ) ? $free_nodes : 0;
    892     $free_cpus         = $avail_cpus - $running_cpus - $na_cpus;
    893     $free_cpus        = ( $free_cpus >= 0 ) ? $free_cpus : 0;
     890    $free_nodes         = ( $free_nodes >= 0 ) ? $free_nodes : 0;
     891    $free_cpus          = $avail_cpus - $running_cpus - $na_cpus;
     892    $free_cpus          = ( $free_cpus >= 0 ) ? $free_cpus : 0;
    894893
    895894    $tpl->assignGlobal( "avail_nodes", $avail_nodes );
Note: See TracChangeset for help on using the changeset viewer.