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