A closer look at how RRDTOOL is structured. The syntax is indeed cumbersome, but not too difficult. Each time the command line is executed, it must be output as a file. We hope to make an application to dynamically generate charts and look at the Cacti implementation method. The core part is to use the popen function... SyntaxHighlighter. all ();
A closer look at how RRDTOOL is structured. The syntax is indeed cumbersome, but not too difficult. Each time the command line is executed, it must be output as a file. We hope to make an application to dynamically generate charts and look at the Cacti implementation method. The core part is to use the popen function to output commands to the pipeline, then read all the data cyclically, and then output it to the client as an image. In this way, you can see dynamic images without the need for physical storage. The following is the code segment I have captured for your reference.
Error_reporting (E_ALL );
// Drawing command. Note that a connector is added to the graph.
$ Command = '/opt/rrdtool/bin/rrdtool graph--- start =-86400 -- end =-300 -- title = Test -- height = 400 -- width = 800 DEF: value1 = "/home/echo/workspace/misc/tianjin_dpool_web_21_traffic_in_22.rrd": traffic_in: average area: value1 # ff0000 2> & 1 ';
// Test the channel operator
Session_write_close ();
// Execute commands in MPs queue mode and receive error output
$ Handle = popen ("$ command 2> & 1", 'r ');
$ Read = '';
While (! Feof ($ handle )){
$ Read. = fgets ($ handle, 4096 );
}
Pclose ($ handle );
Echo $ read;
// Set the proper headers to allow caching
$ This-> request-> headers ['content-type'] = File: mime_by_ext ('PNG ');
$ This-> request-> headers ['content-length'] = strlen ($ read );
$ This-> request-> headers ['last-modified'] = date ('R', time ());
From: lonely blog