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

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

web/addons/job_monarch/host_view.php:

  • make header properly according to new setup

web/addons/job_monarch/search.php,
web/addons/job_monarch/index.php:

  • use correct metricname parsing
  • Property svn:keywords set to Id
File size: 6.2 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 411 2007-07-06 13:50:48Z 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        $metrics = $metrics[$hostname];
77        $mymetrics = array();
78
79        $longtitle = "Batch Archive Node Report :: Powered by Job Monarch!";
80        $title = "Batch Archive Node Report";
81
82        makeHeader( 'host_view', $title, $longtitle );
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
126        # For the node view link.
127        $tpl->assign("node_view","./?p=2&c=$cluster_url&h=$hostname");
128
129        //# No reason to go on if this node is down.
130        //if ($hosts_down)
131        //   {
132        //      $tpl->printToScreen();
133        //      return;
134        //   }
135
136        $tpl->assign("ip", $hosts_up[IP]);
137
138        foreach ($mymetrics as $name => $v)
139           {
140               if ($v[TYPE] == "string" or $v[TYPE]=="timestamp" or $always_timestamp[$name])
141                  {
142                     # Long gmetric name/values will disrupt the display here.
143                     if ($v[SOURCE] == "gmond") $s_metrics[$name] = $v;
144                  }
145               elseif ($v[SLOPE] == "zero" or $always_constant[$name])
146                  {
147                     $c_metrics[$name] = $v;
148                  }
149               else if ($reports[$metric])
150                  continue;
151               else
152                  {
153                     $graphargs = "c=$cluster_url&h=$hostname&v=$v[VAL]&m=$name"
154                       ."&z=medium&st=$cluster[LOCALTIME]&job_start=$job_start&job_stop=$job_stop&period_start=$period_start&period_stop=$period_stop";
155                     # Adding units to graph 2003 by Jason Smith <smithj4@bnl.gov>.
156                     if ($v[UNITS]) {
157                        $encodeUnits = rawurlencode($v[UNITS]);
158                        $graphargs .= "&vl=$encodeUnits";
159                     }
160                     $g_metrics[$name][graph] = $graphargs;
161          }
162           }
163        # Add the uptime metric for this host. Cannot be done in ganglia.php,
164        # since it requires a fully-parsed XML tree. The classic contructor problem.
165        $s_metrics[uptime][TYPE] = "string";
166        $s_metrics[uptime][VAL] = uptime($cluster[LOCALTIME] - $metrics[boottime][VAL]);
167
168        # Add the gmond started timestamps & last reported time (in uptime format) from
169        # the HOST tag:
170        $s_metrics[gmond_started][TYPE] = "timestamp";
171        $s_metrics[gmond_started][VAL] = $hosts_up[GMOND_STARTED];
172        $s_metrics[last_reported][TYPE] = "string";
173        $s_metrics[last_reported][VAL] = uptime($cluster[LOCALTIME] - $hosts_up[REPORTED]);
174
175        # Show string metrics
176        if (is_array($s_metrics))
177           {
178              ksort($s_metrics);
179              foreach ($s_metrics as $name => $v )
180             {
181                $tpl->newBlock("string_metric_info");
182                $tpl->assign("name", $name);
183                if( $v[TYPE]=="timestamp" or $always_timestamp[$name])
184                   {
185                      $tpl->assign("value", date("r", $v[VAL]));
186                   }
187                else
188                   {
189                      $tpl->assign("value", "$v[VAL] $v[UNITS]");
190                   }
191             }
192           }
193
194        # Show constant metrics.
195        if (is_array($c_metrics))
196           {
197              ksort($c_metrics);
198              foreach ($c_metrics as $name => $v )
199             {
200                $tpl->newBlock("const_metric_info");
201                $tpl->assign("name", $name);
202                $tpl->assign("value", "$v[VAL] $v[UNITS]");
203             }
204           }
205
206        # Show graphs.
207        if (is_array($g_metrics))
208           {
209              ksort($g_metrics);
210
211              $i = 0;
212              foreach ( $g_metrics as $name => $v )
213                 {
214                    $tpl->newBlock("vol_metric_info");
215                    $tpl->assign("graphargs", $v[graph]);
216                    $tpl->assign("alt", "$hostname $name");
217                    if($i++ %2)
218                       $tpl->assign("br", "<BR>");
219                 }
220           }
221}
222
223        //$tpl->printToScreen();
224?>
Note: See TracBrowser for help on using the repository browser.