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

Last change on this file since 732 was 720, checked in by ramonb, 11 years ago
  • cleanup
  • 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 720 2013-03-21 20:53:01Z 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;
61
62    $trd = new TarchRrdGraph( $clustername, $hostname );
63    $rrdirs = $trd->getRrdDirs( $period_start, $period_stop );
64
65    $longtitle = "Batch Archive Node Report :: Powered by Job Monarch!";
66    $title = "Batch Archive Node Report";
67
68    makeHeader( 'host_view', $title, $longtitle );
69
70    $metrics = $metrics[$hostname];
71    $mymetrics = array();
72
73    foreach( $rrdirs as $rrdir ) 
74    {
75        $ml    = $trd->dirList( $rrdir );
76
77        foreach( $ml as $lmetr )
78        {
79            $metrn_fields    = explode( '.', $lmetr );
80
81            $metrn        = $metrn_fields[0];
82
83            if( !in_array( $metrn, $mymetrics ) )
84            {
85                $mymetrics[$metrn]    = $metrics[$metrn];
86            }
87        }
88    }
89
90    $hosts_up = $hosts_up[$hostname];
91
92    $tpl->assign("cluster", $clustername);
93    $tpl->assign("host", $hostname);
94    $tpl->assign("node_image", "../../".node_image($metrics));
95    $tpl->assign("sort",$sort);
96    $tpl->assign("range",$range);
97
98    if( !is_numeric( $period_start ) ) 
99    {
100        $period_start = datetimeToEpoch( $period_start );
101    }
102    if( !is_numeric( $period_stop ) ) 
103    {
104        $period_stop = datetimeToEpoch( $period_stop );
105    }
106
107    if($hosts_up)
108          $tpl->assign("node_msg", "This host is up and running."); 
109    else
110          $tpl->assign("node_msg", "This host is down."); 
111
112    $cluster_url=rawurlencode($clustername);
113    $tpl->assign("cluster_url", $cluster_url);
114    $tpl->assign("graphargs", "h=$hostname&$get_metric_string&job_start=$job_start&job_stop=$job_stop&period_start=$period_start&period_stop=$period_stop");
115
116    # For the node view link.
117    $tpl->assign("node_view","./?p=2&c=$cluster_url&h=$hostname");
118
119    $tpl->assign("ip", $hosts_up[IP]);
120
121    foreach ($mymetrics as $name => $v)
122    {
123        if ($v[TYPE] == "string" or $v[TYPE]=="timestamp" or $always_timestamp[$name])
124        {
125            # Long gmetric name/values will disrupt the display here.
126            if ($v[SOURCE] == "gmond") $s_metrics[$name] = $v;
127        }
128        elseif ($v[SLOPE] == "zero" or $always_constant[$name])
129        {
130            $c_metrics[$name] = $v;
131        }
132        else if ($reports[$metric])
133        {
134            continue;
135        }
136        else
137        {
138            $graphargs = "c=$cluster_url&h=$hostname&m=$name"
139               ."&z=medium&job_start=$job_start&job_stop=$job_stop&period_start=$period_start&period_stop=$period_stop";
140            # Adding units to graph 2003 by Jason Smith <smithj4@bnl.gov>.
141            if ($v[UNITS]) 
142            {
143                $encodeUnits = rawurlencode($v[UNITS]);
144                $graphargs .= "&vl=$encodeUnits";
145            }
146            $g_metrics[$name][graph] = $graphargs;
147        }
148    }
149    # Add the uptime metric for this host. Cannot be done in ganglia.php,
150    # since it requires a fully-parsed XML tree. The classic contructor problem.
151    $s_metrics[uptime][TYPE] = "string";
152    $s_metrics[uptime][VAL] = uptime($cluster[LOCALTIME] - $metrics[boottime][VAL]);
153
154    # Add the gmond started timestamps & last reported time (in uptime format) from
155    # the HOST tag:
156    $s_metrics[gmond_started][TYPE] = "timestamp";
157    $s_metrics[gmond_started][VAL] = $hosts_up[GMOND_STARTED];
158    $s_metrics[last_reported][TYPE] = "string";
159    $s_metrics[last_reported][VAL] = uptime($cluster[LOCALTIME] - $hosts_up[REPORTED]);
160
161    # Show string metrics
162    if (is_array($s_metrics))
163    {
164        ksort($s_metrics);
165        foreach ($s_metrics as $name => $v )
166        {
167            $tpl->newBlock("string_metric_info");
168            $tpl->assign("name", $name);
169            if( $v[TYPE]=="timestamp" or $always_timestamp[$name])
170            {
171                $tpl->assign("value", date("r", $v[VAL]));
172            }
173            else
174            {
175                $tpl->assign("value", "$v[VAL] $v[UNITS]");
176            }
177        }
178    }
179
180    # Show constant metrics.
181    if (is_array($c_metrics))
182    {
183        ksort($c_metrics);
184        foreach ($c_metrics as $name => $v )
185        {
186            $tpl->newBlock("const_metric_info");
187            $tpl->assign("name", $name);
188            $tpl->assign("value", "$v[VAL] $v[UNITS]");
189        }
190    }
191
192    # Show graphs.
193    if (is_array($g_metrics))
194    {
195        ksort($g_metrics);
196
197        $i = 0;
198        foreach ( $g_metrics as $name => $v )
199        {
200            $tpl->newBlock("vol_metric_info");
201            $tpl->assign("graphargs", $v[graph]);
202            $tpl->assign("alt", "$hostname $name");
203            if($i++ %2)
204            {
205                $tpl->assign("br", "<BR>");
206            }
207         }
208    }
209}
210
211?>
Note: See TracBrowser for help on using the repository browser.