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

Last change on this file since 336 was 231, checked in by bastiaans, 18 years ago

*.php:

  • added svn keywords propset
  • Property svn:keywords set to Id
File size: 5.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 231 2006-03-10 16:36:38Z 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        $metrics = $metrics[$hostname];
70        //print_r( $metrics );
71        $hosts_up = $hosts_up[$hostname];
72        //print_r( $hosts_up );
73
74        $tpl->assign("cluster", $clustername);
75        $tpl->assign("host", $hostname);
76        $tpl->assign("node_image", "../../".node_image($metrics));
77        $tpl->assign("sort",$sort);
78        $tpl->assign("range",$range);
79
80        if( !is_numeric( $period_start ) ) {
81                $period_start = datetimeToEpoch( $period_start );
82        }
83        if( !is_numeric( $period_stop ) ) {
84                $period_stop = datetimeToEpoch( $period_stop );
85        }
86
87        if($hosts_up)
88              $tpl->assign("node_msg", "This host is up and running."); 
89        else
90              $tpl->assign("node_msg", "This host is down."); 
91
92        $cluster_url=rawurlencode($clustername);
93        $tpl->assign("cluster_url", $cluster_url);
94        $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");
95
96        # For the node view link.
97        $tpl->assign("node_view","./?p=2&c=$cluster_url&h=$hostname");
98
99        //# No reason to go on if this node is down.
100        //if ($hosts_down)
101        //   {
102        //      $tpl->printToScreen();
103        //      return;
104        //   }
105
106        $tpl->assign("ip", $hosts_up[IP]);
107
108        foreach ($metrics as $name => $v)
109           {
110               if ($v[TYPE] == "string" or $v[TYPE]=="timestamp" or $always_timestamp[$name])
111                  {
112                     # Long gmetric name/values will disrupt the display here.
113                     if ($v[SOURCE] == "gmond") $s_metrics[$name] = $v;
114                  }
115               elseif ($v[SLOPE] == "zero" or $always_constant[$name])
116                  {
117                     $c_metrics[$name] = $v;
118                  }
119               else if ($reports[$metric])
120                  continue;
121               else
122                  {
123                     $graphargs = "c=$cluster_url&h=$hostname&v=$v[VAL]&m=$name"
124                       ."&z=medium&st=$cluster[LOCALTIME]&job_start=$job_start&job_stop=$job_stop&period_start=$period_start&period_stop=$period_stop";
125                     # Adding units to graph 2003 by Jason Smith <smithj4@bnl.gov>.
126                     if ($v[UNITS]) {
127                        $encodeUnits = rawurlencode($v[UNITS]);
128                        $graphargs .= "&vl=$encodeUnits";
129                     }
130                     $g_metrics[$name][graph] = $graphargs;
131          }
132           }
133        # Add the uptime metric for this host. Cannot be done in ganglia.php,
134        # since it requires a fully-parsed XML tree. The classic contructor problem.
135        $s_metrics[uptime][TYPE] = "string";
136        $s_metrics[uptime][VAL] = uptime($cluster[LOCALTIME] - $metrics[boottime][VAL]);
137
138        # Add the gmond started timestamps & last reported time (in uptime format) from
139        # the HOST tag:
140        $s_metrics[gmond_started][TYPE] = "timestamp";
141        $s_metrics[gmond_started][VAL] = $hosts_up[GMOND_STARTED];
142        $s_metrics[last_reported][TYPE] = "string";
143        $s_metrics[last_reported][VAL] = uptime($cluster[LOCALTIME] - $hosts_up[REPORTED]);
144
145        # Show string metrics
146        if (is_array($s_metrics))
147           {
148              ksort($s_metrics);
149              foreach ($s_metrics as $name => $v )
150             {
151                $tpl->newBlock("string_metric_info");
152                $tpl->assign("name", $name);
153                if( $v[TYPE]=="timestamp" or $always_timestamp[$name])
154                   {
155                      $tpl->assign("value", date("r", $v[VAL]));
156                   }
157                else
158                   {
159                      $tpl->assign("value", "$v[VAL] $v[UNITS]");
160                   }
161             }
162           }
163
164        # Show constant metrics.
165        if (is_array($c_metrics))
166           {
167              ksort($c_metrics);
168              foreach ($c_metrics as $name => $v )
169             {
170                $tpl->newBlock("const_metric_info");
171                $tpl->assign("name", $name);
172                $tpl->assign("value", "$v[VAL] $v[UNITS]");
173             }
174           }
175
176        # Show graphs.
177        if (is_array($g_metrics))
178           {
179              ksort($g_metrics);
180
181              $i = 0;
182              foreach ( $g_metrics as $name => $v )
183                 {
184                    $tpl->newBlock("vol_metric_info");
185                    $tpl->assign("graphargs", $v[graph]);
186                    $tpl->assign("alt", "$hostname $name");
187                    if($i++ %2)
188                       $tpl->assign("br", "<BR>");
189                 }
190           }
191}
192
193        //$tpl->printToScreen();
194?>
Note: See TracBrowser for help on using the repository browser.