[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 736 2013-03-24 17:44:13Z 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; |
---|
[734] | 60 | global $job_start, $job_stop, $view, $conf; |
---|
[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); |
---|
[735] | 135 | $tpl->assign("graphargs", "h=$hostname&job_start=$job_start&job_stop=$job_stop&period_start=$period_start&period_stop=$period_stop"); |
---|
[149] | 136 | |
---|
[719] | 137 | # For the node view link. |
---|
| 138 | $tpl->assign("node_view","./?p=2&c=$cluster_url&h=$hostname"); |
---|
[149] | 139 | |
---|
[719] | 140 | $tpl->assign("ip", $hosts_up[IP]); |
---|
[149] | 141 | |
---|
[736] | 142 | #print_r( $mymetrics ); |
---|
| 143 | |
---|
[719] | 144 | foreach ($mymetrics as $name => $v) |
---|
[720] | 145 | { |
---|
| 146 | if ($v[TYPE] == "string" or $v[TYPE]=="timestamp" or $always_timestamp[$name]) |
---|
| 147 | { |
---|
| 148 | # Long gmetric name/values will disrupt the display here. |
---|
| 149 | if ($v[SOURCE] == "gmond") $s_metrics[$name] = $v; |
---|
| 150 | } |
---|
[736] | 151 | else if ($v[SLOPE] == "zero" or $always_constant[$name]) |
---|
[720] | 152 | { |
---|
| 153 | $c_metrics[$name] = $v; |
---|
| 154 | } |
---|
| 155 | else if ($reports[$metric]) |
---|
| 156 | { |
---|
| 157 | continue; |
---|
| 158 | } |
---|
| 159 | else |
---|
| 160 | { |
---|
| 161 | $graphargs = "c=$cluster_url&h=$hostname&m=$name" |
---|
[736] | 162 | ."&z=overview-medium&job_start=$job_start&job_stop=$job_stop&period_start=$period_start&period_stop=$period_stop"; |
---|
[720] | 163 | # Adding units to graph 2003 by Jason Smith <smithj4@bnl.gov>. |
---|
| 164 | if ($v[UNITS]) |
---|
| 165 | { |
---|
| 166 | $encodeUnits = rawurlencode($v[UNITS]); |
---|
| 167 | $graphargs .= "&vl=$encodeUnits"; |
---|
| 168 | } |
---|
| 169 | $g_metrics[$name][graph] = $graphargs; |
---|
| 170 | } |
---|
| 171 | } |
---|
[719] | 172 | # Add the uptime metric for this host. Cannot be done in ganglia.php, |
---|
| 173 | # since it requires a fully-parsed XML tree. The classic contructor problem. |
---|
| 174 | $s_metrics[uptime][TYPE] = "string"; |
---|
| 175 | $s_metrics[uptime][VAL] = uptime($cluster[LOCALTIME] - $metrics[boottime][VAL]); |
---|
[149] | 176 | |
---|
[719] | 177 | # Add the gmond started timestamps & last reported time (in uptime format) from |
---|
| 178 | # the HOST tag: |
---|
| 179 | $s_metrics[gmond_started][TYPE] = "timestamp"; |
---|
| 180 | $s_metrics[gmond_started][VAL] = $hosts_up[GMOND_STARTED]; |
---|
| 181 | $s_metrics[last_reported][TYPE] = "string"; |
---|
| 182 | $s_metrics[last_reported][VAL] = uptime($cluster[LOCALTIME] - $hosts_up[REPORTED]); |
---|
[149] | 183 | |
---|
[719] | 184 | # Show string metrics |
---|
| 185 | if (is_array($s_metrics)) |
---|
[720] | 186 | { |
---|
| 187 | ksort($s_metrics); |
---|
| 188 | foreach ($s_metrics as $name => $v ) |
---|
| 189 | { |
---|
| 190 | $tpl->newBlock("string_metric_info"); |
---|
| 191 | $tpl->assign("name", $name); |
---|
| 192 | if( $v[TYPE]=="timestamp" or $always_timestamp[$name]) |
---|
| 193 | { |
---|
| 194 | $tpl->assign("value", date("r", $v[VAL])); |
---|
| 195 | } |
---|
| 196 | else |
---|
| 197 | { |
---|
| 198 | $tpl->assign("value", "$v[VAL] $v[UNITS]"); |
---|
| 199 | } |
---|
| 200 | } |
---|
| 201 | } |
---|
[149] | 202 | |
---|
[719] | 203 | # Show constant metrics. |
---|
| 204 | if (is_array($c_metrics)) |
---|
[720] | 205 | { |
---|
| 206 | ksort($c_metrics); |
---|
| 207 | foreach ($c_metrics as $name => $v ) |
---|
| 208 | { |
---|
| 209 | $tpl->newBlock("const_metric_info"); |
---|
| 210 | $tpl->assign("name", $name); |
---|
| 211 | $tpl->assign("value", "$v[VAL] $v[UNITS]"); |
---|
| 212 | } |
---|
| 213 | } |
---|
[149] | 214 | |
---|
[719] | 215 | # Show graphs. |
---|
| 216 | if (is_array($g_metrics)) |
---|
[720] | 217 | { |
---|
| 218 | ksort($g_metrics); |
---|
[149] | 219 | |
---|
[720] | 220 | $i = 0; |
---|
| 221 | foreach ( $g_metrics as $name => $v ) |
---|
| 222 | { |
---|
[719] | 223 | $tpl->newBlock("vol_metric_info"); |
---|
| 224 | $tpl->assign("graphargs", $v[graph]); |
---|
| 225 | $tpl->assign("alt", "$hostname $name"); |
---|
| 226 | if($i++ %2) |
---|
[720] | 227 | { |
---|
| 228 | $tpl->assign("br", "<BR>"); |
---|
| 229 | } |
---|
[719] | 230 | } |
---|
[720] | 231 | } |
---|
[149] | 232 | } |
---|
| 233 | |
---|
| 234 | ?> |
---|