当前位置: 首页>>代码示例>>PHP>>正文


PHP rrd_init函数代码示例

本文整理汇总了PHP中rrd_init函数的典型用法代码示例。如果您正苦于以下问题:PHP rrd_init函数的具体用法?PHP rrd_init怎么用?PHP rrd_init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了rrd_init函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: export_build_graphs

function export_build_graphs($fp, $path, $tree_id, $parent_tree_item_id)  {
	/* start the count of graphs */
	$total_graphs_created = 0;

	$cacti_export_path = read_config_option("path_html_export");

	$req="";
	if (get_tree_item_type($parent_tree_item_id)=="host")  {
		$req="select distinct
				graph_templates_graph.id,
				graph_templates_graph.local_graph_id,
				graph_templates_graph.height,
				graph_templates_graph.width,
				graph_templates_graph.title_cache,
				graph_templates.name,
				graph_local.host_id
			from graph_templates_graph
				left join graph_templates on (graph_templates_graph.graph_template_id=graph_templates.id)
			    left join graph_local on (graph_templates_graph.local_graph_id=graph_local.id)
			where graph_local.host_id=".get_host_id($parent_tree_item_id)."
			  and graph_templates_graph.local_graph_id!=0
			  and graph_templates_graph.export='on'
			order by graph_templates_graph.title_cache";
	}else {
		/* searching for the graph_tree_items of the tree_id which are graphs */
		$req="select distinct
				graph_templates_graph.id,
				graph_templates_graph.local_graph_id,
				graph_templates_graph.height,
				graph_templates_graph.width,
				graph_templates_graph.title_cache,
				graph_templates.name,
				graph_local.host_id,
				graph_tree_items.id as gtid
			from graph_templates_graph
				left join graph_tree_items on (graph_templates_graph.local_graph_id=graph_tree_items.local_graph_id)
			    left join graph_templates on (graph_templates_graph.graph_template_id=graph_templates.id)
			    left join graph_local on (graph_templates_graph.local_graph_id=graph_local.id)
			where graph_tree_items.graph_tree_id =".$tree_id."
			  and graph_templates_graph.local_graph_id!=0
			  and graph_templates_graph.export='on'
			order by graph_templates_graph.title_cache";
	}

	$graphs=db_fetch_assoc($req);
	$rras = db_fetch_assoc("select
		rra.id,
		rra.name
		from rra
		order by timespan");

	/* open a pipe to rrdtool for writing */
	$rrdtool_pipe = rrd_init();

	/* for each graph... */
	$i = 0;
	foreach($graphs as $graph)  {
		/* this test gives us the graph_tree_items which are just under the parent_graph_tree_item */
		if (((get_tree_item_type($parent_tree_item_id)=="header") || ($parent_tree_item_id == 0)) && (get_parent_id($graph["gtid"], "graph_tree_items","graph_tree_id = ".$tree_id) != $parent_tree_item_id))  {
			/* do nothing */
		}else {
			/* settings for preview graphs */
			$graph_data_array["graph_height"] = "100";
			$graph_data_array["graph_width"] = "300";
			$graph_data_array["graph_nolegend"] = true;
			$graph_data_array["export"] = true;
			$graph_data_array["export_filename"] = "'".$path."'/thumb_".$graph["local_graph_id"].".png";

			rrdtool_function_graph($graph["local_graph_id"], 0, $graph_data_array, $rrdtool_pipe);
			$total_graphs_created++;

			/* generate html files for each graph */
			$fp_graph_index = fopen($cacti_export_path."/".$path."/graph_".$graph["local_graph_id"].".html", "w");
			fwrite($fp_graph_index, HTML_HEADER_TREE);
			draw_html_left_tree($fp_graph_index,$tree_id);
			fwrite($fp_graph_index, HTML_GRAPH_HEADER_ONE_TREE);
			fwrite($fp_graph_index, "<strong>Graph - " . $graph["title_cache"] . "</strong>");
			fwrite($fp_graph_index, HTML_GRAPH_HEADER_TWO);
			fwrite($fp_graph_index, "<td>");

			/* reset vars for actual graph image creation */
			reset($rras);
			unset($graph_data_array);

			/* generate graphs for each rra */
			foreach ($rras as $rra) {
				$graph_data_array["export"] = true;
				$graph_data_array["export_filename"] = "'".$path."'/graph_".$graph["local_graph_id"]."_".$rra["id"].".png";

				rrdtool_function_graph($graph["local_graph_id"], $rra["id"], $graph_data_array, $rrdtool_pipe);
				$total_graphs_created++;

				/* write image related html */
				fwrite($fp_graph_index, "<div align=center><img src='graph_".$graph["local_graph_id"]."_".$rra["id"].".png' border=0></div>\n
					<div align=center><strong>".$rra["name"]."</strong></div><br>");
			}

			fwrite($fp_graph_index, "</tr></table>");
			fwrite($fp_graph_index, HTML_FOOTER_TREE);
			fclose($fp_graph_index);
//.........这里部分代码省略.........
开发者ID:songchin,项目名称:Cacti,代码行数:101,代码来源:graph_export.php

示例2: list

	case "--help":
		display_help();
		exit;
	default:
		print "ERROR: Invalid Parameter " . $parameter . "\n\n";
		display_help();
		exit;
	}
}

/* record the start time */
list($micro,$seconds) = split(" ", microtime());
$start = $seconds + $micro;

/* open a pipe to rrdtool for writing */
$rrdtool_pipe = rrd_init();

$rrds_processed = 0;

while (db_fetch_cell("SELECT count(*) FROM poller_output") > 0) {
	$rrds_processed = $rrds_processed + process_poller_output($rrdtool_pipe, FALSE);
}

echo "There were $rrds_processed, RRD updates made this pass\n";

rrd_close($rrdtool_pipe);

/*	display_help - displays the usage of the function */
function display_help () {
	print "Cacti Empty Poller Output Table Script 1.0, Copyright 2007 - The Cacti Group\n\n";
	print "usage: poller_output_empty.php [-h] [--help] [-v] [--version]\n\n";
开发者ID:songchin,项目名称:Cacti,代码行数:31,代码来源:poller_output_empty.php

示例3: rrdtool_execute

function rrdtool_execute($command_line, $log_to_stdout, $output_flag, &$rrd_struc = array(), $logopt = "WEBLOG") {
	global $config;

	if (!is_numeric($output_flag)) {
		$output_flag = RRDTOOL_OUTPUT_STDOUT;
	}

	/* WIN32: before sending this command off to rrdtool, get rid
	of all of the '\' characters. Unix does not care; win32 does.
	Also make sure to replace all of the fancy \'s at the end of the line,
	but make sure not to get rid of the "\n"'s that are supposed to be
	in there (text format) */
	$command_line = str_replace("\\\n", " ", $command_line);

	/* output information to the log file if appropriate */
	if (read_config_option("log_verbosity") >= POLLER_VERBOSITY_DEBUG) {
		cacti_log("CACTI2RRD: " . read_config_option("path_rrdtool") . " $command_line", $log_to_stdout, $logopt);
	}

	/* if we want to see the error output from rrdtool; make sure to specify this */
	if (($output_flag == RRDTOOL_OUTPUT_STDERR) && (sizeof($rrd_struc) == 0)) {
		$command_line .= " 2>&1";
	}

	/* use popen to eliminate the zombie issue */
	if ($config["cacti_server_os"] == "unix") {
		/* an empty $rrd_struc array means no fp is available */
		if (sizeof($rrd_struc) == 0) {
			session_write_close();
			$fp = popen(read_config_option("path_rrdtool") . escape_command(" $command_line"), "r");
		}else{
			$i = 0;

			while (1) {
				if (fwrite(rrd_get_fd($rrd_struc, RRDTOOL_PIPE_CHILD_READ), escape_command(" $command_line") . "\r\n") == false) {
					cacti_log("ERROR: Detected RRDtool Crash attempting to perform write");

					/* close the invalid pipe */
					rrd_close($rrd_struc);

					/* open a new rrdtool process */
					$rrd_struc = rrd_init();

					if ($i > 4) {
						cacti_log("FATAL: RRDtool Restart Attempts Exceeded.  Giving up on command.");

						break;
					}else{
						$i++;
					}

					continue;
				}else{
					fflush(rrd_get_fd($rrd_struc, RRDTOOL_PIPE_CHILD_READ));

					break;
				}
			}
		}
	}elseif ($config["cacti_server_os"] == "win32") {
		/* an empty $rrd_struc array means no fp is available */
		if (sizeof($rrd_struc) == 0) {
			session_write_close();
			$fp = popen(read_config_option("path_rrdtool") . escape_command(" $command_line"), "rb");
		}else{
			$i = 0;

			while (1) {
				if (fwrite(rrd_get_fd($rrd_struc, RRDTOOL_PIPE_CHILD_READ), escape_command(" $command_line") . "\r\n") == false) {
					cacti_log("ERROR: Detected RRDtool Crash attempting to perform write");

					/* close the invalid pipe */
					rrd_close($rrd_struc);

					/* open a new rrdtool process */
					$rrd_struc = rrd_init();

					if ($i > 4) {
						cacti_log("FATAL: RRDtool Restart Attempts Exceeded.  Giving up on command.");

						break;
					}else{
						$i++;
					}

					continue;
				}else{
					fflush(rrd_get_fd($rrd_struc, RRDTOOL_PIPE_CHILD_READ));

					break;
				}
			}
		}
	}

	switch ($output_flag) {
		case RRDTOOL_OUTPUT_NULL:
			return; break;
		case RRDTOOL_OUTPUT_STDOUT:
			if (isset($fp)) {
//.........这里部分代码省略.........
开发者ID:songchin,项目名称:Cacti,代码行数:101,代码来源:rrd.php

示例4: boost_rrdtool_execute_internal

function boost_rrdtool_execute_internal($command_line, $log_to_stdout, $output_flag, $logopt = "WEBLOG")
{
    global $config, $rrdtool_pipe;
    static $last_command;
    if (!is_numeric($output_flag)) {
        $output_flag = RRDTOOL_OUTPUT_STDOUT;
    }
    /* WIN32: before sending this command off to rrdtool, get rid
    	of all of the '\' characters. Unix does not care; win32 does.
    	Also make sure to replace all of the fancy \'s at the end of the line,
    	but make sure not to get rid of the "\n"'s that are supposed to be
    	in there (text format) */
    $command_line = str_replace("\\\n", " ", $command_line);
    /* output information to the log file if appropriate */
    if (read_config_option("log_verbosity") >= POLLER_VERBOSITY_DEBUG) {
        cacti_log("CACTI2RRD: " . read_config_option("path_rrdtool") . " {$command_line}", $log_to_stdout, $logopt);
    }
    /* if we want to see the error output from rrdtool; make sure to specify this */
    if ($output_flag == RRDTOOL_OUTPUT_STDERR) {
        if (!(is_resource($rrdtool_pipe) || is_array($rrdtool_pipe))) {
            $command_line .= " 2>&1";
        }
    }
    /* an empty $rrdtool_pipe resource or no array means no fd is available */
    if (!(is_resource($rrdtool_pipe) || is_array($rrdtool_pipe))) {
        if ($config["cacti_server_os"] == "unix") {
            $popen_type = "r";
        } else {
            $popen_type = "rb";
        }
        session_write_close();
        $fp = popen(read_config_option("path_rrdtool") . escape_command(" {$command_line}"), $popen_type);
    } else {
        $i = 0;
        while (1) {
            if (function_exists("rrd_get_fd")) {
                $fd = rrd_get_fd($rrdtool_pipe, RRDTOOL_PIPE_CHILD_READ);
            } else {
                $fd = $rrdtool_pipe;
            }
            if (fwrite($fd, escape_command(" {$command_line}") . "\r\n") == false) {
                cacti_log("ERROR: Detected RRDtool Crash on '{$command_line}'.  Last command was '{$last_command}'");
                /* close the invalid pipe */
                rrd_close($rrdtool_pipe);
                /* open a new rrdtool process */
                $rrdtool_pipe = rrd_init();
                if ($i > 4) {
                    cacti_log("FATAL: RRDtool Restart Attempts Exceeded.  Giving up on command.");
                    break;
                } else {
                    $i++;
                }
                continue;
            } else {
                fflush($fd);
                break;
            }
        }
    }
    /* store the last command to provide rrdtool segfault diagnostics */
    $last_command = $command_line;
    switch ($output_flag) {
        case RRDTOOL_OUTPUT_NULL:
            return;
            break;
        case RRDTOOL_OUTPUT_STDOUT:
            if (isset($fp) && is_resource($fp)) {
                $line = "";
                while (!feof($fp)) {
                    $line .= fgets($fp, 4096);
                }
                pclose($fp);
                return $line;
            }
            break;
        case RRDTOOL_OUTPUT_STDERR:
            if (isset($fp) && is_resource($fp)) {
                $line = "";
                while (!feof($fp)) {
                    $line .= fgets($fp, 4096);
                }
                pclose($fp);
                if (substr($output, 1, 3) == "PNG") {
                    return "OK";
                }
                if (substr($output, 0, 5) == "GIF87") {
                    return "OK";
                }
                print $output;
            }
            break;
        case RRDTOOL_OUTPUT_GRAPH_DATA:
            if (isset($fp) && is_resource($fp)) {
                $line = "";
                while (!feof($fp)) {
                    $line .= fgets($fp, 4096);
                }
                pclose($fp);
                return $line;
            }
//.........这里部分代码省略.........
开发者ID:resmon,项目名称:resmon-cacti,代码行数:101,代码来源:setup.php

示例5: export_tree_graphs_and_graph_html

function export_tree_graphs_and_graph_html($path, $tree_id)
{
    global $colors, $config;
    include_once $config["library_path"] . "/tree.php";
    include_once $config["library_path"] . "/data_query.php";
    /* start the count of graphs */
    $total_graphs_created = 0;
    $exported_files = array();
    $cacti_export_path = read_config_option("path_html_export");
    /* auth check for hosts on the trees */
    $current_user = db_fetch_row("SELECT * FROM user_auth WHERE id=" . read_config_option("export_user_id"));
    if (!export_is_tree_allowed($tree_id)) {
        return 0;
    }
    $sql_join = "LEFT JOIN graph_local ON (graph_templates_graph.local_graph_id=graph_local.id)\n\t\tLEFT JOIN graph_templates ON (graph_templates.id=graph_local.graph_template_id)\n\t\tLEFT JOIN host ON (host.id=graph_local.host_id)\n\t\tLEFT JOIN user_auth_perms ON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=1 AND user_auth_perms.user_id=" . $current_user["id"] . ") OR (host.id=user_auth_perms.item_id AND user_auth_perms.type=3 AND user_auth_perms.user_id=" . $current_user["id"] . ") OR (graph_templates.id=user_auth_perms.item_id AND user_auth_perms.type=4 AND user_auth_perms.user_id=" . $current_user["id"] . "))";
    $sql_where = get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_hosts"], $current_user["policy_graph_templates"]);
    $sql_where = empty($sql_where) ? "" : "AND {$sql_where}";
    $graphs = array();
    if ($tree_id == 0) {
        $hosts = db_fetch_assoc("SELECT DISTINCT host_id FROM graph_tree_items");
    } else {
        $hosts = db_fetch_assoc("SELECT DISTINCT host_id FROM graph_tree_items WHERE graph_tree_id=" . $tree_id);
    }
    /* get a list of host graphs first */
    if (sizeof($hosts)) {
        foreach ($hosts as $host) {
            $hosts_sql = "SELECT DISTINCT\n\t\t\tgraph_templates_graph.id,\n\t\t\tgraph_templates_graph.local_graph_id,\n\t\t\tgraph_templates_graph.height,\n\t\t\tgraph_templates_graph.width,\n\t\t\tgraph_templates_graph.title_cache,\n\t\t\tgraph_templates.name,\n\t\t\tgraph_local.host_id\n\t\t\tFROM (graph_tree_items, graph_templates_graph)\n\t\t\t{$sql_join}\n\t\t\tWHERE ((graph_templates_graph.local_graph_id<>0)\n\t\t\t{$sql_where}\n\t\t\tAND (graph_local.host_id=" . $host["host_id"] . ")\n\t\t\tAND (graph_templates_graph.export='on'))\n\t\t\tORDER BY graph_templates_graph.title_cache";
            $host_graphs = db_fetch_assoc($hosts_sql);
            if (sizeof($host_graphs)) {
                if (sizeof($graphs)) {
                    $graphs = array_merge($host_graphs, $graphs);
                } else {
                    $graphs = $host_graphs;
                }
            }
        }
    }
    /* now get the list of graphs placed within the tree */
    if ($tree_id == 0) {
        $sql_where = "WHERE graph_templates_graph.local_graph_id!=0\n\t\t\t{$sql_where}\n\t\t\tAND graph_templates_graph.export='on'";
    } else {
        $sql_where = "WHERE graph_tree_items.graph_tree_id =" . $tree_id . "\n\t\t\t{$sql_where}\n\t\t\tAND graph_templates_graph.local_graph_id!=0\n\t\t\tAND graph_templates_graph.export='on'";
    }
    $non_host_sql = "SELECT\n\t\tgraph_templates_graph.id,\n\t\tgraph_templates_graph.local_graph_id,\n\t\tgraph_templates_graph.height,\n\t\tgraph_templates_graph.width,\n\t\tgraph_templates_graph.title_cache,\n\t\tgraph_templates.name,\n\t\tgraph_local.host_id,\n\t\tgraph_tree_items.id AS gtid\n\t\tFROM (graph_tree_items, graph_templates_graph)\n\t\t{$sql_join}\n\t\t{$sql_where}\n\t\tAND graph_tree_items.local_graph_id = graph_templates_graph.local_graph_id\n\t\tAND graph_templates_graph.export='on'\n\t\tORDER BY graph_templates_graph.title_cache";
    $non_host_graphs = db_fetch_assoc($non_host_sql);
    if (sizeof($non_host_graphs)) {
        if (sizeof($graphs)) {
            $graphs = array_merge($non_host_graphs, $graphs);
        } else {
            $graphs = $non_host_graphs;
        }
    }
    /* open a pipe to rrdtool for writing */
    $rrdtool_pipe = rrd_init();
    /* for each graph... */
    $i = 0;
    if (sizeof($graphs) > 0) {
        foreach ($graphs as $graph) {
            $rras = get_associated_rras($graph["local_graph_id"]);
            /* settings for preview graphs */
            $graph_data_array["graph_height"] = read_config_option("export_default_height");
            $graph_data_array["graph_width"] = read_config_option("export_default_width");
            $graph_data_array["graph_nolegend"] = true;
            $graph_data_array["export"] = true;
            if (read_config_option("export_tree_isolation") == "on") {
                $graph_data_array["export_filename"] = "/" . $path . "/graphs/thumb_" . $graph["local_graph_id"] . ".png";
                $export_filename = $cacti_export_path . "/" . $path . "/graphs/thumb_" . $graph["local_graph_id"] . ".png";
            } else {
                $graph_data_array["export_filename"] = "/graphs/thumb_" . $graph["local_graph_id"] . ".png";
                $export_filename = $cacti_export_path . "/graphs/thumb_" . $graph["local_graph_id"] . ".png";
            }
            if (!array_search($export_filename, $exported_files)) {
                /* add the graph to the exported list */
                array_push($exported_files, $export_filename);
                export_log("Creating Graph '" . $cacti_export_path . $graph_data_array["export_filename"] . "'");
                /* generate the graph */
                rrdtool_function_graph($graph["local_graph_id"], 0, $graph_data_array, $rrdtool_pipe);
                $total_graphs_created++;
                /* generate html files for each graph */
                if (read_config_option("export_tree_isolation") == "on") {
                    export_log("Creating File  '" . $cacti_export_path . "/" . $path . "/graph_" . $graph["local_graph_id"] . ".html'");
                    $fp_graph_index = fopen($cacti_export_path . "/" . $path . "/graph_" . $graph["local_graph_id"] . ".html", "w");
                } else {
                    export_log("Creating File  '" . $cacti_export_path . "/graph_" . $graph["local_graph_id"] . ".html'");
                    $fp_graph_index = fopen($cacti_export_path . "/graph_" . $graph["local_graph_id"] . ".html", "w");
                }
                fwrite($fp_graph_index, HTML_HEADER_TREE);
                /* write the code for the tree at the left */
                draw_html_left_tree($fp_graph_index, $tree_id);
                fwrite($fp_graph_index, HTML_GRAPH_HEADER_ONE_TREE);
                fwrite($fp_graph_index, "<strong>Graph - " . $graph["title_cache"] . "</strong></td></tr>");
                fwrite($fp_graph_index, HTML_GRAPH_HEADER_TWO_TREE);
                fwrite($fp_graph_index, "<td>");
                /* reset vars for actual graph image creation */
                reset($rras);
                unset($graph_data_array);
                /* generate graphs for each rra */
                foreach ($rras as $rra) {
                    $graph_data_array["export"] = true;
                    if (read_config_option("export_tree_isolation") == "on") {
//.........这里部分代码省略.........
开发者ID:songchin,项目名称:Cacti,代码行数:101,代码来源:graph_export.php

示例6: export

function export() {
	global $config;

	if (!file_exists(read_config_option("path_html_export"))) {
		export_fatal("Export path does not exist!");
	}

	export_log("Running graph export");

	$cacti_root_path = $config["base_path"];
	$cacti_export_path = read_config_option("path_html_export");

	/* copy the css/images on the first time */
	if (file_exists("$cacti_export_path/main.css") == false) {
		copy("$cacti_root_path/include/main.css", "$cacti_export_path/main.css");
		copy("$cacti_root_path/images/tab_cacti.gif", "$cacti_export_path/tab_cacti.gif");
		copy("$cacti_root_path/images/cacti_backdrop.gif", "$cacti_export_path/cacti_backdrop.gif");
		copy("$cacti_root_path/images/transparent_line.gif", "$cacti_export_path/transparent_line.gif");
		copy("$cacti_root_path/images/shadow.gif", "$cacti_export_path/shadow.gif");
	}

	/* if the index file already exists, delete it */
	check_remove($cacti_export_path . "/index.html");

	/* open pointer to the new index file */
	$fp_index = fopen($cacti_export_path . "/index.html", "w");

	/* get a list of all graphs that need exported */
	$graphs = db_fetch_assoc("select
		graph_templates_graph.id,
		graph_templates_graph.local_graph_id,
		graph_templates_graph.height,
		graph_templates_graph.width,
		graph_templates_graph.title_cache,
		graph_templates.name,
		graph_local.host_id
		from graph_templates_graph left join graph_templates on graph_templates_graph.graph_template_id=graph_templates.id
		left join graph_local on graph_templates_graph.local_graph_id=graph_local.id
		where graph_templates_graph.local_graph_id!=0 and graph_templates_graph.export='on'
		order by graph_templates_graph.title_cache");
	$rras = db_fetch_assoc("select
		rra.id,
		rra.name
		from rra
		order by steps");

	/* write the html header data to the index file */
	fwrite($fp_index, HTML_HEADER);
	fwrite($fp_index, HTML_GRAPH_HEADER_ONE);
	fwrite($fp_index, "<strong>Displaying " . sizeof($graphs) . " Exported Graph" . ((sizeof($graphs) > 1) ? "s" : "") . "</strong>");
	fwrite($fp_index, HTML_GRAPH_HEADER_TWO);

	/* open a pipe to rrdtool for writing */
	$rrdtool_pipe = rrd_init();

	/* for each graph... */
	$i = 0; $k = 0;
	if ((sizeof($graphs) > 0) && (sizeof($rras) > 0)) {
	foreach ($graphs as $graph) {
		check_remove($cacti_export_path . "/thumb_" . $graph["local_graph_id"] . ".png");
		check_remove($cacti_export_path . "/graph_" . $graph["local_graph_id"] . ".html");

		/* settings for preview graphs */
		$graph_data_array["graph_height"] = "100";
		$graph_data_array["graph_width"] = "300";
		$graph_data_array["graph_nolegend"] = true;
		$graph_data_array["export"] = true;
		$graph_data_array["export_filename"] = "thumb_" . $graph["local_graph_id"] . ".png";
		rrdtool_function_graph($graph["local_graph_id"], 0, $graph_data_array, $rrdtool_pipe);

		/* generate html files for each graph */
		$fp_graph_index = fopen($cacti_export_path . "/graph_" . $graph["local_graph_id"] . ".html", "w");

		fwrite($fp_graph_index, HTML_HEADER);
		fwrite($fp_graph_index, HTML_GRAPH_HEADER_ONE);
		fwrite($fp_graph_index, "<strong>Graph - " . $graph["title_cache"] . "</strong>");
		fwrite($fp_graph_index, HTML_GRAPH_HEADER_TWO);
		fwrite($fp_graph_index, "<td>");

		/* reset vars for actual graph image creation */
		reset($rras);
		unset($graph_data_array);

		/* generate graphs for each rra */
		foreach ($rras as $rra) {
			$graph_data_array["export"] = true;
			$graph_data_array["export_filename"] = "graph_" . $graph["local_graph_id"] . "_" . $rra["id"] . ".png";

			rrdtool_function_graph($graph["local_graph_id"], $rra["id"], $graph_data_array, $rrdtool_pipe);

			/* write image related html */
			fwrite($fp_graph_index, "<div align=center><img src='graph_" . $graph["local_graph_id"] . "_" . $rra["id"] . ".png' border=0></div>\n
				<div align=center><strong>" . $rra["name"] . "</strong></div><br>");
		}

		fwrite($fp_graph_index, "</td>");
		fwrite($fp_graph_index, HTML_GRAPH_FOOTER);
		fwrite($fp_graph_index, HTML_FOOTER);
		fclose($fp_graph_index);

//.........这里部分代码省略.........
开发者ID:songchin,项目名称:Cacti,代码行数:101,代码来源:graph_export.php

示例7: output_rrd_data

function output_rrd_data($start_time, $force = FALSE)
{
    global $start, $max_run_duration, $config, $debug, $get_memory, $memory_used;
    global $rrdtool_pipe, $rrdtool_read_pipe;
    include_once $config['base_path'] . '/lib/rrd.php';
    $boost_poller_status = read_config_option('boost_poller_status');
    $rrd_updates = 0;
    /* implement process lock control for boost */
    if (!db_fetch_cell("SELECT GET_LOCK('poller_boost', 1)")) {
        if ($debug) {
            cacti_log('DEBUG: Found lock, so another boost process is running');
        }
        return -1;
    }
    /* detect a process that has overrun it's warning time */
    if (substr_count($boost_poller_status, 'running')) {
        $status_array = explode(':', $boost_poller_status);
        if (!empty($status_array[1])) {
            $previous_start_time = strtotime($status_array[1]);
            /* if the runtime was exceeded, allow the next process to run */
            if ($previous_start_time + $max_run_duration < $start_time) {
                cacti_log('WARNING: Detected Poller Boost Overrun, Possible Boost Poller Crash', FALSE, 'BOOST SVR');
            }
        }
    }
    /* if the poller is not running, or has never run, start */
    /* mark the boost server as running */
    db_execute("REPLACE INTO settings (name, value) VALUES ('boost_poller_status', 'running - start time:" . date('Y-m-d G:i:s') . "')");
    $current_time = date('Y-m-d G:i:s', $start_time);
    $rrdtool_pipe = rrd_init();
    $rrdtool_read_pipe = rrd_init();
    $runtime_exceeded = false;
    /* let's set and track memory usage will we */
    if (!function_exists('memory_get_peak_usage')) {
        $get_memory = true;
        $memory_used = memory_get_usage();
    } else {
        $get_memory = false;
    }
    $delayed_inserts = db_fetch_row("SHOW STATUS LIKE 'Not_flushed_delayed_rows'");
    while ($delayed_inserts['Value']) {
        cacti_log('BOOST WAIT: Waiting 1s for delayed inserts are made', true, 'SYSTEM');
        usleep(1000000);
        $delayed_inserts = db_fetch_row("SHOW STATUS LIKE 'Not_flushed_delayed_rows'");
    }
    /* split poller_output_boost */
    $archive_table = 'poller_output_boost_arch_' . time();
    db_execute("RENAME TABLE poller_output_boost TO {$archive_table}");
    db_execute("CREATE TABLE poller_output_boost LIKE {$archive_table}");
    $more_arch_tables = db_fetch_assoc("SELECT table_name AS name\n\t\tFROM information_schema.tables\n\t\tWHERE table_schema=SCHEMA()\n\t\tAND table_name LIKE 'poller_output_boost_arch_%'\n\t\tAND table_name!='{$archive_table}'\n\t\tAND table_rows>0;");
    if (count($more_arch_tables)) {
        foreach ($more_arch_tables as $table) {
            $table_name = $table['name'];
            db_execute("INSERT INTO {$archive_table} SELECT * FROM {$table_name}");
            db_execute("TRUNCATE TABLE {$table_name}");
        }
    }
    if (!strlen($archive_table)) {
        cacti_log('ERROR: Failed to retrieve archive table name');
        return -1;
    }
    while (1) {
        $rows = db_fetch_cell("SELECT count(*) FROM {$archive_table}");
        if ($rows > 0) {
            $rrd_updates += boost_process_poller_output(FALSE, '', $current_time);
            if ($get_memory) {
                $cur_memory = memory_get_usage();
                if ($cur_memory > $memory_used) {
                    $memory_used = $cur_memory;
                }
            }
        } else {
            break;
        }
        if (time() - $start > $max_run_duration && !$runtime_exceeded) {
            cacti_log('WARNING: RRD On Demand Updater Exceeded Runtime Limits. Continuing to Process!!!');
            $runtime_exceeded = true;
        }
    }
    /* tell the main poller that we are done */
    db_execute("REPLACE INTO settings (name, value) VALUES ('boost_poller_status', 'complete - end time:" . date('Y-m-d G:i:s') . "')");
    /* log memory usage */
    if (function_exists('memory_get_peak_usage')) {
        db_execute("REPLACE INTO settings (name, value) VALUES ('boost_peak_memory', '" . memory_get_peak_usage() . "')");
    } else {
        db_execute("REPLACE INTO settings (name, value) VALUES ('boost_peak_memory', '" . $memory_used . "')");
    }
    rrd_close($rrdtool_pipe);
    rrd_close($rrdtool_read_pipe);
    /* cleanup  - remove empty arch tables */
    $tables = db_fetch_assoc("SELECT table_name AS name\n\t\tFROM information_schema.tables\n\t\tWHERE table_schema=SCHEMA()\n\t\tAND table_name LIKE 'poller_output_boost_arch_%'\n\t\tAND table_rows=0;");
    if (count($tables)) {
        foreach ($tables as $table) {
            db_execute('DROP TABLE ' . $table['name']);
        }
    }
    db_execute("SELECT RELEASE_LOCK('poller_boost');");
    return $rrd_updates;
}
开发者ID:MrWnn,项目名称:cacti,代码行数:99,代码来源:poller_boost.php

示例8: db_fetch_cell

	$all_num_polling_items = db_fetch_cell("SELECT count(*) FROM poller_item WHERE poller_id=" . $poller_id);
	$all_polling_hosts = array_merge(array(0 => array("id" => "0")), db_fetch_assoc("select id from host where disabled = '' ORDER BY id"));

	/* get the number of active pollers */
	$pollers = db_fetch_assoc("SELECT * FROM poller WHERE active = 'on'");
	$num_pollers = sizeof($pollers);

	/* update web paths for the poller */
	db_execute("REPLACE INTO settings (name,value) VALUES ('path_webroot','" . addslashes((CACTI_SERVER_OS == "win32") ? strtolower(str_replace("\\","/",substr(dirname(__FILE__), 0, 1))) . str_replace("\\","/",substr(dirname(__FILE__), 1)) : dirname(__FILE__)) . "')");

	/* initialize poller_time and poller_output tables */
	db_execute("TRUNCATE TABLE poller_time");

	/* open a pipe to rrdtool for writing */
	$rrd_processes = read_config_option("concurrent_rrd_processes");
	$rrdtool_pipe = rrd_init($rrd_processes);

	/* insert the current date/time for graphs */
	db_execute("REPLACE INTO settings (name,value) VALUES ('date',NOW())");

	/* allow remote pollers to start */
	db_execute("UPDATE poller SET run_state='Ready' WHERE active='on'");

	/* show main poller as running */
	db_execute("UPDATE poller SET run_state='Running' WHERE id=1");

} else {
	/* verify I am a valid poller */
	if (sizeof(db_fetch_assoc("SELECT id FROM poller WHERE id = " . $poller_id)) == 0) {
		print sprintf(_("Poller '%i' does not exist in this system.\n"), $poller_id);
		log_save(sprintf(_("Poller '%i' is attempting to run, but does not exist on this system."),$poller_id), SEV_CRITICAL, FACIL_POLLER, "", $poller_id, 0, true);
开发者ID:songchin,项目名称:Cacti,代码行数:31,代码来源:poller.php


注:本文中的rrd_init函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。