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

Last change on this file since 736 was 736, checked in by ramonb, 11 years ago
  • more cleanup and fixes
  • Property svn:keywords set to Id
File size: 6.7 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 736 2013-03-24 17:44:13Z 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    $tpl->assign("graphargs", "h=$hostname&job_start=$job_start&job_stop=$job_stop&period_start=$period_start&period_stop=$period_stop");
136
137    # For the node view link.
138    $tpl->assign("node_view","./?p=2&c=$cluster_url&h=$hostname");
139
140    $tpl->assign("ip", $hosts_up[IP]);
141
142    #print_r( $mymetrics );
143
144    foreach ($mymetrics as $name => $v)
145    {
146        if ($v[TYPE] == "string" or $v[TYPE]=="timestamp" or $always_timestamp[$name])
147        {
148            # Long gmetric name/values will disrupt the display here.
149            if ($v[SOURCE] == "gmond") $s_metrics[$name] = $v;
150        }
151        else if ($v[SLOPE] == "zero" or $always_constant[$name])
152        {
153            $c_metrics[$name] = $v;
154        }
155        else if ($reports[$metric])
156        {
157            continue;
158        }
159        else
160        {
161            $graphargs = "c=$cluster_url&h=$hostname&m=$name"
162               ."&z=overview-medium&job_start=$job_start&job_stop=$job_stop&period_start=$period_start&period_stop=$period_stop";
163            # Adding units to graph 2003 by Jason Smith <smithj4@bnl.gov>.
164            if ($v[UNITS]) 
165            {
166                $encodeUnits = rawurlencode($v[UNITS]);
167                $graphargs .= "&vl=$encodeUnits";
168            }
169            $g_metrics[$name][graph] = $graphargs;
170        }
171    }
172    # Add the uptime metric for this host. Cannot be done in ganglia.php,
173    # since it requires a fully-parsed XML tree. The classic contructor problem.
174    $s_metrics[uptime][TYPE] = "string";
175    $s_metrics[uptime][VAL] = uptime($cluster[LOCALTIME] - $metrics[boottime][VAL]);
176
177    # Add the gmond started timestamps & last reported time (in uptime format) from
178    # the HOST tag:
179    $s_metrics[gmond_started][TYPE] = "timestamp";
180    $s_metrics[gmond_started][VAL] = $hosts_up[GMOND_STARTED];
181    $s_metrics[last_reported][TYPE] = "string";
182    $s_metrics[last_reported][VAL] = uptime($cluster[LOCALTIME] - $hosts_up[REPORTED]);
183
184    # Show string metrics
185    if (is_array($s_metrics))
186    {
187        ksort($s_metrics);
188        foreach ($s_metrics as $name => $v )
189        {
190            $tpl->newBlock("string_metric_info");
191            $tpl->assign("name", $name);
192            if( $v[TYPE]=="timestamp" or $always_timestamp[$name])
193            {
194                $tpl->assign("value", date("r", $v[VAL]));
195            }
196            else
197            {
198                $tpl->assign("value", "$v[VAL] $v[UNITS]");
199            }
200        }
201    }
202
203    # Show constant metrics.
204    if (is_array($c_metrics))
205    {
206        ksort($c_metrics);
207        foreach ($c_metrics as $name => $v )
208        {
209            $tpl->newBlock("const_metric_info");
210            $tpl->assign("name", $name);
211            $tpl->assign("value", "$v[VAL] $v[UNITS]");
212        }
213    }
214
215    # Show graphs.
216    if (is_array($g_metrics))
217    {
218        ksort($g_metrics);
219
220        $i = 0;
221        foreach ( $g_metrics as $name => $v )
222        {
223            $tpl->newBlock("vol_metric_info");
224            $tpl->assign("graphargs", $v[graph]);
225            $tpl->assign("alt", "$hostname $name");
226            if($i++ %2)
227            {
228                $tpl->assign("br", "<BR>");
229            }
230         }
231    }
232}
233
234?>
Note: See TracBrowser for help on using the repository browser.