[149] | 1 | <?php |
---|
[225] | 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 | * |
---|
[231] | 22 | * SVN $Id: host_view.php 720 2013-03-21 20:53:01Z ramonb $ |
---|
[225] | 23 | */ |
---|
| 24 | |
---|
[149] | 25 | include_once "./libtoga.php"; |
---|
| 26 | |
---|
[720] | 27 | function datetimeToEpoch( $datetime ) |
---|
| 28 | { |
---|
[149] | 29 | |
---|
[189] | 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 | |
---|
[720] | 54 | function makeHostView() |
---|
| 55 | { |
---|
[149] | 56 | |
---|
[719] | 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; |
---|
[149] | 61 | |
---|
[719] | 62 | $trd = new TarchRrdGraph( $clustername, $hostname ); |
---|
| 63 | $rrdirs = $trd->getRrdDirs( $period_start, $period_stop ); |
---|
[399] | 64 | |
---|
[719] | 65 | $longtitle = "Batch Archive Node Report :: Powered by Job Monarch!"; |
---|
| 66 | $title = "Batch Archive Node Report"; |
---|
[411] | 67 | |
---|
[719] | 68 | makeHeader( 'host_view', $title, $longtitle ); |
---|
[411] | 69 | |
---|
[719] | 70 | $metrics = $metrics[$hostname]; |
---|
| 71 | $mymetrics = array(); |
---|
[412] | 72 | |
---|
[719] | 73 | foreach( $rrdirs as $rrdir ) |
---|
| 74 | { |
---|
| 75 | $ml = $trd->dirList( $rrdir ); |
---|
[399] | 76 | |
---|
[719] | 77 | foreach( $ml as $lmetr ) |
---|
| 78 | { |
---|
| 79 | $metrn_fields = explode( '.', $lmetr ); |
---|
[399] | 80 | |
---|
[719] | 81 | $metrn = $metrn_fields[0]; |
---|
[399] | 82 | |
---|
[719] | 83 | if( !in_array( $metrn, $mymetrics ) ) |
---|
| 84 | { |
---|
| 85 | $mymetrics[$metrn] = $metrics[$metrn]; |
---|
| 86 | } |
---|
| 87 | } |
---|
| 88 | } |
---|
[399] | 89 | |
---|
[719] | 90 | $hosts_up = $hosts_up[$hostname]; |
---|
[149] | 91 | |
---|
[719] | 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); |
---|
[149] | 97 | |
---|
[720] | 98 | if( !is_numeric( $period_start ) ) |
---|
| 99 | { |
---|
[719] | 100 | $period_start = datetimeToEpoch( $period_start ); |
---|
| 101 | } |
---|
[720] | 102 | if( !is_numeric( $period_stop ) ) |
---|
| 103 | { |
---|
[719] | 104 | $period_stop = datetimeToEpoch( $period_stop ); |
---|
| 105 | } |
---|
[189] | 106 | |
---|
[719] | 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."); |
---|
[149] | 111 | |
---|
[719] | 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"); |
---|
[149] | 115 | |
---|
[719] | 116 | # For the node view link. |
---|
| 117 | $tpl->assign("node_view","./?p=2&c=$cluster_url&h=$hostname"); |
---|
[149] | 118 | |
---|
[719] | 119 | $tpl->assign("ip", $hosts_up[IP]); |
---|
[149] | 120 | |
---|
[719] | 121 | foreach ($mymetrics as $name => $v) |
---|
[720] | 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" |
---|
[719] | 139 | ."&z=medium&job_start=$job_start&job_stop=$job_stop&period_start=$period_start&period_stop=$period_stop"; |
---|
[720] | 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 | } |
---|
[719] | 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]); |
---|
[149] | 153 | |
---|
[719] | 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]); |
---|
[149] | 160 | |
---|
[719] | 161 | # Show string metrics |
---|
| 162 | if (is_array($s_metrics)) |
---|
[720] | 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 | } |
---|
[149] | 179 | |
---|
[719] | 180 | # Show constant metrics. |
---|
| 181 | if (is_array($c_metrics)) |
---|
[720] | 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 | } |
---|
[149] | 191 | |
---|
[719] | 192 | # Show graphs. |
---|
| 193 | if (is_array($g_metrics)) |
---|
[720] | 194 | { |
---|
| 195 | ksort($g_metrics); |
---|
[149] | 196 | |
---|
[720] | 197 | $i = 0; |
---|
| 198 | foreach ( $g_metrics as $name => $v ) |
---|
| 199 | { |
---|
[719] | 200 | $tpl->newBlock("vol_metric_info"); |
---|
| 201 | $tpl->assign("graphargs", $v[graph]); |
---|
| 202 | $tpl->assign("alt", "$hostname $name"); |
---|
| 203 | if($i++ %2) |
---|
[720] | 204 | { |
---|
| 205 | $tpl->assign("br", "<BR>"); |
---|
| 206 | } |
---|
[719] | 207 | } |
---|
[720] | 208 | } |
---|
[149] | 209 | } |
---|
| 210 | |
---|
| 211 | ?> |
---|