Example #1
0
function variable_ninety_fifth_percentile($var_scale, $var_divisor, $var_type, $var_precision, &$graph_item, &$graph_items, $graph_start, $graph_end) {
	global $ninety_fifth_cache;

	require_once(CACTI_BASE_PATH . "/lib/graph/graph_utility.php");

	if (($var_type == "current") || ($var_type == "max")) {
		if (!isset($ninety_fifth_cache{$graph_item["local_data_id"]})) {
			$ninety_fifth_cache{$graph_item["local_data_id"]} = ninety_fifth_percentile($graph_item["local_data_id"], $graph_start, $graph_end);
		}
	}elseif (($var_type == "total") || ($var_type == "total_peak") || ($var_type == "all_max_current") || ($var_type == "all_max_peak")) {
		for ($t=0;($t<count($graph_items));$t++) {
			if ((!isset($ninety_fifth_cache{$graph_items[$t]["local_data_id"]})) && (!empty($graph_items[$t]["local_data_id"]))) {
				$ninety_fifth_cache{$graph_items[$t]["local_data_id"]} = ninety_fifth_percentile($graph_items[$t]["local_data_id"], $graph_start, $graph_end);
			}
		}
	}elseif (($var_type == "aggregate") || ($var_type == "aggregate_sum") || ($var_type == "aggregate_max")) {
		$local_data_array = array();
		for ($t=0;($t<count($graph_items));$t++) {
			if ((is_graph_item_type_primary($graph_items[$t]["graph_type_id"])) && (!empty($graph_items[$t]["data_template_rrd_id"]))) {
				$local_data_array[$graph_items[$t]["local_data_id"]][] = $graph_items[$t]["data_source_name"];
			}
		}
                $ninety_fifth_cache{0} = ninety_fifth_percentile($local_data_array, $graph_start, $graph_end);
	}

	$ninety_fifth = 0;

	/* format the output according to args passed to the variable */
	if ($var_type == "current") {
		$ninety_fifth = $ninety_fifth_cache{$graph_item["local_data_id"]}{$graph_item["data_source_name"]};
		$ninety_fifth = ($var_scale == "bits") ? $ninety_fifth * 8 : $ninety_fifth;
		$ninety_fifth /= pow(10, intval($var_divisor));
	}elseif ($var_type == "total") {
		for ($t=0; $t<count($graph_items); $t++) {
			if ((is_graph_item_type_primary($graph_items[$t]["graph_type_id"])) && (!empty($graph_items[$t]["data_template_rrd_id"]))) {
				$local_ninety_fifth = $ninety_fifth_cache{$graph_items[$t]["local_data_id"]}{$graph_items[$t]["data_source_name"]};
				$local_ninety_fifth = ($var_scale == "bits") ? $local_ninety_fifth * 8 : $local_ninety_fifth;
				$local_ninety_fifth /= pow(10, intval($var_divisor));

				$ninety_fifth += $local_ninety_fifth;
			}
		}
	}elseif ($var_type == "max") {
		$ninety_fifth = $ninety_fifth_cache{$graph_item["local_data_id"]}["ninety_fifth_percentile_maximum"];
		$ninety_fifth = ($var_scale == "bits") ? $ninety_fifth * 8 : $ninety_fifth;
		$ninety_fifth /= pow(10, intval($var_divisor));
	}elseif ($var_type == "total_peak") {
		for ($t=0; $t<count($graph_items); $t++) {
			if ((is_graph_item_type_primary($graph_items[$t]["graph_type_id"])) && (!empty($graph_items[$t]["data_template_rrd_id"]))) {
				$local_ninety_fifth = $ninety_fifth_cache{$graph_items[$t]["local_data_id"]}["ninety_fifth_percentile_maximum"];
				$local_ninety_fifth = ($var_scale == "bits") ? $local_ninety_fifth * 8 : $local_ninety_fifth;
				$local_ninety_fifth /= pow(10, intval($var_divisor));

				$ninety_fifth += $local_ninety_fifth;
			}
		}
	}elseif ($var_type == "all_max_current") {
		for ($t=0; $t<count($graph_items); $t++) {
			if ((is_graph_item_type_primary($graph_items[$t]["graph_type_id"])) && (!empty($graph_items[$t]["data_template_rrd_id"]))) {
				$local_ninety_fifth = $ninety_fifth_cache{$graph_items[$t]["local_data_id"]}{$graph_items[$t]["data_source_name"]};
				$local_ninety_fifth = ($var_scale == "bits") ? $local_ninety_fifth * 8 : $local_ninety_fifth;
				$local_ninety_fifth /= pow(10, intval($var_divisor));

				if ($local_ninety_fifth > $ninety_fifth) {
					$ninety_fifth = $local_ninety_fifth;
				}
			}
		}
	}elseif ($var_type == "all_max_peak") {
		for ($t=0; $t<count($graph_items); $t++) {
			if ((is_graph_item_type_primary($graph_items[$t]["graph_type_id"])) && (!empty($graph_items[$t]["data_template_rrd_id"]))) {
				$local_ninety_fifth = $ninety_fifth_cache{$graph_items[$t]["local_data_id"]}["ninety_fifth_percentile_maximum"];
				$local_ninety_fifth = ($var_scale == "bits") ? $local_ninety_fifth * 8 : $local_ninety_fifth;
				$local_ninety_fifth /= pow(10, intval($var_divisor));

				if ($local_ninety_fifth > $ninety_fifth) {
					$ninety_fifth = $local_ninety_fifth;
				}
			}
		}
	}elseif ($var_type == "aggregate") {
		if (empty($ninety_fifth_cache{0}["ninety_fifth_percentile_aggregate_total"])) {
			$ninety_fifth = 0;
		}else{
			$local_ninety_fifth = $ninety_fifth_cache{0}["ninety_fifth_percentile_aggregate_total"];
			$local_ninety_fifth = ($regexp_match_array[1] == "bits") ? $local_ninety_fifth * 8 : $local_ninety_fifth;
			$local_ninety_fifth /= pow(10,intval($var_divisor));
			$ninety_fifth = $local_ninety_fifth;
		}
	}elseif ($var_type == "aggregate_max") {
		if (empty($ninety_fifth_cache{0}["ninety_fifth_percentile_aggregate_max"])) {
			$ninety_fifth = 0;
		}else{
			$local_ninety_fifth = $ninety_fifth_cache{0}["ninety_fifth_percentile_aggregate_max"];
			$local_ninety_fifth = ($regexp_match_array[1] == "bits") ? $local_ninety_fifth * 8 : $local_ninety_fifth;
			$local_ninety_fifth /= pow(10,intval($var_divisor));
			$ninety_fifth = $local_ninety_fifth;
		}
	}elseif ($var_type == "aggregate_sum") {
		if (empty($ninety_fifth_cache{0}["ninety_fifth_percentile_aggregate_sum"])) {
			$ninety_fifth = 0;
		}else{
			$local_ninety_fifth = $ninety_fifth_cache{0}["ninety_fifth_percentile_aggregate_sum"];
			$local_ninety_fifth = ($regexp_match_array[1] == "bits") ? $local_ninety_fifth * 8 : $local_ninety_fifth;
			$local_ninety_fifth /= pow(10,intval($var_divisor));
			$ninety_fifth = $local_ninety_fifth;
		}
	}

	/* determine the floating point precision */
	if ((isset($var_precision)) && (is_numeric($var_precision))) {
		$round_to = $var_precision;
	}else{
		$round_to = 2;
	}

	/* return the final result and round off to two decimal digits */
	return round($ninety_fifth, $round_to);
}
Example #2
0
function variable_ninety_fifth_percentile(&$regexp_match_array, &$graph_item, &$graph_items, $graph_start, $graph_end) {
	global $graph_item_types;

	if (sizeof($regexp_match_array) == 0) {
		return 0;
	}

	if (($regexp_match_array[3] == "current") || ($regexp_match_array[3] == "max")) {
		$ninety_fifth_cache{$graph_item["local_data_id"]} = ninety_fifth_percentile($graph_item["local_data_id"], $graph_start, $graph_end);
	}elseif ($regexp_match_array[3] == "total") {
		for ($t=0;($t<count($graph_items));$t++) {
			if (!empty($graph_items[$t]["local_data_id"])) {
				$ninety_fifth_cache{$graph_items[$t]["local_data_id"]} = ninety_fifth_percentile($graph_items[$t]["local_data_id"], $graph_start, $graph_end);
			}
		}
	}

	$ninety_fifth = 0;

	/* format the output according to args passed to the variable */
	if ($regexp_match_array[3] == "current") {
		$ninety_fifth = $ninety_fifth_cache{$graph_item["local_data_id"]}{$graph_item["data_source_name"]};
		$ninety_fifth = ($regexp_match_array[1] == "bits") ? $ninety_fifth * 8 : $ninety_fifth;
		$ninety_fifth /= pow(10,intval($regexp_match_array[2]));
	}elseif ($regexp_match_array[3] == "total") {
		for ($t=0;($t<count($graph_items));$t++) {
			if ((ereg("(AREA|STACK|LINE[123])", $graph_item_types{$graph_items[$t]["graph_type_id"]})) && (!empty($graph_items[$t]["data_template_rrd_id"]))) {
				$local_ninety_fifth = $ninety_fifth_cache{$graph_items[$t]["local_data_id"]}{$graph_items[$t]["data_source_name"]};
				$local_ninety_fifth = ($regexp_match_array[1] == "bits") ? $local_ninety_fifth * 8 : $local_ninety_fifth;
				$local_ninety_fifth /= pow(10,intval($regexp_match_array[2]));

				$ninety_fifth += $local_ninety_fifth;
			}
		}
	}elseif ($regexp_match_array[3] == "max") {
		$ninety_fifth = $ninety_fifth_cache{$graph_item["local_data_id"]}["ninety_fifth_percentile_maximum"];
		$ninety_fifth = ($regexp_match_array[1] == "bits") ? $ninety_fifth * 8 : $ninety_fifth;
		$ninety_fifth /= pow(10,intval($regexp_match_array[2]));
	}

	/* determine the floating point precision */
	if ((isset($regexp_match_array[5])) && (ereg("^[0-9]+$", $regexp_match_array[5]))) {
		$round_to = $regexp_match_array[5];
	}else{
		$round_to = 2;
	}

	/* return the final result and round off to two decimal digits */
	return round($ninety_fifth, $round_to);
}