Class Graphite_Graph_Series
DSL for building Graphite series to display on a graph.
One or more series are passed to the Graphite server as target parameters in a render request. Each series is a description of the data to graph and instructions on how to render it. There are a large number of functions which can be applied to combine, manipulate and decorate collections of data points which are either loaded from a datasource such as whisper or an RRD file or generated by a function.
Graphite uses a nested function call syntax to describe each series. Manging this by hand for a reasonably complex rendering can become quite tedious. This DSL presents a fluid syntax for describing each series as though it were a chain of transforms to be applied to an object.
- <?php
- ->cactistyle()
- ->color('green')
- ->alias('Free')
- ->scale(1 / (1024 * 1024)) // B to MiB
Although this builder can be used as a stand-alone component, it will most often be used via a call to Graphite_GraphBuilder::buildSeries() as part of a larger graph creation process:
- <?php
- /**
- * Example usage of the DSL API to construct a graph of memory usage.
- *
- * Graph last 2 days of snmp collected memory utilization on host
- * host.example.com.
- *
- * Show both free and used memory as stacked series after scaling values from
- * bytes to megabytes (or more properly mebibytes).
- *
- * This example shows two different ways that the Graphite_Graph_Series DSL can
- * be used to construct a target series for graphing.
- */
- require_once dirname(__FILE__) . '/../src/autoload.php';
- ->title('Memory')
- ->vtitle('MiB')
- ->width(800)
- ->height(600)
- ->bgcolor('white')
- ->fgcolor('black')
- ->from('-2days')
- ->area('stacked')
- ->prefix('collectd')
- ->prefix('com.example.host')
- ->prefix('snmp')
- ->buildSeries('memory-free')
- ->cactistyle()
- ->color('green')
- ->alias('Free')
- ->scale(1 / (1024 * 1024)) // B to MiB
- ->buildSeries('memory-used')
- ->scale(1 / (1024 * 1024))
- ->color('blue')
- ->alias('Used')
- ->cactiStyle()
- ;
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Memory on host.example.com</title>
- </head>
- <body>
- <img src="http://graphite.example.com/render?<?php echo $g; ?>">
- </body>
- </html>
- Bryan Davis <bd808@bd808.com>
Copyright: | 2012 Bryan Davis and contributors. All Rights Reserved. |
Link: | http://readthedocs.org/docs/graphite/en/latest/functions.html |
License: | Simplified BSD License |
Member Variables
protected array |
$conf
Series configuration data. |
protected Graphite_GraphBuilder |
$graph
Paired graph builder. |
Method Summary
public static Graphite_Graph_Series |
builder(
[ $series
= null] )
Builder factory. |
public static string |
generate(
$conf
)
Generate the target parameter for a given configuration. |
public Graphite_Graph_Series |
__construct(
[ $series
= null] , [ $graph
= null] )
Constructor. |
public array |
asMetric(
)
Get the description of this series as an array suitable for use with a call to Graphite_GraphBuilder::metric(). |
public mixed |
build(
)
Build this series. |
public Graphite_Graph_Series |
__call(
$name
, $args
)
Handle attempts to call non-existant methods. |
Methods
builder
Builder factory.
Parameters:
Name | Type | Description |
---|---|---|
$series |
string | Base series to construct series from. |
generate
Generate the target parameter for a given configuration.
Parameters:
Name | Type | Description |
---|---|---|
$conf |
mixed | Configuration as array or Graphite_Graph_Series object |
Exceptions:
Type | Description |
---|---|
Graphite_ConfigurationException |
If neither series nor target is set in $conf |
__construct
Constructor.
Parameters:
Name | Type | Description |
---|---|---|
$series |
string | Base series to construct series from. |
$graph |
asMetric
Get the description of this series as an array suitable for use with a call to Graphite_GraphBuilder::metric().
build
Build this series.
Returns either an array of series configuration data or the string representation of this series depending on whether or not this series has a Graphite_GraphBuilder or not.
__call
Handle attempts to call non-existant methods.
Looks up method name as a function and if found adds that function and the given arguments to this builder's configuration.
If no matching function was found it will attempt to lookup the given method as a generator and add it to the current configuration.
Parameters:
Name | Type | Description |
---|---|---|
$name |
string | Method name |
$args |
array | Invocation arguments |
Located in /src/Graphite/Graph/Series.php [line 47]