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