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

Legend:

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

    r412 r719  
    6262function makeHostView() {
    6363
    64         global $tpl, $metrics, $clustername, $hostname;
    65         global $cluster_ul, $hosts_up, $get_metric_string;
    66         global $cluster, $period_start, $period_stop;
    67         global $job_start, $job_stop;
    68 
    69         //print_r( $metrics );
    70 
    71         //printf( "c %s\n", $clustername );
    72 
    73         $trd = new TarchRrdGraph( $clustername, $hostname );
    74         $rrdirs = $trd->getRrdDirs( $period_start, $period_stop );
    75 
    76         $longtitle = "Batch Archive Node Report :: Powered by Job Monarch!";
    77         $title = "Batch Archive Node Report";
    78 
    79         makeHeader( 'host_view', $title, $longtitle );
    80 
    81         $metrics = $metrics[$hostname];
    82         $mymetrics = array();
    83 
    84         foreach( $rrdirs as $rrdir )
    85         {
    86                 $ml     = $trd->dirList( $rrdir );
    87 
    88                 foreach( $ml as $lmetr )
    89                 {
    90                         $metrn_fields   = explode( '.', $lmetr );
    91 
    92                         $metrn          = $metrn_fields[0];
    93 
    94                         if( !in_array( $metrn, $mymetrics ) )
    95                         {
    96                                 $mymetrics[$metrn]      = $metrics[$metrn];
    97                         }
    98                 }
    99         }
    100 
    101         $hosts_up = $hosts_up[$hostname];
    102         //print_r( $hosts_up );
    103 
    104         $tpl->assign("cluster", $clustername);
    105         $tpl->assign("host", $hostname);
    106         $tpl->assign("node_image", "../../".node_image($metrics));
    107         $tpl->assign("sort",$sort);
    108         $tpl->assign("range",$range);
    109 
    110         if( !is_numeric( $period_start ) ) {
    111                 $period_start = datetimeToEpoch( $period_start );
    112         }
    113         if( !is_numeric( $period_stop ) ) {
    114                 $period_stop = datetimeToEpoch( $period_stop );
    115         }
    116 
    117         if($hosts_up)
    118               $tpl->assign("node_msg", "This host is up and running.");
    119         else
    120               $tpl->assign("node_msg", "This host is down.");
    121 
    122         $cluster_url=rawurlencode($clustername);
    123         $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");
    125         $tpl->assign("graphargs", "h=$hostname&$get_metric_string&job_start=$job_start&job_stop=$job_stop&period_start=$period_start&period_stop=$period_stop");
    126 
    127         # For the node view link.
    128         $tpl->assign("node_view","./?p=2&c=$cluster_url&h=$hostname");
    129 
    130         //# No reason to go on if this node is down.
    131         //if ($hosts_down)
    132         //   {
    133         //      $tpl->printToScreen();
    134         //      return;
    135         //   }
    136 
    137         $tpl->assign("ip", $hosts_up[IP]);
    138 
    139         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"
    157                        ."&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;
     64    global $tpl, $metrics, $clustername, $hostname;
     65    global $cluster_ul, $hosts_up, $get_metric_string;
     66    global $cluster, $period_start, $period_stop;
     67    global $job_start, $job_stop;
     68
     69    //print_r( $metrics );
     70
     71    //printf( "c %s\n", $clustername );
     72
     73    $trd = new TarchRrdGraph( $clustername, $hostname );
     74    $rrdirs = $trd->getRrdDirs( $period_start, $period_stop );
     75
     76    $longtitle = "Batch Archive Node Report :: Powered by Job Monarch!";
     77    $title = "Batch Archive Node Report";
     78
     79    makeHeader( 'host_view', $title, $longtitle );
     80
     81    $metrics = $metrics[$hostname];
     82    $mymetrics = array();
     83
     84    foreach( $rrdirs as $rrdir )
     85    {
     86        $ml    = $trd->dirList( $rrdir );
     87
     88        foreach( $ml as $lmetr )
     89        {
     90            $metrn_fields    = explode( '.', $lmetr );
     91
     92            $metrn        = $metrn_fields[0];
     93
     94            if( !in_array( $metrn, $mymetrics ) )
     95            {
     96                $mymetrics[$metrn]    = $metrics[$metrn];
     97            }
     98        }
     99    }
     100
     101    $hosts_up = $hosts_up[$hostname];
     102    //print_r( $hosts_up );
     103
     104    $tpl->assign("cluster", $clustername);
     105    $tpl->assign("host", $hostname);
     106    $tpl->assign("node_image", "../../".node_image($metrics));
     107    $tpl->assign("sort",$sort);
     108    $tpl->assign("range",$range);
     109
     110    if( !is_numeric( $period_start ) ) {
     111        $period_start = datetimeToEpoch( $period_start );
     112    }
     113    if( !is_numeric( $period_stop ) ) {
     114        $period_stop = datetimeToEpoch( $period_stop );
     115    }
     116
     117    if($hosts_up)
     118          $tpl->assign("node_msg", "This host is up and running.");
     119    else
     120          $tpl->assign("node_msg", "This host is down.");
     121
     122    $cluster_url=rawurlencode($clustername);
     123    $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");
     125    $tpl->assign("graphargs", "h=$hostname&$get_metric_string&job_start=$job_start&job_stop=$job_stop&period_start=$period_start&period_stop=$period_stop");
     126
     127    # For the node view link.
     128    $tpl->assign("node_view","./?p=2&c=$cluster_url&h=$hostname");
     129
     130    //# No reason to go on if this node is down.
     131    //if ($hosts_down)
     132    //   {
     133    //      $tpl->printToScreen();
     134    //      return;
     135    //   }
     136
     137    $tpl->assign("ip", $hosts_up[IP]);
     138
     139    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;
    164145          }
    165            }
    166         # Add the uptime metric for this host. Cannot be done in ganglia.php,
    167         # since it requires a fully-parsed XML tree. The classic contructor problem.
    168         $s_metrics[uptime][TYPE] = "string";
    169         $s_metrics[uptime][VAL] = uptime($cluster[LOCALTIME] - $metrics[boottime][VAL]);
    170 
    171         # Add the gmond started timestamps & last reported time (in uptime format) from
    172         # the HOST tag:
    173         $s_metrics[gmond_started][TYPE] = "timestamp";
    174         $s_metrics[gmond_started][VAL] = $hosts_up[GMOND_STARTED];
    175         $s_metrics[last_reported][TYPE] = "string";
    176         $s_metrics[last_reported][VAL] = uptime($cluster[LOCALTIME] - $hosts_up[REPORTED]);
    177 
    178         # Show string metrics
    179         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            }
    196 
    197         # Show constant metrics.
    198         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            }
    208 
    209         # Show graphs.
    210         if (is_array($g_metrics))
    211            {
    212               ksort($g_metrics);
    213 
    214               $i = 0;
    215               foreach ( $g_metrics as $name => $v )
    216                  {
    217                     $tpl->newBlock("vol_metric_info");
    218                     $tpl->assign("graphargs", $v[graph]);
    219                     $tpl->assign("alt", "$hostname $name");
    220                     if($i++ %2)
    221                        $tpl->assign("br", "<BR>");
    222                  }
    223            }
     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"
     157               ."&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       }
     166    # Add the uptime metric for this host. Cannot be done in ganglia.php,
     167    # since it requires a fully-parsed XML tree. The classic contructor problem.
     168    $s_metrics[uptime][TYPE] = "string";
     169    $s_metrics[uptime][VAL] = uptime($cluster[LOCALTIME] - $metrics[boottime][VAL]);
     170
     171    # Add the gmond started timestamps & last reported time (in uptime format) from
     172    # the HOST tag:
     173    $s_metrics[gmond_started][TYPE] = "timestamp";
     174    $s_metrics[gmond_started][VAL] = $hosts_up[GMOND_STARTED];
     175    $s_metrics[last_reported][TYPE] = "string";
     176    $s_metrics[last_reported][VAL] = uptime($cluster[LOCALTIME] - $hosts_up[REPORTED]);
     177
     178    # Show string metrics
     179    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       }
     196
     197    # Show constant metrics.
     198    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       }
     208
     209    # Show graphs.
     210    if (is_array($g_metrics))
     211       {
     212          ksort($g_metrics);
     213
     214          $i = 0;
     215          foreach ( $g_metrics as $name => $v )
     216         {
     217            $tpl->newBlock("vol_metric_info");
     218            $tpl->assign("graphargs", $v[graph]);
     219            $tpl->assign("alt", "$hostname $name");
     220            if($i++ %2)
     221               $tpl->assign("br", "<BR>");
     222         }
     223       }
    224224}
    225225
    226         //$tpl->printToScreen();
     226    //$tpl->printToScreen();
    227227?>
Note: See TracChangeset for help on using the changeset viewer.