php-doc-en/reference/rrd/examples.xml

114 lines
2.5 KiB
XML
Raw Normal View History

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<chapter xml:id="rrd.examples" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
&reftitle.examples;
<section xml:id="rrd.examples-procedural">
<title>Procedural PECL/rrd example</title>
<para>
<example>
<title>Procedural usage of rrd</title>
<programlisting role="php">
<![CDATA[
<?php
$rrdFile = dirname(__FILE__) . "/speed.rrd";
//create rrd file
rrd_create($rrdFile,
array(
"--start",920804400,
"DS:speed:COUNTER:600:U:U",
"RRA:AVERAGE:0.5:1:24",
"RRA:AVERAGE:0.5:6:10"
)
);
//update rrd file
rrd_update($rrdFile,
array(
"920804700:12345",
"920805000:12357"
)
);
//graph output
rrd_graph(dirname(__FILE__) . "/speed.png",
array(
"--start", "920804400",
"--end", "920808000",
"--vertical-label", "m/s",
"DEF:myspeed=$rrdFile:speed:AVERAGE",
"CDEF:realspeed=myspeed,1000,*",
"LINE2:realspeed#FF0000"
)
);
?>
]]>
</programlisting>
</example>
</para>
</section>
<section xml:id="rrd.examples-oop">
<title>OOP PECL/rrd example</title>
<para>
<example>
<title>OO usage of rrd</title>
<programlisting role="php">
<![CDATA[
<?php
$rrdFile = dirname(__FILE__) . "/speed.rrd";
$outputPngFile = dirname(__FILE__) . "/speed.png";
$creator = new RRDCreator($rrdFile, "now -10d", 500);
$creator->addDataSource("speed:COUNTER:600:U:U");
$creator->addArchive("AVERAGE:0.5:1:24");
$creator->addArchive("AVERAGE:0.5:6:10");
$creator->save();
$updater = new RRDUpdater($rrdFile);
$updater->update(array("speed" => "12345"), "920804700");
$updater->update(array("speed" => "12357"), "920805000");
$graphObj = new RRDGraph($outputPngFile);
$graphObj->setOptions(
array(
"--start" => "920804400",
"--end" => 920808000,
"--vertical-label" => "m/s",
"DEF:myspeed=$rrdFile:speed:AVERAGE",
"CDEF:realspeed=myspeed,1000,*",
"LINE2:realspeed#FF0000"
)
);
$graphObj->save();
?>
]]>
</programlisting>
</example>
</para>
</section>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->