Graphite_GraphBuilder Manual
A DSL and ini-based templating language to assist in constructing query strings for use with Graphite.
About
Graphite provides several interfaces for creating graphs and dashboards, but one of its powerful features is an API for generating graphs and retrieving raw data. This allows easy embedding of graphs in custom dashboards and other applications.
The process of describing complex graphs is however cumbersome at best. Graphite_GraphBuilder attempts to reduce the complexity of embedding Graphite graphs in PHP based applications by providing a fluent API for describing graphs and a facility for loading full or partial graph descriptions from ini files.
Examples
DSL Usage
- <?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>
Ini Usage
See Graphite_IniParser documentation for more details on the Mustache-like template expansion available within the ini files.
- ;
- ; Variables are declared by surrounding any string with double braces: {{VAR}}
- ;
- ; name itself will be output. This feature can be used to provide default
- ; values.
- ;
- ; Use like:
- ; ->prefix('com.example.host')
- ; ->ini('interface.ini', array('IF' => 'Tunnel0', 'IF_DESC' => 'tu0'));
- ; echo $g;
- ;; Graph settings
- ; a whole
- title = "Network Traffic {{IF_DESC}}"
- vtitle = "Bits Per Sec"
- bgcolor = "{{white}}"
- fgcolor = "333333"
- line_mode = "staircase"
- [snmp]
- ; a "prefix" is a partial path to prepend to another metric
- :is = "prefix"
- prefix = "collectd.snmp"
- [interface-octets]
- :is = "prefix"
- ; prefixes can use other prefixes if that makes keeping track easier
- :prefix = "snmp"
- prefix = "if_octets-{{IF}}"
- [rx]
- ; prefix and section label define the metric to graph
- ; "collectd.snmp.if_octets-IF.rx" in this case
- :prefix = "interface-octets"
- ; "counter" is an alias for the "nonNegativeDerivative" function
- counter = true
- color = "green"
- alias = "Inbound"
- [tx]
- :prefix = "interface-octets"
- counter = true
- scale = -1
- color = "blue"
- alias = "Outbound"
- [95th_in-out]
- :prefix = "interface-octets"
- ; "metric" is the data point under prefix to plot
- ; default is taken from the section label if not provided
- metric = "*"
- ; "series" if provided must be a fully qualified graphite metric name
- ; it will not be expended with the default or explicit prefixes
- ; This can also be used for functions no yet supported by the API
- ; series = movingMedian(foo.bar.baz, 5)
- counter = true
- sum = true
- npercentile = 95
- color = "red"
- dashed = 10
- alias = "95th Percentile in+out"
Download
Install with Composer
Graphite_GraphBuilder can be installed via {@link http://getcomposer.org/ Composer} as "{@link http://packagist.org/packages/graphite-graph/graphite-graph graphite-graph/graphite-graph}". The "dev-master" branch tracks stable development.
{ "require": { "graphite-graph/graphite-graph": "dev-master" } }
Get the Source
You can download this source in {@link https://github.com/bd808/graphite-graph-php/zipball/master zip} and tar formats.
You can also clone the project with Git by running:
$ git clone git://github.com/bd808/graphite-graph-php
Contributing
Fork this project on GitHub : bd808/graphite-graph-php
Credits
Written by Bryan Davis with support from Keynetics.
Inspired by https://github.com/ripienaar/graphite-graph-dsl/