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

Legend:

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

    r719 r720  
    2525include_once "./libtoga.php";
    2626
    27 //$tpl = new TemplatePower( "templates/host_view.tpl" );
    28 //$tpl->assignInclude("extra", "templates/host_extra.tpl");
    29 //$tpl->prepare();
    30 
    31 function datetimeToEpoch( $datetime ) {
    32 
    33         //printf("datetime = %s\n", $datetime );
     27function datetimeToEpoch( $datetime )
     28{
     29
    3430        $datetime_fields = explode( ' ', $datetime );
    3531
     
    5147        $seconds = $time_fields[2];
    5248
    53         //printf( "hours = %s minutes = %s seconds = %s\n", $hours, $minutes, $seconds );
    54 
    5549        $timestamp = mktime( $hours, $minutes, $seconds, $months, $days, $years );
    56 
    57         //printf( "timestamp = %s\n", $timestamp );
    5850
    5951        return $timestamp;
    6052}
    6153
    62 function makeHostView() {
     54function makeHostView()
     55{
    6356
    6457    global $tpl, $metrics, $clustername, $hostname;
     
    6760    global $job_start, $job_stop;
    6861
    69     //print_r( $metrics );
    70 
    71     //printf( "c %s\n", $clustername );
    72 
    7362    $trd = new TarchRrdGraph( $clustername, $hostname );
    7463    $rrdirs = $trd->getRrdDirs( $period_start, $period_stop );
     
    10089
    10190    $hosts_up = $hosts_up[$hostname];
    102     //print_r( $hosts_up );
    10391
    10492    $tpl->assign("cluster", $clustername);
     
    10896    $tpl->assign("range",$range);
    10997
    110     if( !is_numeric( $period_start ) ) {
     98    if( !is_numeric( $period_start ) )
     99    {
    111100        $period_start = datetimeToEpoch( $period_start );
    112101    }
    113     if( !is_numeric( $period_stop ) ) {
     102    if( !is_numeric( $period_stop ) )
     103    {
    114104        $period_stop = datetimeToEpoch( $period_stop );
    115105    }
     
    122112    $cluster_url=rawurlencode($clustername);
    123113    $tpl->assign("cluster_url", $cluster_url);
    124     //$tpl->assign("graphargs", "h=$hostname&$get_metric_string&st=$cluster[LOCALTIME]&job_start=$job_start&job_stop=$job_stop&period_start=$period_start&period_stop=$period_stop");
    125114    $tpl->assign("graphargs", "h=$hostname&$get_metric_string&job_start=$job_start&job_stop=$job_stop&period_start=$period_start&period_stop=$period_stop");
    126115
     
    128117    $tpl->assign("node_view","./?p=2&c=$cluster_url&h=$hostname");
    129118
    130     //# No reason to go on if this node is down.
    131     //if ($hosts_down)
    132     //   {
    133     //      $tpl->printToScreen();
    134     //      return;
    135     //   }
    136 
    137119    $tpl->assign("ip", $hosts_up[IP]);
    138120
    139121    foreach ($mymetrics as $name => $v)
    140        {
    141            if ($v[TYPE] == "string" or $v[TYPE]=="timestamp" or $always_timestamp[$name])
    142           {
    143              # Long gmetric name/values will disrupt the display here.
    144              if ($v[SOURCE] == "gmond") $s_metrics[$name] = $v;
    145           }
    146            elseif ($v[SLOPE] == "zero" or $always_constant[$name])
    147           {
    148              $c_metrics[$name] = $v;
    149           }
    150            else if ($reports[$metric])
    151           continue;
    152            else
    153           {
    154              //$graphargs = "c=$cluster_url&h=$hostname&v=$v[VAL]&m=$name"
    155              //  ."&z=medium&st=$cluster[LOCALTIME]&job_start=$job_start&job_stop=$job_stop&period_start=$period_start&period_stop=$period_stop";
    156              $graphargs = "c=$cluster_url&h=$hostname&m=$name"
     122    {
     123        if ($v[TYPE] == "string" or $v[TYPE]=="timestamp" or $always_timestamp[$name])
     124        {
     125            # Long gmetric name/values will disrupt the display here.
     126            if ($v[SOURCE] == "gmond") $s_metrics[$name] = $v;
     127        }
     128        elseif ($v[SLOPE] == "zero" or $always_constant[$name])
     129        {
     130            $c_metrics[$name] = $v;
     131        }
     132        else if ($reports[$metric])
     133        {
     134            continue;
     135        }
     136        else
     137        {
     138            $graphargs = "c=$cluster_url&h=$hostname&m=$name"
    157139               ."&z=medium&job_start=$job_start&job_stop=$job_stop&period_start=$period_start&period_stop=$period_stop";
    158              # Adding units to graph 2003 by Jason Smith <smithj4@bnl.gov>.
    159              if ($v[UNITS]) {
    160             $encodeUnits = rawurlencode($v[UNITS]);
    161             $graphargs .= "&vl=$encodeUnits";
    162              }
    163              $g_metrics[$name][graph] = $graphargs;
    164           }
    165        }
     140            # Adding units to graph 2003 by Jason Smith <smithj4@bnl.gov>.
     141            if ($v[UNITS])
     142            {
     143                $encodeUnits = rawurlencode($v[UNITS]);
     144                $graphargs .= "&vl=$encodeUnits";
     145            }
     146            $g_metrics[$name][graph] = $graphargs;
     147        }
     148    }
    166149    # Add the uptime metric for this host. Cannot be done in ganglia.php,
    167150    # since it requires a fully-parsed XML tree. The classic contructor problem.
     
    178161    # Show string metrics
    179162    if (is_array($s_metrics))
    180        {
    181           ksort($s_metrics);
    182           foreach ($s_metrics as $name => $v )
    183          {
    184         $tpl->newBlock("string_metric_info");
    185         $tpl->assign("name", $name);
    186         if( $v[TYPE]=="timestamp" or $always_timestamp[$name])
    187            {
    188               $tpl->assign("value", date("r", $v[VAL]));
    189            }
    190         else
    191            {
    192               $tpl->assign("value", "$v[VAL] $v[UNITS]");
    193            }
    194          }
    195        }
     163    {
     164        ksort($s_metrics);
     165        foreach ($s_metrics as $name => $v )
     166        {
     167            $tpl->newBlock("string_metric_info");
     168            $tpl->assign("name", $name);
     169            if( $v[TYPE]=="timestamp" or $always_timestamp[$name])
     170            {
     171                $tpl->assign("value", date("r", $v[VAL]));
     172            }
     173            else
     174            {
     175                $tpl->assign("value", "$v[VAL] $v[UNITS]");
     176            }
     177        }
     178    }
    196179
    197180    # Show constant metrics.
    198181    if (is_array($c_metrics))
    199        {
    200           ksort($c_metrics);
    201           foreach ($c_metrics as $name => $v )
    202          {
    203         $tpl->newBlock("const_metric_info");
    204         $tpl->assign("name", $name);
    205         $tpl->assign("value", "$v[VAL] $v[UNITS]");
    206          }
    207        }
     182    {
     183        ksort($c_metrics);
     184        foreach ($c_metrics as $name => $v )
     185        {
     186            $tpl->newBlock("const_metric_info");
     187            $tpl->assign("name", $name);
     188            $tpl->assign("value", "$v[VAL] $v[UNITS]");
     189        }
     190    }
    208191
    209192    # Show graphs.
    210193    if (is_array($g_metrics))
    211        {
    212           ksort($g_metrics);
    213 
    214           $i = 0;
    215           foreach ( $g_metrics as $name => $v )
    216          {
     194    {
     195        ksort($g_metrics);
     196
     197        $i = 0;
     198        foreach ( $g_metrics as $name => $v )
     199        {
    217200            $tpl->newBlock("vol_metric_info");
    218201            $tpl->assign("graphargs", $v[graph]);
    219202            $tpl->assign("alt", "$hostname $name");
    220203            if($i++ %2)
    221                $tpl->assign("br", "<BR>");
     204            {
     205                $tpl->assign("br", "<BR>");
     206            }
    222207         }
    223        }
     208    }
    224209}
    225210
    226     //$tpl->printToScreen();
    227211?>
Note: See TracChangeset for help on using the changeset viewer.