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

Last change on this file since 592 was 412, checked in by bastiaans, 17 years ago

web/addons/job_monarch/host_view.php:

  • bugfixes to graph display new style
  • Property svn:keywords set to Id
File size: 6.6 KB
Line 
1<?php
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 *
22 * SVN $Id: host_view.php 412 2007-07-06 14:36:09Z bastiaans $
23 */
24
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
31function datetimeToEpoch( $datetime ) {
32
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
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
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;
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           }
224}
225
226        //$tpl->printToScreen();
227?>
Note: See TracBrowser for help on using the repository browser.