[149] | 1 | <?php |
---|
| 2 | include_once "./libtoga.php"; |
---|
| 3 | |
---|
| 4 | //$tpl = new TemplatePower( "templates/host_view.tpl" ); |
---|
| 5 | //$tpl->assignInclude("extra", "templates/host_extra.tpl"); |
---|
| 6 | //$tpl->prepare(); |
---|
| 7 | |
---|
[189] | 8 | function datetimeToEpoch( $datetime ) { |
---|
[149] | 9 | |
---|
[189] | 10 | //printf("datetime = %s\n", $datetime ); |
---|
| 11 | $datetime_fields = explode( ' ', $datetime ); |
---|
| 12 | |
---|
| 13 | $date = $datetime_fields[0]; |
---|
| 14 | $time = $datetime_fields[1]; |
---|
| 15 | |
---|
| 16 | $date_fields = explode( '-', $date ); |
---|
| 17 | |
---|
| 18 | $days = $date_fields[0]; |
---|
| 19 | $months = $date_fields[1]; |
---|
| 20 | $years = $date_fields[2]; |
---|
| 21 | |
---|
| 22 | //printf( "days = %s months = %s years = %s\n", $days, $months, $years ); |
---|
| 23 | |
---|
| 24 | $time_fields = explode( ':', $time ); |
---|
| 25 | |
---|
| 26 | $hours = $time_fields[0]; |
---|
| 27 | $minutes = $time_fields[1]; |
---|
| 28 | $seconds = $time_fields[2]; |
---|
| 29 | |
---|
| 30 | //printf( "hours = %s minutes = %s seconds = %s\n", $hours, $minutes, $seconds ); |
---|
| 31 | |
---|
| 32 | $timestamp = mktime( $hours, $minutes, $seconds, $months, $days, $years ); |
---|
| 33 | |
---|
| 34 | //printf( "timestamp = %s\n", $timestamp ); |
---|
| 35 | |
---|
| 36 | return $timestamp; |
---|
| 37 | } |
---|
| 38 | |
---|
[149] | 39 | function makeHostView() { |
---|
| 40 | |
---|
| 41 | global $tpl, $metrics, $clustername, $hostname; |
---|
| 42 | global $cluster_ul, $hosts_up, $get_metric_string; |
---|
| 43 | global $cluster, $period_start, $period_stop; |
---|
| 44 | global $job_start, $job_stop; |
---|
| 45 | |
---|
| 46 | $metrics = $metrics[$hostname]; |
---|
| 47 | //print_r( $metrics ); |
---|
| 48 | $hosts_up = $hosts_up[$hostname]; |
---|
| 49 | //print_r( $hosts_up ); |
---|
| 50 | |
---|
| 51 | $tpl->assign("cluster", $clustername); |
---|
| 52 | $tpl->assign("host", $hostname); |
---|
| 53 | $tpl->assign("node_image", "../../".node_image($metrics)); |
---|
| 54 | $tpl->assign("sort",$sort); |
---|
| 55 | $tpl->assign("range",$range); |
---|
| 56 | |
---|
[189] | 57 | if( !is_numeric( $period_start ) ) { |
---|
| 58 | $period_start = datetimeToEpoch( $period_start ); |
---|
| 59 | } |
---|
| 60 | if( !is_numeric( $period_stop ) ) { |
---|
| 61 | $period_stop = datetimeToEpoch( $period_stop ); |
---|
| 62 | } |
---|
| 63 | |
---|
[149] | 64 | if($hosts_up) |
---|
| 65 | $tpl->assign("node_msg", "This host is up and running."); |
---|
| 66 | else |
---|
| 67 | $tpl->assign("node_msg", "This host is down."); |
---|
| 68 | |
---|
| 69 | $cluster_url=rawurlencode($clustername); |
---|
| 70 | $tpl->assign("cluster_url", $cluster_url); |
---|
| 71 | $tpl->assign("graphargs", "h=$hostname&$get_metric_string&st=$cluster[LOCALTIME]&job_start=$job_start&job_stop=$job_stop&period_start=$period_start&period_stop=$period_stop"); |
---|
| 72 | |
---|
| 73 | # For the node view link. |
---|
| 74 | $tpl->assign("node_view","./?p=2&c=$cluster_url&h=$hostname"); |
---|
| 75 | |
---|
| 76 | //# No reason to go on if this node is down. |
---|
| 77 | //if ($hosts_down) |
---|
| 78 | // { |
---|
| 79 | // $tpl->printToScreen(); |
---|
| 80 | // return; |
---|
| 81 | // } |
---|
| 82 | |
---|
| 83 | $tpl->assign("ip", $hosts_up[IP]); |
---|
| 84 | |
---|
| 85 | foreach ($metrics as $name => $v) |
---|
| 86 | { |
---|
| 87 | if ($v[TYPE] == "string" or $v[TYPE]=="timestamp" or $always_timestamp[$name]) |
---|
| 88 | { |
---|
| 89 | # Long gmetric name/values will disrupt the display here. |
---|
| 90 | if ($v[SOURCE] == "gmond") $s_metrics[$name] = $v; |
---|
| 91 | } |
---|
| 92 | elseif ($v[SLOPE] == "zero" or $always_constant[$name]) |
---|
| 93 | { |
---|
| 94 | $c_metrics[$name] = $v; |
---|
| 95 | } |
---|
| 96 | else if ($reports[$metric]) |
---|
| 97 | continue; |
---|
| 98 | else |
---|
| 99 | { |
---|
| 100 | $graphargs = "c=$cluster_url&h=$hostname&v=$v[VAL]&m=$name" |
---|
| 101 | ."&z=medium&st=$cluster[LOCALTIME]&job_start=$job_start&job_stop=$job_stop&period_start=$period_start&period_stop=$period_stop"; |
---|
| 102 | # Adding units to graph 2003 by Jason Smith <smithj4@bnl.gov>. |
---|
| 103 | if ($v[UNITS]) { |
---|
| 104 | $encodeUnits = rawurlencode($v[UNITS]); |
---|
| 105 | $graphargs .= "&vl=$encodeUnits"; |
---|
| 106 | } |
---|
| 107 | $g_metrics[$name][graph] = $graphargs; |
---|
| 108 | } |
---|
| 109 | } |
---|
| 110 | # Add the uptime metric for this host. Cannot be done in ganglia.php, |
---|
| 111 | # since it requires a fully-parsed XML tree. The classic contructor problem. |
---|
| 112 | $s_metrics[uptime][TYPE] = "string"; |
---|
| 113 | $s_metrics[uptime][VAL] = uptime($cluster[LOCALTIME] - $metrics[boottime][VAL]); |
---|
| 114 | |
---|
| 115 | # Add the gmond started timestamps & last reported time (in uptime format) from |
---|
| 116 | # the HOST tag: |
---|
| 117 | $s_metrics[gmond_started][TYPE] = "timestamp"; |
---|
| 118 | $s_metrics[gmond_started][VAL] = $hosts_up[GMOND_STARTED]; |
---|
| 119 | $s_metrics[last_reported][TYPE] = "string"; |
---|
| 120 | $s_metrics[last_reported][VAL] = uptime($cluster[LOCALTIME] - $hosts_up[REPORTED]); |
---|
| 121 | |
---|
| 122 | # Show string metrics |
---|
| 123 | if (is_array($s_metrics)) |
---|
| 124 | { |
---|
| 125 | ksort($s_metrics); |
---|
| 126 | foreach ($s_metrics as $name => $v ) |
---|
| 127 | { |
---|
| 128 | $tpl->newBlock("string_metric_info"); |
---|
| 129 | $tpl->assign("name", $name); |
---|
| 130 | if( $v[TYPE]=="timestamp" or $always_timestamp[$name]) |
---|
| 131 | { |
---|
| 132 | $tpl->assign("value", date("r", $v[VAL])); |
---|
| 133 | } |
---|
| 134 | else |
---|
| 135 | { |
---|
| 136 | $tpl->assign("value", "$v[VAL] $v[UNITS]"); |
---|
| 137 | } |
---|
| 138 | } |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | # Show constant metrics. |
---|
| 142 | if (is_array($c_metrics)) |
---|
| 143 | { |
---|
| 144 | ksort($c_metrics); |
---|
| 145 | foreach ($c_metrics as $name => $v ) |
---|
| 146 | { |
---|
| 147 | $tpl->newBlock("const_metric_info"); |
---|
| 148 | $tpl->assign("name", $name); |
---|
| 149 | $tpl->assign("value", "$v[VAL] $v[UNITS]"); |
---|
| 150 | } |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | # Show graphs. |
---|
| 154 | if (is_array($g_metrics)) |
---|
| 155 | { |
---|
| 156 | ksort($g_metrics); |
---|
| 157 | |
---|
| 158 | $i = 0; |
---|
| 159 | foreach ( $g_metrics as $name => $v ) |
---|
| 160 | { |
---|
| 161 | $tpl->newBlock("vol_metric_info"); |
---|
| 162 | $tpl->assign("graphargs", $v[graph]); |
---|
| 163 | $tpl->assign("alt", "$hostname $name"); |
---|
| 164 | if($i++ %2) |
---|
| 165 | $tpl->assign("br", "<BR>"); |
---|
| 166 | } |
---|
| 167 | } |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | //$tpl->printToScreen(); |
---|
| 171 | ?> |
---|