[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 740 2013-03-24 19:29:09Z 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; |
---|
[740] | 60 | global $job_start, $job_stop, $view, $conf, $range; |
---|
[149] | 61 | |
---|
[734] | 62 | $rrdirs = array(); |
---|
[736] | 63 | |
---|
[734] | 64 | if( $view == "overview-host" ) |
---|
| 65 | { |
---|
[736] | 66 | $rrdirs[] = $conf['rrds'] . '/' . $clustername .'/'. $hostname; |
---|
[734] | 67 | } |
---|
| 68 | else |
---|
| 69 | { |
---|
[736] | 70 | $trd = new TarchRrdGraph( $clustername, $hostname ); |
---|
| 71 | $rrdirs = $trd->getRrdDirs( $period_start, $period_stop ); |
---|
[734] | 72 | } |
---|
[399] | 73 | |
---|
[734] | 74 | $longtitle = "Batch Archive Node Report :: Powered by Job Monarch!"; |
---|
| 75 | $title = "Batch Archive Node Report"; |
---|
[411] | 76 | |
---|
[719] | 77 | makeHeader( 'host_view', $title, $longtitle ); |
---|
[411] | 78 | |
---|
[736] | 79 | #print_r( $rrdirs); |
---|
| 80 | |
---|
[719] | 81 | $metrics = $metrics[$hostname]; |
---|
| 82 | $mymetrics = array(); |
---|
[412] | 83 | |
---|
[719] | 84 | foreach( $rrdirs as $rrdir ) |
---|
| 85 | { |
---|
[736] | 86 | #printf("rrd dir %s\n", $rrdir ); |
---|
| 87 | if( $view == "overview-host" ) |
---|
[719] | 88 | { |
---|
[736] | 89 | $mymetrics = $metrics; |
---|
| 90 | #print_r( $mymetrics ); |
---|
| 91 | } |
---|
| 92 | else |
---|
| 93 | { |
---|
| 94 | #printf("archive mode\n"); |
---|
| 95 | $ml = $trd->dirList( $rrdir ); |
---|
[399] | 96 | |
---|
[736] | 97 | foreach( $ml as $lmetr ) |
---|
| 98 | { |
---|
| 99 | $metrn_fields = explode( '.', $lmetr ); |
---|
[399] | 100 | |
---|
[736] | 101 | $metrn = $metrn_fields[0]; |
---|
| 102 | |
---|
| 103 | if( !in_array( $metrn, $mymetrics ) ) |
---|
| 104 | { |
---|
| 105 | $mymetrics[$metrn] = $metrics[$metrn]; |
---|
| 106 | } |
---|
[719] | 107 | } |
---|
| 108 | } |
---|
| 109 | } |
---|
[399] | 110 | |
---|
[719] | 111 | $hosts_up = $hosts_up[$hostname]; |
---|
[149] | 112 | |
---|
[719] | 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); |
---|
[149] | 118 | |
---|
[720] | 119 | if( !is_numeric( $period_start ) ) |
---|
| 120 | { |
---|
[719] | 121 | $period_start = datetimeToEpoch( $period_start ); |
---|
| 122 | } |
---|
[720] | 123 | if( !is_numeric( $period_stop ) ) |
---|
| 124 | { |
---|
[719] | 125 | $period_stop = datetimeToEpoch( $period_stop ); |
---|
| 126 | } |
---|
[189] | 127 | |
---|
[719] | 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."); |
---|
[149] | 132 | |
---|
[719] | 133 | $cluster_url=rawurlencode($clustername); |
---|
| 134 | $tpl->assign("cluster_url", $cluster_url); |
---|
[149] | 135 | |
---|
[740] | 136 | $graphargs = "h=$hostname&r=$range&job_start=$job_start&job_stop=$job_stop"; |
---|
[739] | 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 | |
---|
[719] | 150 | # For the node view link. |
---|
| 151 | $tpl->assign("node_view","./?p=2&c=$cluster_url&h=$hostname"); |
---|
[149] | 152 | |
---|
[719] | 153 | $tpl->assign("ip", $hosts_up[IP]); |
---|
[149] | 154 | |
---|
[736] | 155 | #print_r( $mymetrics ); |
---|
| 156 | |
---|
[719] | 157 | foreach ($mymetrics as $name => $v) |
---|
[720] | 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 | } |
---|
[736] | 164 | else if ($v[SLOPE] == "zero" or $always_constant[$name]) |
---|
[720] | 165 | { |
---|
| 166 | $c_metrics[$name] = $v; |
---|
| 167 | } |
---|
| 168 | else if ($reports[$metric]) |
---|
| 169 | { |
---|
| 170 | continue; |
---|
| 171 | } |
---|
| 172 | else |
---|
| 173 | { |
---|
[740] | 174 | $graphargs = "c=$cluster_url&h=$hostname&m=$name&z=overview-medium&r=$range&job_start=$job_start&job_stop=$job_stop"; |
---|
[739] | 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 | } |
---|
[720] | 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 | } |
---|
[719] | 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]); |
---|
[149] | 198 | |
---|
[719] | 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]); |
---|
[149] | 205 | |
---|
[719] | 206 | # Show string metrics |
---|
| 207 | if (is_array($s_metrics)) |
---|
[720] | 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 | } |
---|
[149] | 224 | |
---|
[719] | 225 | # Show constant metrics. |
---|
| 226 | if (is_array($c_metrics)) |
---|
[720] | 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 | } |
---|
[149] | 236 | |
---|
[719] | 237 | # Show graphs. |
---|
| 238 | if (is_array($g_metrics)) |
---|
[720] | 239 | { |
---|
| 240 | ksort($g_metrics); |
---|
[149] | 241 | |
---|
[720] | 242 | $i = 0; |
---|
| 243 | foreach ( $g_metrics as $name => $v ) |
---|
| 244 | { |
---|
[719] | 245 | $tpl->newBlock("vol_metric_info"); |
---|
| 246 | $tpl->assign("graphargs", $v[graph]); |
---|
| 247 | $tpl->assign("alt", "$hostname $name"); |
---|
| 248 | if($i++ %2) |
---|
[720] | 249 | { |
---|
| 250 | $tpl->assign("br", "<BR>"); |
---|
| 251 | } |
---|
[719] | 252 | } |
---|
[720] | 253 | } |
---|
[149] | 254 | } |
---|
| 255 | |
---|
| 256 | ?> |
---|