本文整理汇总了PHP中rrdtool_execute函数的典型用法代码示例。如果您正苦于以下问题:PHP rrdtool_execute函数的具体用法?PHP rrdtool_execute怎么用?PHP rrdtool_execute使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rrdtool_execute函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: rrdtool_function_graph
//.........这里部分代码省略.........
/* if we are not displaying a legend there is no point in us even processing the auto padding,
text format stuff. */
if ((!isset($graph_data_array["graph_nolegend"])) && ($graph["auto_padding"] == "on") && (isset($text_format_lengths{$graph_item["data_template_rrd_id"]}))) {
/* we are basing how much to pad on area and stack text format,
not gprint. but of course the padding has to be displayed in gprint,
how fun! */
$pad_number = ($greatest_text_format - $text_format_lengths{$graph_item["data_template_rrd_id"]});
//cacti_log("MAX: $greatest_text_format, CURR: $text_format_lengths[$item_dsid], DSID: $item_dsid");
$text_padding = str_pad("", $pad_number);
/* two GPRINT's in a row screws up the padding, lets not do that */
if (($graph_item_types{$graph_item["graph_type_id"]} == "GPRINT") && ($last_graph_type == "GPRINT")) {
$text_padding = "";
}
$last_graph_type = $graph_item_types{$graph_item["graph_type_id"]};
}
/* we put this in a variable so it can be manipulated before mainly used
if we want to skip it, like below */
$current_graph_item_type = $graph_item_types{$graph_item["graph_type_id"]};
/* IF this graph item has a data source... get a DEF name for it, or the cdef if that applies
to this graph item */
if ($graph_item["cdef_id"] == "0") {
if (isset($cf_ds_cache{$graph_item["data_template_rrd_id"]}[$cf_id])) {
$data_source_name = generate_graph_def_name(strval($cf_ds_cache{$graph_item["data_template_rrd_id"]}[$cf_id]));
}else{
$data_source_name = "";
}
}else{
$data_source_name = "cdef" . generate_graph_def_name(strval($cdef_cache{$graph_item["cdef_id"]}{$graph_item["data_template_rrd_id"]}[$cf_id]));
}
/* to make things easier... if there is no text format set; set blank text */
if (!isset($graph_variables["text_format"][$graph_item_id])) {
$graph_variables["text_format"][$graph_item_id] = "";
}
if (!isset($hardreturn[$graph_item_id])) {
$hardreturn[$graph_item_id] = "";
}
/* +++++++++++++++++++++++ GRAPH ITEMS +++++++++++++++++++++++ */
/* most of the calculations have been done above. now we have for print everything out
in an RRDTool-friendly fashion */
if (ereg("^(AREA|STACK|LINE[123])$", $graph_item_types{$graph_item["graph_type_id"]})) {
$graph_variables["text_format"][$graph_item_id] = str_replace(":", "\:", $graph_variables["text_format"][$graph_item_id]); /* escape colons */
$txt_graph_items .= $graph_item_types{$graph_item["graph_type_id"]} . ":" . $data_source_name . "#" . $graph_item["hex"] . ":" . "\"" . $graph_variables["text_format"][$graph_item_id] . $hardreturn[$graph_item_id] . "\" ";
}elseif ($graph_item_types{$graph_item["graph_type_id"]} == "COMMENT") {
$txt_graph_items .= $graph_item_types{$graph_item["graph_type_id"]} . ":\"" . $graph_variables["text_format"][$graph_item_id] . $hardreturn[$graph_item_id] . "\" ";
}elseif (($graph_item_types{$graph_item["graph_type_id"]} == "GPRINT") && (!isset($graph_data_array["graph_nolegend"]))) {
$graph_variables["text_format"][$graph_item_id] = str_replace(":", "\:", $graph_variables["text_format"][$graph_item_id]); /* escape colons */
$txt_graph_items .= $graph_item_types{$graph_item["graph_type_id"]} . ":" . $data_source_name . ":" . $consolidation_functions{$graph_item["consolidation_function_id"]} . ":\"$text_padding" . $graph_variables["text_format"][$graph_item_id] . $graph_item["gprint_text"] . $hardreturn[$graph_item_id] . "\" ";
}elseif ($graph_item_types{$graph_item["graph_type_id"]} == "HRULE") {
$graph_variables["text_format"][$graph_item_id] = str_replace(":", "\:", $graph_variables["text_format"][$graph_item_id]); /* escape colons */
$graph_variables["value"][$graph_item_id] = str_replace(":", "\:", $graph_variables["value"][$graph_item_id]); /* escape colons */
$txt_graph_items .= $graph_item_types{$graph_item["graph_type_id"]} . ":" . $graph_variables["value"][$graph_item_id] . "#" . $graph_item["hex"] . ":\"" . $graph_variables["text_format"][$graph_item_id] . $hardreturn[$graph_item_id] . "\" ";
}elseif ($graph_item_types{$graph_item["graph_type_id"]} == "VRULE") {
$graph_variables["text_format"][$graph_item_id] = str_replace(":", "\:", $graph_variables["text_format"][$graph_item_id]); /* escape colons */
$value_array = explode(":", $graph_item["value"]);
if ($value_array[0] < 0) {
$value = date("U") - (-3600 * $value_array[0]) - 60 * $value_array[1];
}else{
$value = date("U", mktime($value_array[0],$value_array[1],0));
}
$txt_graph_items .= $graph_item_types{$graph_item["graph_type_id"]} . ":" . $value . "#" . $graph_item["hex"] . ":\"" . $graph_variables["text_format"][$graph_item_id] . $hardreturn[$graph_item_id] . "\" ";
}
$i++;
if ($i < sizeof($graph_items)) {
$txt_graph_items .= RRD_NL;
}
}
}
/* either print out the source or pass the source onto rrdtool to get us a nice PNG */
if (isset($graph_data_array["print_source"])) {
print "<PRE>" . read_config_option("path_rrdtool") . " graph $graph_opts$graph_defs$txt_graph_items</PRE>";
}else{
if (isset($graph_data_array["export"])) {
rrdtool_execute("graph $graph_opts$graph_defs$txt_graph_items", false, RRDTOOL_OUTPUT_NULL, $rrd_struc);
return 0;
}else{
if (isset($graph_data_array["output_flag"])) {
$output_flag = $graph_data_array["output_flag"];
}else{
$output_flag = RRDTOOL_OUTPUT_GRAPH_DATA;
}
return rrdtool_execute("graph $graph_opts$graph_defs$txt_graph_items", false, $output_flag, $rrd_struc);
}
}
}
示例2: rrdtool_function_xport
//.........这里部分代码省略.........
if (isset($magic_item["ALL_DATA_SOURCES_DUPS"])) {
$cdef_string = str_replace("ALL_DATA_SOURCES_DUPS", $magic_item["ALL_DATA_SOURCES_DUPS"], $cdef_string);
}
if (isset($magic_item["ALL_DATA_SOURCES_NODUPS"])) {
$cdef_string = str_replace("ALL_DATA_SOURCES_NODUPS", $magic_item["ALL_DATA_SOURCES_NODUPS"], $cdef_string);
}
if (isset($magic_item["SIMILAR_DATA_SOURCES_DUPS"])) {
$cdef_string = str_replace("SIMILAR_DATA_SOURCES_DUPS", $magic_item["SIMILAR_DATA_SOURCES_DUPS"], $cdef_string);
}
if (isset($magic_item["SIMILAR_DATA_SOURCES_NODUPS"])) {
$cdef_string = str_replace("SIMILAR_DATA_SOURCES_NODUPS", $magic_item["SIMILAR_DATA_SOURCES_NODUPS"], $cdef_string);
}
/* COUNT_ALL|SIMILAR_DATA_SOURCES(NO)?DUPS are to be replaced here */
if (isset($magic_item["COUNT_ALL_DS_DUPS"])) {
$cdef_string = str_replace("COUNT_ALL_DS_DUPS", $magic_item["COUNT_ALL_DS_DUPS"], $cdef_string);
}
if (isset($magic_item["COUNT_ALL_DS_NODUPS"])) {
$cdef_string = str_replace("COUNT_ALL_DS_NODUPS", $magic_item["COUNT_ALL_DS_NODUPS"], $cdef_string);
}
if (isset($magic_item["COUNT_SIMILAR_DS_DUPS"])) {
$cdef_string = str_replace("COUNT_SIMILAR_DS_DUPS", $magic_item["COUNT_SIMILAR_DS_DUPS"], $cdef_string);
}
if (isset($magic_item["COUNT_SIMILAR_DS_NODUPS"])) {
$cdef_string = str_replace("COUNT_SIMILAR_DS_NODUPS", $magic_item["COUNT_SIMILAR_DS_NODUPS"], $cdef_string);
}
/* data source item variables */
$cdef_string = str_replace("CURRENT_DS_MINIMUM_VALUE", (empty($xport_item["rrd_minimum"]) ? "0" : $xport_item["rrd_minimum"]), $cdef_string);
$cdef_string = str_replace("CURRENT_DS_MAXIMUM_VALUE", (empty($xport_item["rrd_maximum"]) ? "0" : $xport_item["rrd_maximum"]), $cdef_string);
$cdef_string = str_replace("CURRENT_GRAPH_MINIMUM_VALUE", (empty($graph["lower_limit"]) ? "0" : $graph["lower_limit"]), $cdef_string);
$cdef_string = str_replace("CURRENT_GRAPH_MAXIMUM_VALUE", (empty($graph["upper_limit"]) ? "0" : $graph["upper_limit"]), $cdef_string);
/* replace query variables in cdefs */
$cdef_string = rrd_substitute_host_query_data($cdef_string, $graph, $xport_item);
/* make the initial "virtual" cdef name: 'cdef' + [a,b,c,d...] */
$cdef_xport_defs .= "CDEF:cdef" . generate_graph_def_name(strval($i)) . "=";
$cdef_xport_defs .= $cdef_string;
$cdef_xport_defs .= " \\\n";
/* the CDEF cache is so we do not create duplicate CDEF's on a graph */
$cdef_cache{$xport_item["cdef_id"]}{$xport_item["data_template_rrd_id"]}[$cf_id] = "$i";
}
/* add the cdef string to the end of the def string */
$xport_defs .= $cdef_xport_defs;
/* note the current item_id for easy access */
$xport_item_id = $xport_item["graph_templates_item_id"];
/* IF this graph item has a data source... get a DEF name for it, or the cdef if that applies
to this graph item */
if ($xport_item["cdef_id"] == "0") {
if (isset($cf_ds_cache{$xport_item["data_template_rrd_id"]}[$cf_id])) {
$data_source_name = generate_graph_def_name(strval($cf_ds_cache{$xport_item["data_template_rrd_id"]}[$cf_id]));
}else{
$data_source_name = "";
}
}else{
$data_source_name = "cdef" . generate_graph_def_name(strval($cdef_cache{$xport_item["cdef_id"]}{$xport_item["data_template_rrd_id"]}[$cf_id]));
}
/* +++++++++++++++++++++++ XPORT ITEMS +++++++++++++++++++++++ */
$need_rrd_nl = TRUE;
if (ereg("^(AREA|LINE[123]|STACK)$", $graph_item_types{$xport_item["graph_type_id"]})) {
/* give all export items a name */
if (trim($xport_variables["text_format"][$xport_item_id]) == "") {
$legend_name = "col" . $j . "-" . $data_source_name;
}else{
$legend_name = $xport_variables["text_format"][$xport_item_id];
}
$j++;
$txt_xport_items .= "XPORT:" . $data_source_name . ":" . "\"" . str_replace(":", "", $legend_name) . "\"";
}else{
$need_rrd_nl = FALSE;
}
$i++;
if (($i < sizeof($xport_items)) && ($need_rrd_nl)) {
$txt_xport_items .= RRD_NL;
}
}
}
$output_flag = RRDTOOL_OUTPUT_STDOUT;
$xport_array = rrdxport2array(rrdtool_execute("xport $xport_opts$xport_defs$txt_xport_items", false, $output_flag, $rrd_struc));
/* add host and graph information */
$xport_array["meta"]["title_cache"] = $graph["title_cache"];
$xport_array["meta"]["vertical_label"] = $graph["vertical_label"];
$xport_array["meta"]["local_graph_id"] = $local_graph_id;
$xport_array["meta"]["host_id"] = $graph["host_id"];
return $xport_array;
}
示例3: get_rrd_cfs
function get_rrd_cfs($local_data_id)
{
global $rrd_cfs, $consolidation_functions;
$rrdfile = get_data_source_path($local_data_id, TRUE);
if (!isset($rrd_cfs)) {
$rrd_cfs = array();
} else {
if (array_key_exists($local_data_id, $rrd_cfs)) {
return $rrd_cfs[$local_data_id];
}
}
$cfs = array();
$output = rrdtool_execute("info {$rrdfile}", FALSE, RRDTOOL_OUTPUT_STDOUT);
/* search for
* rra[0].cf = "LAST"
* or similar
*/
if (strlen($output)) {
$output = explode("\n", $output);
if (sizeof($output)) {
foreach ($output as $line) {
if (substr_count($line, ".cf")) {
$values = explode("=", $line);
if (!in_array(trim($values[1], '" '), $cfs)) {
$cfs[] = trim($values[1], '" ');
}
}
}
}
}
$new_cfs = array();
if (sizeof($cfs)) {
foreach ($cfs as $cf) {
switch ($cf) {
case "AVG":
case "AVERAGE":
$new_cfs[] = array_search('AVERAGE', $consolidation_functions);
break;
case "MIN":
$new_cfs[] = array_search('MIN', $consolidation_functions);
break;
case "MAX":
$new_cfs[] = array_search('MAX', $consolidation_functions);
break;
case "LAST":
$new_cfs[] = array_search('LAST', $consolidation_functions);
break;
}
}
}
$rrd_cfs[$local_data_id] = $new_cfs;
return $new_cfs;
}
示例4: rrdtool_function_graph
//.........这里部分代码省略.........
} elseif ($graph_item_types[$graph_item["graph_type_id"]] == "HRULE") {
$graph_variables["text_format"][$graph_item_id] = str_replace(":", "\\:", $graph_variables["text_format"][$graph_item_id]);
/* escape colons */
$graph_variables["value"][$graph_item_id] = str_replace(":", "\\:", $graph_variables["value"][$graph_item_id]);
/* escape colons */
/* perform variable substitution; if this does not return a number, rrdtool will FAIL! */
$substitute = rrd_substitute_host_query_data($graph_variables["value"][$graph_item_id], $graph, $graph_item);
if (is_numeric($substitute)) {
$graph_variables["value"][$graph_item_id] = $substitute;
}
$txt_graph_items .= $graph_item_types[$graph_item["graph_type_id"]] . ":" . $graph_variables["value"][$graph_item_id] . $graph_item_color_code . ":" . cacti_escapeshellarg($graph_variables["text_format"][$graph_item_id] . $hardreturn[$graph_item_id]) . " ";
} elseif ($graph_item_types[$graph_item["graph_type_id"]] == "VRULE") {
$graph_variables["text_format"][$graph_item_id] = str_replace(":", "\\:", $graph_variables["text_format"][$graph_item_id]);
/* escape colons */
if (substr_count($graph_item["value"], ":")) {
$value_array = explode(":", $graph_item["value"]);
if ($value_array[0] < 0) {
$value = date("U") - -3600 * $value_array[0] - 60 * $value_array[1];
} else {
$value = date("U", mktime($value_array[0], $value_array[1], 0));
}
} else {
if (is_numeric($graph_item["value"])) {
$value = $graph_item["value"];
}
}
$txt_graph_items .= $graph_item_types[$graph_item["graph_type_id"]] . ":" . $value . $graph_item_color_code . ":" . cacti_escapeshellarg($graph_variables["text_format"][$graph_item_id] . $hardreturn[$graph_item_id]) . " ";
}
} else {
$need_rrd_nl = FALSE;
}
} else {
if (preg_match("/^(AREA|LINE[123]|STACK)\$/", $graph_item_types[$graph_item["graph_type_id"]])) {
/* give all export items a name */
if (trim($graph_variables["text_format"][$graph_item_id]) == "") {
$legend_name = "col" . $j . "-" . $data_source_name;
} else {
$legend_name = $graph_variables["text_format"][$graph_item_id];
}
$stacked_columns["col" . $j] = $graph_item_types[$graph_item["graph_type_id"]] == "STACK" ? 1 : 0;
$j++;
$txt_graph_items .= "XPORT:" . cacti_escapeshellarg($data_source_name) . ":" . str_replace(":", "", cacti_escapeshellarg($legend_name));
} else {
$need_rrd_nl = FALSE;
}
}
$i++;
if ($i < sizeof($graph_items) && $need_rrd_nl) {
$txt_graph_items .= RRD_NL;
}
}
}
if (!isset($graph_data_array['export_csv']) || $graph_data_array['export_csv'] != true) {
$graph_array = api_plugin_hook_function('rrd_graph_graph_options', array('graph_opts' => $graph_opts, 'graph_defs' => $graph_defs, 'txt_graph_items' => $txt_graph_items, 'graph_id' => $local_graph_id, 'start' => $graph_start, 'end' => $graph_end));
if (!empty($graph_array)) {
$graph_defs = $graph_array['graph_defs'];
$txt_graph_items = $graph_array['txt_graph_items'];
$graph_opts = $graph_array['graph_opts'];
}
/* either print out the source or pass the source onto rrdtool to get us a nice PNG */
if (isset($graph_data_array["print_source"])) {
print "<PRE>" . htmlspecialchars(read_config_option("path_rrdtool") . " graph " . $graph_opts . $graph_defs . $txt_graph_items) . "</PRE>";
} else {
if (isset($graph_data_array["export"])) {
rrdtool_execute("graph {$graph_opts}{$graph_defs}{$txt_graph_items}", false, RRDTOOL_OUTPUT_NULL, $rrdtool_pipe);
return 0;
} elseif (isset($graph_data_array['export_realtime'])) {
$output_flag = RRDTOOL_OUTPUT_GRAPH_DATA;
$output = rrdtool_execute("graph {$graph_opts}{$graph_defs}{$txt_graph_items}", false, $output_flag, $rrdtool_pipe);
//cacti_log(str_replace(RRD_NL, ' ', "rrdtool graph $graph_opts$graph_defs$txt_graph_items"));
if ($fp = fopen($graph_data_array['export_realtime'], 'w')) {
fwrite($fp, $output, strlen($output));
fclose($fp);
chmod($graph_data_array['export_realtime'], 0644);
}
return $output;
} else {
$graph_data_array = boost_prep_graph_array($graph_data_array);
if (!isset($graph_data_array["output_flag"])) {
$output_flag = RRDTOOL_OUTPUT_GRAPH_DATA;
} else {
$output_flag = $graph_data_array["output_flag"];
}
$output = rrdtool_execute("graph {$graph_opts}{$graph_defs}{$txt_graph_items}", false, $output_flag, $rrdtool_pipe);
boost_graph_set_file($output, $local_graph_id, $rra_id);
return $output;
}
}
} else {
$output_flag = RRDTOOL_OUTPUT_STDOUT;
$xport_array = rrdxport2array(rrdtool_execute("xport {$graph_opts}{$graph_defs}{$txt_graph_items}", false, $output_flag));
/* add host and graph information */
$xport_array["meta"]["stacked_columns"] = $stacked_columns;
$xport_array["meta"]["title_cache"] = cacti_escapeshellarg($graph["title_cache"]);
$xport_array["meta"]["vertical_label"] = cacti_escapeshellarg($graph["vertical_label"]);
$xport_array["meta"]["local_graph_id"] = $local_graph_id;
$xport_array["meta"]["host_id"] = $graph["host_id"];
return $xport_array;
}
}
示例5: rrdtool_function_graph_rt
//.........这里部分代码省略.........
if ($graph_item_types{$graph_item["graph_type_id"]} == "COMMENT") {
if (read_config_option("rrdtool_version") != "rrd-1.0.x") {
$comment_string = $graph_item_types{$graph_item["graph_type_id"]} . ":\"" . str_replace(":", "\:", $graph_variables["text_format"][$graph_item_id]) . $hardreturn[$graph_item_id] . "\" ";
if (trim($comment_string) == 'COMMENT:"\n"') {
$txt_graph_items .= 'COMMENT:" \n"'; # rrdtool will skip a COMMENT that holds a NL only; so add a blank to make NL work
} else if (trim($comment_string) != "COMMENT:\"\"") {
$txt_graph_items .= rrd_substitute_host_query_data($comment_string, $graph, $graph_item);
}
}else {
$comment_string = $graph_item_types{$graph_item["graph_type_id"]} . ":\"" . $graph_variables["text_format"][$graph_item_id] . $hardreturn[$graph_item_id] . "\" ";
if (trim($comment_string) == 'COMMENT:"\n"') {
$txt_graph_items .= 'COMMENT:" \n"'; # rrdtool will skip a COMMENT that holds a NL only; so add a blank to make NL work
} else if (trim($comment_string) != "COMMENT:\"\"") {
$txt_graph_items .= rrd_substitute_host_query_data($comment_string, $graph, $graph_item);
}
}
}elseif (($graph_item_types{$graph_item["graph_type_id"]} == "GPRINT") && (!isset($graph_data_array["graph_nolegend"]))) {
$graph_variables["text_format"][$graph_item_id] = str_replace(":", "\:", $graph_variables["text_format"][$graph_item_id]); /* escape colons */
$txt_graph_items .= $graph_item_types{$graph_item["graph_type_id"]} . ":" . $data_source_name . ":" . $consolidation_functions{$graph_item["consolidation_function_id"]} . ":\"$text_padding" . $graph_variables["text_format"][$graph_item_id] . $graph_item["gprint_text"] . $hardreturn[$graph_item_id] . "\" ";
}elseif (ereg("^(AREA|LINE[123]|STACK|HRULE|VRULE)$", $graph_item_types{$graph_item["graph_type_id"]})) {
/* initialize any color syntax for graph item */
if (empty($graph_item["hex"])) {
$graph_item_color_code = "";
}else{
$graph_item_color_code = "#" . $graph_item["hex"];
if (read_config_option("rrdtool_version") != "rrd-1.0.x") {
$graph_item_color_code .= $graph_item["alpha"];
}
}
if (ereg("^(AREA|LINE[123])$", $graph_item_types{$graph_item["graph_type_id"]})) {
$graph_item_stack_type = $graph_item_types{$graph_item["graph_type_id"]};
$graph_variables["text_format"][$graph_item_id] = str_replace(":", "\:", $graph_variables["text_format"][$graph_item_id]); /* escape colons */
$txt_graph_items .= $graph_item_types{$graph_item["graph_type_id"]} . ":" . $data_source_name . $graph_item_color_code . ":" . "\"" . $graph_variables["text_format"][$graph_item_id] . $hardreturn[$graph_item_id] . "\" ";
}elseif ($graph_item_types{$graph_item["graph_type_id"]} == "STACK") {
if (read_config_option("rrdtool_version") != "rrd-1.0.x") {
$graph_variables["text_format"][$graph_item_id] = str_replace(":", "\:", $graph_variables["text_format"][$graph_item_id]); /* escape colons */
$txt_graph_items .= $graph_item_stack_type . ":" . $data_source_name . $graph_item_color_code . ":" . "\"" . $graph_variables["text_format"][$graph_item_id] . $hardreturn[$graph_item_id] . "\":STACK";
}else {
$graph_variables["text_format"][$graph_item_id] = str_replace(":", "\:", $graph_variables["text_format"][$graph_item_id]); /* escape colons */
$txt_graph_items .= $graph_item_types{$graph_item["graph_type_id"]} . ":" . $data_source_name . $graph_item_color_code . ":" . "\"" . $graph_variables["text_format"][$graph_item_id] . $hardreturn[$graph_item_id] . "\" ";
}
}elseif ($graph_item_types{$graph_item["graph_type_id"]} == "HRULE") {
$graph_variables["text_format"][$graph_item_id] = str_replace(":", "\:", $graph_variables["text_format"][$graph_item_id]); /* escape colons */
$graph_variables["value"][$graph_item_id] = str_replace(":", "\:", $graph_variables["value"][$graph_item_id]); /* escape colons */
/* perform variable substitution; if this does not return a number, rrdtool will FAIL! */
$substitute = rrd_substitute_host_query_data($graph_variables["value"][$graph_item_id], $graph, $graph_item);
if (is_numeric($substitute)) {
$graph_variables["value"][$graph_item_id] = trim($substitute);
}
$txt_graph_items .= $graph_item_types{$graph_item["graph_type_id"]} . ":" . $graph_variables["value"][$graph_item_id] . $graph_item_color_code . ":\"" . $graph_variables["text_format"][$graph_item_id] . $hardreturn[$graph_item_id] . "\" ";
}elseif ($graph_item_types{$graph_item["graph_type_id"]} == "VRULE") {
$graph_variables["text_format"][$graph_item_id] = str_replace(":", "\:", $graph_variables["text_format"][$graph_item_id]); /* escape colons */
if (substr_count($graph_item["value"], ":")) {
$value_array = explode(":", $graph_item["value"]);
if ($value_array[0] < 0) {
$value = date("U") - (-3600 * $value_array[0]) - 60 * $value_array[1];
}else{
$value = date("U", mktime($value_array[0],$value_array[1],0));
}
}else if (is_numeric($graph_item["value"])) {
$value = $graph_item["value"];
}
$txt_graph_items .= $graph_item_types{$graph_item["graph_type_id"]} . ":" . $value . $graph_item_color_code . ":\"" . $graph_variables["text_format"][$graph_item_id] . $hardreturn[$graph_item_id] . "\" ";
}
}else{
$need_rrd_nl = FALSE;
}
$i++;
if (($i < sizeof($graph_items)) && ($need_rrd_nl)) {
$txt_graph_items .= RRD_NL;
}
}
}
/* either print out the source or pass the source onto rrdtool to get us a nice PNG */
if (isset($graph_data_array["print_source"])) {
print "<PRE>" . read_config_option("path_rrdtool") . " graph $graph_opts$graph_defs$txt_graph_items</PRE>";
}else{
if (isset($graph_data_array["export"])) {
@rrdtool_execute("graph $graph_opts$graph_defs$txt_graph_items", false, RRDTOOL_OUTPUT_NULL);
return 0;
}else{
if (isset($graph_data_array["output_flag"])) {
$output_flag = $graph_data_array["output_flag"];
}else{
$output_flag = RRDTOOL_OUTPUT_GRAPH_DATA;
}
return @rrdtool_execute("graph $graph_opts$graph_defs$txt_graph_items", false, $output_flag);
}
}
}
示例6: api_rrd_datasource_add
/**
* add a (list of) datasource(s) to an (array of) rrd file(s)
* @param array $file_array - array of rrd files
* @param array $ds_array - array of datasouce parameters
* @param bool $debug - debug mode
* returns mixed - success (bool) or error message (array)
*/
function api_rrd_datasource_add($file_array, $ds_array, $debug) {
require_once(CACTI_BASE_PATH."/lib/rrd.php");
require(CACTI_BASE_PATH . "/include/data_source/data_source_arrays.php");
#print_r($ds_array);
$rrd_struc = array();
/* iterate all given rrd files */
foreach($file_array as $file) {
/* create a DOM object from an rrdtool dump */
$dom = new domDocument;
$dom->loadXML(rrdtool_execute("dump $file", false, RRDTOOL_OUTPUT_STDOUT, $rrd_struc, 'UTIL'));
if (!$dom) {
$check["err_msg"] = __('Error while parsing the XML of rrdtool dump');
return $check;
}
/* rrdtool dump depends on rrd file version:
* version 0001 => RRDTool 1.0.x
* version 0003 => RRDTool 1.2.x, 1.3.x, 1.4.x
*/
$version = trim($dom->getElementsByTagName('version')->item(0)->nodeValue);
/* now start XML processing */
foreach($ds_array as $ds) {
/* first, append the <DS> strcuture in the rrd header */
if ($ds['type'] === $data_source_types[DATA_SOURCE_TYPE_COMPUTE]) {
append_COMPUTE_DS($dom, $version, $ds['name'], $ds['type'], $ds['cdef']);
}else {
append_DS($dom, $version, $ds['name'], $ds['type'], $ds['heartbeat'], $ds['min'], $ds['max']);
}
/* now work on the <DS> structure as part of the <cdp_prep> tree */
append_CDP_Prep_DS($dom, $version);
/* add <V>alues to the <database> tree */
append_Value($dom);
}
if($debug) {
echo $dom->saveXML();
}else {
/* for rrdtool restore, we need a file, so write the XML to disk */
$xml_file = $file . '.xml';
$rc = $dom->save($xml_file);
/* verify, if write was successful */
if ($rc === false) {
$check["err_msg"] = __('ERROR while writing XML file: %s', $xml_file);
return $check;
}else {
/* are we allowed to write the rrd file? */
if (is_writable($file)) {
/* restore the modified XML to rrd */
rrdtool_execute("restore -f $xml_file $file", false, RRDTOOL_OUTPUT_STDOUT, $rrd_struc, 'UTIL');
/* scratch that XML file to avoid filling up the disk */
unlink($xml_file);
cacti_log(__("Added datasource(s) to rrd file: %s", $file), false, 'UTIL');
}else {
$check["err_msg"] = __('ERROR: RRD file %s not writeable', $file);
return $check;
}
}
}
}
return true;
}
示例7: get_rrd_cfs
function get_rrd_cfs($local_data_id) {
global $rrd_cfs;
require(CACTI_BASE_PATH . "/include/presets/preset_rra_arrays.php");
$rrdfile = get_data_source_path($local_data_id, TRUE);
if (!isset($rrd_cfs)) {
$rrd_cfs = array();
}else if (array_key_exists($local_data_id, $rrd_cfs)) {
return $rrd_cfs[$local_data_id];
}
$cfs = array();
$output = rrdtool_execute("info $rrdfile", FALSE, RRDTOOL_OUTPUT_STDOUT);
/* search for
* rra[0].cf = "LAST"
* or similar
*/
if (strlen($output)) {
$output = explode("\n", $output);
if (sizeof($output)) {
foreach($output as $line) {
if (substr_count($line, ".cf")) {
$values = explode("=",$line);
if (!in_array(trim($values[1]), $cfs)) {
$cfs[] = trim($values[1], '" ');
}
}
}
}
}
$new_cfs = array();
if (sizeof($cfs)) {
foreach($cfs as $cf) {
$new_cfs[] = array_search($cf, $consolidation_functions);
}
}
$rrd_cfs[$local_data_id] = $new_cfs;
return $new_cfs;
}
示例8: thold_rrd_last
function thold_rrd_last($rra)
{
global $config;
$last_time_entry = @rrdtool_execute('last ' . trim(get_data_source_path($rra, true)), false, RRDTOOL_OUTPUT_STDOUT);
return trim($last_time_entry);
}
示例9: rrdtool_function_info
function rrdtool_function_info($data_source_id) {
global $config;
/* Get the path to rrdtool file */
$data_source_path = get_data_source_path($data_source_id, true);
/* Execute rrdtool info command */
$cmd_line = " info " . $data_source_path;
$output = rrdtool_execute($cmd_line, RRDTOOL_OUTPUT_NULL, RRDTOOL_OUTPUT_STDOUT);
if (sizeof($output) == 0) {
return false;
}
/* Parse the output */
$matches = array();
$rrd_info = array( 'rra' => array(), "ds" => array() );
$output = explode("\n", $output);
foreach ($output as $line) {
$line = trim($line);
if (preg_match("/^ds\[(\S+)\]\.(\S+) = (\S+)$/", $line, $matches)) {
$rrd_info["ds"][$matches[1]][$matches[2]] = $matches[3];
} elseif (preg_match("/^rra\[(\S+)\]\.(\S+)\[(\S+)\]\.(\S+) = (\S+)$/", $line, $matches)) {
$rrd_info['rra'][$matches[1]][$matches[2]][$matches[3]][$matches[4]] = $matches[5];
} elseif (preg_match("/^rra\[(\S+)\]\.(\S+) = (\S+)$/", $line, $matches)) {
$rrd_info['rra'][$matches[1]][$matches[2]] = $matches[3];
} elseif (preg_match("/^(\S+) = \"(\S+)\"$/", $line, $matches)) {
$rrd_info[$matches[1]] = $matches[2];
} elseif (preg_match("/^(\S+) = (\S+)$/", $line, $matches)) {
$rrd_info[$matches[1]] = $matches[2];
}
}
$output = "";
$matches = array();
/* Return parsed values */
return $rrd_info;
}
示例10: dsstats_obtain_data_source_avgpeak_values
function dsstats_obtain_data_source_avgpeak_values($rrdfile, $interval, $pipes)
{
global $config;
/* don't attempt to get information if the file does not exist */
if (file_exists($rrdfile)) {
/* high speed or snail speed */
if (read_config_option("dsstats_rrdtool_pipe") == "on") {
$info = dsstats_rrdtool_execute("info {$rrdfile}", $pipes);
} else {
$info = rrdtool_execute("info {$rrdfile}", false, RRDTOOL_OUTPUT_STDOUT);
}
/* don't do anything if RRDfile did not return data */
if ($info != "") {
$info_array = explode("\n", $info);
$average = FALSE;
$max = FALSE;
$dsnames = array();
/* figure out whatis in this RRDfile. Assume CF Uniformity as Cacti does not allow async rrdfiles.
* also verify the consolidation functions in the RRDfile for average and max calculations.
*/
if (sizeof($info_array)) {
foreach ($info_array as $line) {
if (substr_count($line, "ds[")) {
$parts = explode("]", $line);
$parts2 = explode("[", $parts[0]);
$dsnames[trim($parts2[1])] = 1;
} else {
if (substr_count($line, ".cf")) {
$parts = explode("=", $line);
if (substr_count($parts[1], "AVERAGE")) {
$average = TRUE;
} elseif (substr_count($parts[1], "MAX")) {
$max = TRUE;
}
} else {
if (substr_count($line, "step")) {
$parts = explode("=", $line);
$poller_interval = trim($parts[1]);
}
}
}
}
}
/* create the command syntax to get data */
/* assume that an RRDfile has not more than 62 data sources */
$defs = "abcdefghijklmnopqrstuvwzyz012345789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$i = 0;
$def = "";
$xport = "";
$dsvalues = array();
/* escape the file name if on Windows */
if ($config["cacti_server_os"] != "unix") {
$rrdfile = str_replace(":", "\\:", $rrdfile);
}
/* setup the export command by parsing throught the internal data source names */
if (sizeof($dsnames)) {
foreach ($dsnames as $dsname => $present) {
if ($average) {
$def .= "DEF:" . $defs[$i] . "=\"" . $rrdfile . "\":" . $dsname . ":AVERAGE ";
$xport .= " XPORT:" . $defs[$i];
$i++;
}
if ($max) {
$def .= "DEF:" . $defs[$i] . "=\"" . $rrdfile . "\":" . $dsname . ":MAX ";
$xport .= " XPORT:" . $defs[$i];
$i++;
}
}
}
/* change the interval to something RRDtool understands */
switch ($interval) {
case "daily":
$interval = "day";
break;
case "weekly":
$interval = "week";
break;
case "monthly":
$interval = "month";
break;
case "yearly":
$interval = "year";
break;
}
/* now execute the xport command */
$xport_cmd = "xport --start now-1" . $interval . " --end now " . trim($def) . " " . trim($xport) . " --maxrows 10";
if (read_config_option("dsstats_rrdtool_pipe") == "on") {
$xport_data = dsstats_rrdtool_execute($xport_cmd, $pipes);
} else {
$xport_data = rrdtool_execute($xport_cmd, false, RRDTOOL_OUTPUT_STDOUT);
}
/* initialize the array of return values */
foreach ($dsnames as $dsname => $present) {
$dsvalues[$dsname]["AVG"] = 0;
$dsvalues[$dsname]["AVGCNT"] = 0;
$dsvalues[$dsname]["MAX"] = 0;
}
/* process the xport array and return average and peak values */
if ($xport_data != "") {
$xport_array = explode("\n", $xport_data);
//.........这里部分代码省略.........
示例11: thold_rrd_last
function thold_rrd_last($local_data_id)
{
$last_time_entry = @rrdtool_execute('last ' . trim(get_data_source_path($local_data_id, true)), false, RRDTOOL_OUTPUT_STDOUT);
return trim($last_time_entry);
}
示例12: strtotime
print " </TR>\n";
// Time values
$start = strtotime($date_start);
$end = strtotime($date_end);
$start_a = $start - $units * $tspan;
// Display colors/types
$disp_a = "{$type_ds}:a#{$col_ds}";
$disp_pred = "{$type_pred}:predict#{$col_pred}";
// Must increment unit (current timespan is included)
$units = $units + 1;
// For windows users (Thank you Praveen Kumar)
$ds_name = str_replace(" ", "", $ds_name);
$ds_var = str_replace(" ", "", $ds_var);
// Build graph options
$gr_ops = "--imgformat=PNG --title='{$ds_name}/{$ds_var}' --height={$height} --width={$width} --alt-autoscale-max --slope-mode --start={$start} --end={$end} DEF:a=\"{$ds_path}\":{$ds_var}:AVERAGE:start={$start_a} {$disp_a}:'采集数据' CDEF:predict={$tspan},-{$units},{$win},a,PREDICT {$disp_pred}:'预测值'";
@rrdtool_execute("graph {$file_abs} {$gr_ops}", true, RRDTOOL_OUTPUT_NULL);
print " <TR>\n";
print " <TD>\n";
print ' <IMG src="' . $file_rel . '" alt="">';
print " </TD>\n";
print " </TR>\n";
print "<TR class='textHeaderDark' style='color:white;font-size=12px;background-color:#00438C;line-height:120%;'><TD>二维预测算法</TD></TR>";
$src = $config['url_path'] . "graph_image.php?local_graph_id=45&rra_id=0&graph_height=" . $height . "&graph_width=" . $width . "&title_font_size=10&view_type=tree&graph_start=" . $start . "&graph_end=" . $end;
print " <TR>\n";
print " <TD>\n";
print ' <IMG src="' . $src . '">';
print " </TD>\n";
print " </TR>\n";
print "</TABLE>\n";
}
?>
示例13: rrdtool_function_xport
//.........这里部分代码省略.........
$cdef_total_ds = "";
$cdef_similar_ds = "";
if (!empty($xport_item["cdef_id"]) && !isset($cdef_cache[$xport_item["cdef_id"]][$xport_item["data_template_rrd_id"]][$cf_id])) {
$cdef_string = $xport_variables["cdef_cache"][$xport_item["graph_templates_item_id"]];
/* create cdef string for "total all data sources" if requested */
if (ereg("ALL_DATA_SOURCES_(NO)?DUPS", $cdef_string)) {
$item_count = 0;
for ($t = 0; $t < count($xport_items); $t++) {
if (ereg("(AREA|STACK|LINE[123])", $graph_item_types[$xport_items[$t]["graph_type_id"]]) && !empty($xport_items[$t]["data_template_rrd_id"])) {
/* if the user screws up CF settings, PHP will generate warnings if left unchecked */
if (isset($cf_ds_cache[$xport_items[$t]["data_template_rrd_id"]][$cf_id])) {
$def_name = generate_graph_def_name(strval($cf_ds_cache[$xport_items[$t]["data_template_rrd_id"]][$cf_id]));
$cdef_total_ds .= ($item_count == 0 ? "" : ",") . "TIME," . (time() - $seconds_between_graph_updates) . ",GT,{$def_name},{$def_name},UN,0,{$def_name},IF,IF";
/* convert unknowns to '0' first */
$item_count++;
}
}
}
/* if there is only one item to total, don't even bother with the summation. otherwise
cdef=a,b,c,+,+ is fine. */
if ($item_count > 1) {
$cdef_total_ds .= str_repeat(",+", $item_count - 2) . ",+";
}
}
/* create cdef string for "total similar data sources" if requested */
if (ereg("SIMILAR_DATA_SOURCES_(NO)?DUPS", $cdef_string)) {
$sources_seen = array();
$item_count = 0;
for ($t = 0; $t < count($xport_items); $t++) {
if (ereg("(AREA|STACK|LINE[123])", $graph_item_types[$xport_items[$t]["graph_type_id"]]) && !empty($xport_items[$t]["data_template_rrd_id"]) && $xport_item["data_source_name"] == $xport_items[$t]["data_source_name"]) {
/* if the user screws up CF settings, PHP will generate warnings if left unchecked */
if (isset($cf_ds_cache[$xport_items[$t]["data_template_rrd_id"]][$cf_id]) && !isset($sources_seen[$xport_items[$t]["data_template_rrd_id"]])) {
$def_name = generate_graph_def_name(strval($cf_ds_cache[$xport_items[$t]["data_template_rrd_id"]][$cf_id]));
$cdef_similar_ds .= ($item_count == 0 ? "" : ",") . "TIME," . (time() - $seconds_between_graph_updates) . ",GT,{$def_name},{$def_name},UN,0,{$def_name},IF,IF";
/* convert unknowns to '0' first */
$sources_seen[$xport_items[$t]["data_template_rrd_id"]] = 1;
$item_count++;
}
}
}
/* if there is only one item to total, don't even bother with the summation. otherwise
cdef=a,b,c,+,+ is fine. */
if ($item_count > 1) {
$cdef_similar_ds .= str_repeat(",+", $item_count - 2) . ",+";
}
}
$cdef_string = str_replace("CURRENT_DATA_SOURCE", generate_graph_def_name(strval(isset($cf_ds_cache[$xport_item["data_template_rrd_id"]][$cf_id]) ? $cf_ds_cache[$xport_item["data_template_rrd_id"]][$cf_id] : "0")), $cdef_string);
$cdef_string = str_replace("ALL_DATA_SOURCES_NODUPS", $cdef_total_ds, $cdef_string);
$cdef_string = str_replace("SIMILAR_DATA_SOURCES_NODUPS", $cdef_similar_ds, $cdef_string);
/* data source item variables */
$cdef_string = str_replace("CURRENT_DS_MINIMUM_VALUE", empty($xport_item["rrd_minimum"]) ? "0" : $xport_item["rrd_minimum"], $cdef_string);
$cdef_string = str_replace("CURRENT_DS_MAXIMUM_VALUE", empty($xport_item["rrd_maximum"]) ? "0" : $xport_item["rrd_maximum"], $cdef_string);
$cdef_string = str_replace("CURRENT_GRAPH_MINIMUM_VALUE", empty($graph["lower_limit"]) ? "0" : $graph["lower_limit"], $cdef_string);
$cdef_string = str_replace("CURRENT_GRAPH_MAXIMUM_VALUE", empty($graph["upper_limit"]) ? "0" : $graph["upper_limit"], $cdef_string);
/* replace query variables in cdefs */
$cdef_string = rrd_substitute_host_query_data($cdef_string, $graph, $xport_item);
/* make the initial "virtual" cdef name: 'cdef' + [a,b,c,d...] */
$cdef_xport_defs .= "CDEF:cdef" . generate_graph_def_name(strval($i)) . "=";
$cdef_xport_defs .= $cdef_string;
$cdef_xport_defs .= " \\\n";
/* the CDEF cache is so we do not create duplicate CDEF's on a graph */
$cdef_cache[$xport_item["cdef_id"]][$xport_item["data_template_rrd_id"]][$cf_id] = "{$i}";
}
/* add the cdef string to the end of the def string */
$xport_defs .= $cdef_xport_defs;
/* note the current item_id for easy access */
$xport_item_id = $xport_item["graph_templates_item_id"];
/* IF this graph item has a data source... get a DEF name for it, or the cdef if that applies
to this graph item */
if ($xport_item["cdef_id"] == "0") {
if (isset($cf_ds_cache[$xport_item["data_template_rrd_id"]][$cf_id])) {
$data_source_name = generate_graph_def_name(strval($cf_ds_cache[$xport_item["data_template_rrd_id"]][$cf_id]));
} else {
$data_source_name = "";
}
} else {
$data_source_name = "cdef" . generate_graph_def_name(strval($cdef_cache[$xport_item["cdef_id"]][$xport_item["data_template_rrd_id"]][$cf_id]));
}
/* +++++++++++++++++++++++ XPORT ITEMS +++++++++++++++++++++++ */
$need_rrd_nl = TRUE;
if (ereg("^(AREA|LINE[123]|STACK)\$", $graph_item_types[$xport_item["graph_type_id"]])) {
$txt_xport_items .= "XPORT:" . $data_source_name . ":" . "\"" . $xport_variables["text_format"][$xport_item_id] . "\"";
} else {
$need_rrd_nl = FALSE;
}
$i++;
if ($i < sizeof($xport_items) && $need_rrd_nl) {
$txt_xport_items .= RRD_NL;
}
}
}
$output_flag = RRDTOOL_OUTPUT_STDOUT;
$xport_array = rrdxport2array(rrdtool_execute("xport {$xport_opts}{$xport_defs}{$txt_xport_items}", false, $output_flag, $rrd_struc));
/* add host and graph information */
$xport_array["meta"]["title_cache"] = $graph["title_cache"];
$xport_array["meta"]["vertical_label"] = $graph["vertical_label"];
$xport_array["meta"]["local_graph_id"] = $local_graph_id;
$xport_array["meta"]["host_id"] = $graph["host_id"];
return $xport_array;
}