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.

  1.  <?php
  2.   $series Graphite_Graph_Series::builder('whisper.metric.name')
  3.       ->cactistyle()
  4.       ->color('green')
  5.       ->alias('Free')
  6.       ->scale((1024 1024)) // B to MiB
  7.       ->build();

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:

  1. <?php
  2. /**
  3.  * Example usage of the DSL API to construct a graph of memory usage.
  4.  *
  5.  * Graph last 2 days of snmp collected memory utilization on host
  6.  * host.example.com.
  7.  *
  8.  * Show both free and used memory as stacked series after scaling values from
  9.  * bytes to megabytes (or more properly mebibytes).
  10.  *
  11.  * This example shows two different ways that the Graphite_Graph_Series DSL can
  12.  * be used to construct a target series for graphing.
  13.  */
  14.  
  15. require_once dirname(__FILE__'/../src/autoload.php';
  16.  
  17.     ->title('Memory')
  18.     ->vtitle('MiB')
  19.     ->width(800)
  20.     ->height(600)
  21.     ->bgcolor('white')
  22.     ->fgcolor('black')
  23.     ->from('-2days')
  24.     ->area('stacked')
  25.     ->prefix('collectd')
  26.     ->prefix('com.example.host')
  27.     ->prefix('snmp')
  28.     ->buildSeries('memory-free')
  29.         ->cactistyle()
  30.         ->color('green')
  31.         ->alias('Free')
  32.         ->scale((1024 1024)) // B to MiB
  33.         ->build()
  34.     ->buildSeries('memory-used')
  35.         ->scale((1024 1024))
  36.         ->color('blue')
  37.         ->alias('Used')
  38.         ->cactiStyle()
  39.         ->build()
  40.     ;
  41. ?>
  42. <!DOCTYPE html>
  43. <html>
  44.   <head>
  45.     <title>Memory on host.example.com</title>
  46.   </head>
  47.   <body>
  48.     <img src="http://graphite.example.com/render?<?php echo $g?>">
  49.   </body>
  50. </html>

Author(s):
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

static Graphite_Graph_Series builder( [string $series = null] )

Builder factory.

Parameters:

Name Type Description
$series string Base series to construct series from.

generate

static string generate( mixed $conf )

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

Graphite_Graph_Series __construct( [string $series = null] , [ $graph = null] )

Constructor.

Parameters:

Name Type Description
$series string Base series to construct series from.
$graph

asMetric

array asMetric( )

Get the description of this series as an array suitable for use with a call to Graphite_GraphBuilder::metric().

build

mixed 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

Graphite_Graph_Series __call( string $name , array $args )

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]