Book/rrd-Phpdoc专题
RRDtool
目录
- 简介
- 安装/配置
- 预定义常量
- 范例
- RRD 函数
- rrd_create — Creates rrd database file
- rrd_error — Gets latest error message
- rrd_fetch — Fetch the data for graph as array
- rrd_first — Gets the timestamp of the first sample from rrd file
- rrd_graph — Creates image from a data
- rrd_info — Gets information about rrd file
- rrd_last — Gets unix timestamp of the last sample
- rrd_lastupdate — Gets information about last updated data
- rrd_restore — Restores the RRD file from XML dump
- rrd_tune — Tunes some RRD database file header options
- rrd_update — Updates the RRD database
- rrd_version — Gets information about underlying rrdtool library
- rrd_xport — Exports the information about RRD database
- rrdc_disconnect — Close any outstanding connection to rrd caching daemon
- RRDCreator — The RRDCreator class
- RRDCreator::addArchive — Adds RRA - archive of data values for each data source
- RRDCreator::addDataSource — Adds data source definition for RRD database
- RRDCreator::__construct — Creates new RRDCreator instance
- RRDCreator::save — Saves the RRD database to a file
- RRDGraph — The RRDGraph class
- RRDGraph::__construct — Creates new RRDGraph instance
- RRDGraph::save — Saves the result of query into image
- RRDGraph::saveVerbose — Saves the RRD database query into image and returns the verbose information about generated graph
- RRDGraph::setOptions — Sets the options for rrd graph export
- RRDUpdater — The RRDUpdater class
- RRDUpdater::__construct — Creates new RRDUpdater instance
- RRDUpdater::update — Update the RRD database file
简介
Class for creation of RRD database file.
类摘要
RRDCreator
class RRDCreator {
/* 方法 */
public void
addArchive ( <span
class="methodparam">string
$description
)
public void
addDataSource ( <span
class="methodparam">string
$description
)
public <span
class="methodname">__construct ( <span
class="methodparam">string $path
[,
string
$startTime
[, <span
class="type">int $step
=
0 ]] )
public bool save ( <span class="methodparam">void )
}
RRDCreator::addArchive
Adds RRA - archive of data values for each data source
说明
public void
RRDCreator::addArchive ( <span
class="methodparam">string
$description
)
Adds RRA definition by description of archive. Archive consists of a number of data values or statistics for each of the defined data-sources (DS). Data sources are defined by method <span class="methodname">RRDCreator::addDataSource. You need call this method for each requested archive.
参数
description
Definition of archive - RRA. This has same format as RRA definition in
rrd create command. See man page of rrd create for more details.
返回值
没有返回值。
RRDCreator::addDataSource
Adds data source definition for RRD database
说明
public void
RRDCreator::addDataSource ( <span
class="methodparam">string
$description
)
RRD can accept input from several data sources (DS), e.g incoming and outgoing traffic. This method adds data source by description. You need call this method for each data source.
参数
description
Definition of data source - DS. This has same format as DS definition in
rrd create command. See man page of rrd create for more details.
返回值
没有返回值。
RRDCreator::__construct
Creates new RRDCreator instance
说明
public <span
class="methodname">RRDCreator::__construct ( <span
class="methodparam">string $path
[,
string
$startTime
[, <span
class="type">int $step
=
0 ]] )
Creates new RRDCreator instance.
参数
path
Path for newly created RRD database file.
startTime
Time for the first value in RRD database. Parameter supports all formats
which are supported by rrd create call.
intstep
Base interval in seconds with which data will be fed into the RRD
database.
返回值
没有返回值。
RRDCreator::save
Saves the RRD database to a file
说明
public bool RRDCreator::save ( <span class="methodparam">void )
Saves the RRD database into file, which name is defined by <span class="methodname">RRDCreator::__construct.
参数
此函数没有参数。
返回值
成功时返回 true
, 或者在失败时返回 false
。
简介
Class for exporting data from RRD database to image file.
类摘要
RRDGraph
class RRDGraph {
/* 方法 */
public <span
class="methodname">__construct ( <span
class="methodparam">string $path
)
public array save ( <span class="methodparam">void )
public array saveVerbose ( <span class="methodparam">void )
public void
setOptions ( <span
class="methodparam">array $options
)
}
RRDGraph::__construct
Creates new RRDGraph instance
说明
public <span
class="methodname">RRDGraph::__construct ( <span
class="methodparam">string $path
)
Creates new RRDGraph instance. This instance is responsible for rendering the result of RRD database query into image.
参数
path
Full path for the newly created image.
返回值
没有返回值。
RRDGraph::save
Saves the result of query into image
说明
public array RRDGraph::save ( <span class="methodparam">void )
Saves the result of RRD database query into image defined by <span class="methodname">RRDGraph::__construct.
参数
此函数没有参数。
返回值
Array with information about generated image is returned, false
if
error occurs.
RRDGraph::saveVerbose
Saves the RRD database query into image and returns the verbose information about generated graph
说明
public array RRDGraph::saveVerbose ( <span class="methodparam">void )
Saves the RRD database query into image file defined by method <span class="methodname">RRDGraph::__construct and returns the verbose information about generated graph, if "-" is used as image filename, image data are also returned in result array.
参数
此函数没有参数。
返回值
Array with detailed information about generated image is returned,
optionally with image data, false
if error occurs.
RRDGraph::setOptions
Sets the options for rrd graph export
说明
public void
RRDGraph::setOptions ( <span
class="methodparam">array $options
)
参数
options
List of options for the image generation from the RRD database file. It
can be list of strings or list of strings with keys for better
readability. Read the rrd graph man pages for list of available options.
返回值
没有返回值。
范例
示例 #1 RRDGraph::setOptions example
<?php
$graphObj->setOptions(array(
"--start" => "920804400",
"--end" => 920808000,
"--vertical-label" => "m/s",
"DEF:myspeed=$rrdFile:speed:AVERAGE",
"CDEF:realspeed=myspeed,1000,*",
"LINE2:realspeed#FF0000"
));
?>
示例 #2 Set multiple color options
<?php
$graphObj->setOptions(array(
"--start" => "920804400",
"--end" => 920808000,
"--vertical-label" => "m/s",
"--color=BACK#00000000",
"--color=GRID#00000000",
"--color=MGRID#00000000",
"DEF:myspeed=$rrdFile:speed:AVERAGE",
"CDEF:realspeed=myspeed,1000,*",
"LINE2:realspeed#FF0000"
));
?>
Don't use key value syntax for same rrd option. It looks more readable, but it doesn't work.
<?php
$graphObj->setOptions(array(
"--color" => "BACK#00000000",
"--color" => "GRID#00000000",
"--color" => "MGRID#00000000"
));
?>
In nature of php it's same as
<?php
$graphObj->setOptions(array(
"--color" => "MGRID#00000000"
));
?>
简介
Class for updating RDD database file.
类摘要
RRDUpdater
class RRDUpdater {
/* 方法 */
public <span
class="methodname">__construct ( <span
class="methodparam">string $path
)
public bool
update ( <span
class="type">array $values
[, <span
class="methodparam">string $time
<span
class="initializer"> = time() ] )
}
RRDUpdater::__construct
Creates new RRDUpdater instance
说明
public <span
class="methodname">RRDUpdater::__construct ( <span
class="methodparam">string $path
)
Creates new RRDUpdater instance. This instance is responsible for updating the RRD database file.
参数
path
Filesystem path for RRD database file, which will be updated.
返回值
没有返回值。
RRDUpdater::update
Update the RRD database file
说明
public bool
RRDUpdater::update ( <span
class="methodparam">array $values
[,
string $time
<span
class="initializer"> = time() ] )
Updates the RRD file defined via <span class="methodname">RRDUpdater::__construct. The file is updated with a specific values.
参数
values
Data for update. Key is data source name.
time
Time value for updating the RRD with a particulat data. Default value is
current time.
返回值
成功时返回 true
, 或者在失败时返回 false
。
错误/异常
Throws a Exception on error.
范例
示例 #1 RRDUpdater::update examples
<?php
$updator = new RRDUpdater("speed.rrd");
//updates the data source "speed" with value "12411"
//for time defined by timestamp "920807700"
$updator->update(array("speed" => "12411"), "920807700");
?>