source: branches/0.4/web/addons/job_monarch/host_view.php @ 739

Last change on this file since 739 was 739, checked in by ramonb, 11 years ago
  • make sure range is correctly set and passed on
  • Property svn:keywords set to Id
File size: 7.2 KB
Line 
1<?php
2/*
3 *
4 * This file is part of Jobmonarch
5 *
6 * Copyright (C) 2006-2013  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 739 2013-03-24 19:18:46Z ramonb $
23 */
24
25include_once "./libtoga.php";
26
27function datetimeToEpoch( $datetime ) 
28{
29
30        $datetime_fields = explode( ' ', $datetime );
31
32        $date = $datetime_fields[0];
33        $time = $datetime_fields[1];
34
35        $date_fields = explode( '-', $date );
36
37        $days = $date_fields[0];
38        $months = $date_fields[1];
39        $years = $date_fields[2];
40
41        //printf( "days = %s months = %s years = %s\n", $days, $months, $years );
42
43        $time_fields = explode( ':', $time );
44
45        $hours = $time_fields[0];
46        $minutes = $time_fields[1];
47        $seconds = $time_fields[2];
48
49        $timestamp = mktime( $hours, $minutes, $seconds, $months, $days, $years );
50
51        return $timestamp;
52}
53
54function makeHostView() 
55{
56
57    global $tpl, $metrics, $clustername, $hostname;
58    global $cluster_ul, $hosts_up, $get_metric_string;
59    global $cluster, $period_start, $period_stop;
60    global $job_start, $job_stop, $view, $conf;
61
62    $rrdirs = array();
63
64    if( $view == "overview-host" )
65    {
66        $rrdirs[] = $conf['rrds'] . '/' . $clustername .'/'. $hostname;
67    }
68    else
69    {
70        $trd    = new TarchRrdGraph( $clustername, $hostname );
71        $rrdirs = $trd->getRrdDirs( $period_start, $period_stop );
72    }
73
74    $longtitle    = "Batch Archive Node Report :: Powered by Job Monarch!";
75    $title        = "Batch Archive Node Report";
76
77    makeHeader( 'host_view', $title, $longtitle );
78
79    #print_r( $rrdirs);
80
81    $metrics = $metrics[$hostname];
82    $mymetrics = array();
83
84    foreach( $rrdirs as $rrdir ) 
85    {
86        #printf("rrd dir %s\n", $rrdir );
87        if( $view == "overview-host" )
88        {
89            $mymetrics = $metrics;
90            #print_r( $mymetrics );
91        }
92        else
93        {
94            #printf("archive mode\n");
95            $ml    = $trd->dirList( $rrdir );
96
97            foreach( $ml as $lmetr )
98            {
99                $metrn_fields = explode( '.', $lmetr );
100
101                $metrn        = $metrn_fields[0];
102
103                if( !in_array( $metrn, $mymetrics ) )
104                {
105                    $mymetrics[$metrn]    = $metrics[$metrn];
106                }
107            }
108        }
109    }
110
111    $hosts_up = $hosts_up[$hostname];
112
113    $tpl->assign("cluster", $clustername);
114    $tpl->assign("host", $hostname);
115    $tpl->assign("node_image", "../../".node_image($metrics));
116    $tpl->assign("sort",$sort);
117    $tpl->assign("range",$range);
118
119    if( !is_numeric( $period_start ) ) 
120    {
121        $period_start = datetimeToEpoch( $period_start );
122    }
123    if( !is_numeric( $period_stop ) ) 
124    {
125        $period_stop = datetimeToEpoch( $period_stop );
126    }
127
128    if($hosts_up)
129          $tpl->assign("node_msg", "This host is up and running."); 
130    else
131          $tpl->assign("node_msg", "This host is down."); 
132
133    $cluster_url=rawurlencode($clustername);
134    $tpl->assign("cluster_url", $cluster_url);
135
136    $graphargs = "h=$hostname&job_start=$job_start&job_stop=$job_stop&period_start=$period_start&period_stop=$period_stop";
137
138    if( $range == 'job' )
139    {
140        $graphargs .= "&period_start=$period_start&period_stop=$period_stop";
141    }
142    else
143    {
144        $tijd = time();
145        $graphargs .= "&st=$tijd";
146    }
147
148    $tpl->assign("graphargs", "$graphargs");
149
150    # For the node view link.
151    $tpl->assign("node_view","./?p=2&c=$cluster_url&h=$hostname");
152
153    $tpl->assign("ip", $hosts_up[IP]);
154
155    #print_r( $mymetrics );
156
157    foreach ($mymetrics as $name => $v)
158    {
159        if ($v[TYPE] == "string" or $v[TYPE]=="timestamp" or $always_timestamp[$name])
160        {
161            # Long gmetric name/values will disrupt the display here.
162            if ($v[SOURCE] == "gmond") $s_metrics[$name] = $v;
163        }
164        else if ($v[SLOPE] == "zero" or $always_constant[$name])
165        {
166            $c_metrics[$name] = $v;
167        }
168        else if ($reports[$metric])
169        {
170            continue;
171        }
172        else
173        {
174            $graphargs = "c=$cluster_url&h=$hostname&m=$name&z=overview-medium&range=$range&job_start=$job_start&job_stop=$job_stop";
175
176            if( $range == 'job' )
177            {
178                $graphargs .= "&period_start=$period_start&period_stop=$period_stop";
179            }
180            else
181            {
182                $tijd = time();
183                $graphargs .= "&st=$tijd";
184            }
185            # Adding units to graph 2003 by Jason Smith <smithj4@bnl.gov>.
186            if ($v[UNITS]) 
187            {
188                $encodeUnits = rawurlencode($v[UNITS]);
189                $graphargs .= "&vl=$encodeUnits";
190            }
191            $g_metrics[$name][graph] = $graphargs;
192        }
193    }
194    # Add the uptime metric for this host. Cannot be done in ganglia.php,
195    # since it requires a fully-parsed XML tree. The classic contructor problem.
196    $s_metrics[uptime][TYPE] = "string";
197    $s_metrics[uptime][VAL] = uptime($cluster[LOCALTIME] - $metrics[boottime][VAL]);
198
199    # Add the gmond started timestamps & last reported time (in uptime format) from
200    # the HOST tag:
201    $s_metrics[gmond_started][TYPE] = "timestamp";
202    $s_metrics[gmond_started][VAL] = $hosts_up[GMOND_STARTED];
203    $s_metrics[last_reported][TYPE] = "string";
204    $s_metrics[last_reported][VAL] = uptime($cluster[LOCALTIME] - $hosts_up[REPORTED]);
205
206    # Show string metrics
207    if (is_array($s_metrics))
208    {
209        ksort($s_metrics);
210        foreach ($s_metrics as $name => $v )
211        {
212            $tpl->newBlock("string_metric_info");
213            $tpl->assign("name", $name);
214            if( $v[TYPE]=="timestamp" or $always_timestamp[$name])
215            {
216                $tpl->assign("value", date("r", $v[VAL]));
217            }
218            else
219            {
220                $tpl->assign("value", "$v[VAL] $v[UNITS]");
221            }
222        }
223    }
224
225    # Show constant metrics.
226    if (is_array($c_metrics))
227    {
228        ksort($c_metrics);
229        foreach ($c_metrics as $name => $v )
230        {
231            $tpl->newBlock("const_metric_info");
232            $tpl->assign("name", $name);
233            $tpl->assign("value", "$v[VAL] $v[UNITS]");
234        }
235    }
236
237    # Show graphs.
238    if (is_array($g_metrics))
239    {
240        ksort($g_metrics);
241
242        $i = 0;
243        foreach ( $g_metrics as $name => $v )
244        {
245            $tpl->newBlock("vol_metric_info");
246            $tpl->assign("graphargs", $v[graph]);
247            $tpl->assign("alt", "$hostname $name");
248            if($i++ %2)
249            {
250                $tpl->assign("br", "<BR>");
251            }
252         }
253    }
254}
255
256?>
Note: See TracBrowser for help on using the repository browser.