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

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

ALL:

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