source: trunk/web/addons/job_monarch/host_view.php @ 410

Last change on this file since 410 was 399, checked in by bastiaans, 17 years ago

web/addons/job_monarch/search.php:

  • set host view for host detail

web/addons/job_monarch/index.php:

  • enable host view again

web/addons/job_monarch/host_view.php:

  • get available metrics from archive

web/addons/job_monarch/templates/host_view.tpl:

  • remove size restrictions from graphs
  • Property svn:keywords set to Id
File size: 6.1 KB
RevLine 
[149]1<?php
[225]2/*
3 *
4 * This file is part of Jobmonarch
5 *
6 * Copyright (C) 2006  Ramon Bastiaans
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: host_view.php 399 2007-07-01 16:38:47Z bastiaans $
[225]23 */
24
[149]25include_once "./libtoga.php";
26
27//$tpl = new TemplatePower( "templates/host_view.tpl" );
28//$tpl->assignInclude("extra", "templates/host_extra.tpl");
29//$tpl->prepare();
30
[189]31function datetimeToEpoch( $datetime ) {
[149]32
[189]33        //printf("datetime = %s\n", $datetime );
34        $datetime_fields = explode( ' ', $datetime );
35
36        $date = $datetime_fields[0];
37        $time = $datetime_fields[1];
38
39        $date_fields = explode( '-', $date );
40
41        $days = $date_fields[0];
42        $months = $date_fields[1];
43        $years = $date_fields[2];
44
45        //printf( "days = %s months = %s years = %s\n", $days, $months, $years );
46
47        $time_fields = explode( ':', $time );
48
49        $hours = $time_fields[0];
50        $minutes = $time_fields[1];
51        $seconds = $time_fields[2];
52
53        //printf( "hours = %s minutes = %s seconds = %s\n", $hours, $minutes, $seconds );
54
55        $timestamp = mktime( $hours, $minutes, $seconds, $months, $days, $years );
56
57        //printf( "timestamp = %s\n", $timestamp );
58
59        return $timestamp;
60}
61
[149]62function makeHostView() {
63
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
[399]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
[149]76        $metrics = $metrics[$hostname];
[399]77        $mymetrics = array();
78
79        foreach( $rrdirs as $rrdir ) 
80        {
81                $ml     = $trd->dirList( $rrdir );
82
83                foreach( $ml as $lmetr )
84                {
85                        $metrn_fields   = explode( '.', $lmetr );
86
87                        $metrn          = $metrn_fields[0];
88
89                        if( !in_array( $metrn, $mymetrics ) )
90                        {
91                                $mymetrics[$metrn]      = $metrics[$metrn];
92                        }
93                }
94        }
95
[149]96        $hosts_up = $hosts_up[$hostname];
97        //print_r( $hosts_up );
98
99        $tpl->assign("cluster", $clustername);
100        $tpl->assign("host", $hostname);
101        $tpl->assign("node_image", "../../".node_image($metrics));
102        $tpl->assign("sort",$sort);
103        $tpl->assign("range",$range);
104
[189]105        if( !is_numeric( $period_start ) ) {
106                $period_start = datetimeToEpoch( $period_start );
107        }
108        if( !is_numeric( $period_stop ) ) {
109                $period_stop = datetimeToEpoch( $period_stop );
110        }
111
[149]112        if($hosts_up)
113              $tpl->assign("node_msg", "This host is up and running."); 
114        else
115              $tpl->assign("node_msg", "This host is down."); 
116
117        $cluster_url=rawurlencode($clustername);
118        $tpl->assign("cluster_url", $cluster_url);
119        $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");
120
121        # For the node view link.
122        $tpl->assign("node_view","./?p=2&c=$cluster_url&h=$hostname");
123
124        //# No reason to go on if this node is down.
125        //if ($hosts_down)
126        //   {
127        //      $tpl->printToScreen();
128        //      return;
129        //   }
130
131        $tpl->assign("ip", $hosts_up[IP]);
132
[399]133        foreach ($mymetrics as $name => $v)
[149]134           {
135               if ($v[TYPE] == "string" or $v[TYPE]=="timestamp" or $always_timestamp[$name])
136                  {
137                     # Long gmetric name/values will disrupt the display here.
138                     if ($v[SOURCE] == "gmond") $s_metrics[$name] = $v;
139                  }
140               elseif ($v[SLOPE] == "zero" or $always_constant[$name])
141                  {
142                     $c_metrics[$name] = $v;
143                  }
144               else if ($reports[$metric])
145                  continue;
146               else
147                  {
148                     $graphargs = "c=$cluster_url&h=$hostname&v=$v[VAL]&m=$name"
149                       ."&z=medium&st=$cluster[LOCALTIME]&job_start=$job_start&job_stop=$job_stop&period_start=$period_start&period_stop=$period_stop";
150                     # Adding units to graph 2003 by Jason Smith <smithj4@bnl.gov>.
151                     if ($v[UNITS]) {
152                        $encodeUnits = rawurlencode($v[UNITS]);
153                        $graphargs .= "&vl=$encodeUnits";
154                     }
155                     $g_metrics[$name][graph] = $graphargs;
156          }
157           }
158        # Add the uptime metric for this host. Cannot be done in ganglia.php,
159        # since it requires a fully-parsed XML tree. The classic contructor problem.
160        $s_metrics[uptime][TYPE] = "string";
161        $s_metrics[uptime][VAL] = uptime($cluster[LOCALTIME] - $metrics[boottime][VAL]);
162
163        # Add the gmond started timestamps & last reported time (in uptime format) from
164        # the HOST tag:
165        $s_metrics[gmond_started][TYPE] = "timestamp";
166        $s_metrics[gmond_started][VAL] = $hosts_up[GMOND_STARTED];
167        $s_metrics[last_reported][TYPE] = "string";
168        $s_metrics[last_reported][VAL] = uptime($cluster[LOCALTIME] - $hosts_up[REPORTED]);
169
170        # Show string metrics
171        if (is_array($s_metrics))
172           {
173              ksort($s_metrics);
174              foreach ($s_metrics as $name => $v )
175             {
176                $tpl->newBlock("string_metric_info");
177                $tpl->assign("name", $name);
178                if( $v[TYPE]=="timestamp" or $always_timestamp[$name])
179                   {
180                      $tpl->assign("value", date("r", $v[VAL]));
181                   }
182                else
183                   {
184                      $tpl->assign("value", "$v[VAL] $v[UNITS]");
185                   }
186             }
187           }
188
189        # Show constant metrics.
190        if (is_array($c_metrics))
191           {
192              ksort($c_metrics);
193              foreach ($c_metrics as $name => $v )
194             {
195                $tpl->newBlock("const_metric_info");
196                $tpl->assign("name", $name);
197                $tpl->assign("value", "$v[VAL] $v[UNITS]");
198             }
199           }
200
201        # Show graphs.
202        if (is_array($g_metrics))
203           {
204              ksort($g_metrics);
205
206              $i = 0;
207              foreach ( $g_metrics as $name => $v )
208                 {
209                    $tpl->newBlock("vol_metric_info");
210                    $tpl->assign("graphargs", $v[graph]);
211                    $tpl->assign("alt", "$hostname $name");
212                    if($i++ %2)
213                       $tpl->assign("br", "<BR>");
214                 }
215           }
216}
217
218        //$tpl->printToScreen();
219?>
Note: See TracBrowser for help on using the repository browser.