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

Last change on this file since 758 was 751, checked in by ramonb, 11 years ago

job_monarch/libtoga.php:

  • why call Ganglia's get_ganglia.php Gmetad() if we are already parsing ourself
  • now create $metrics ourself while TorqueXMLHandler.parseXML() runs
  • more speedup...

job_monarch/host_view.php,
job_monarch/graph.php:

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