Graphite graph DSL to build URL query string for a graph (PSR-4 and PHP7 compatible)
GraphBuilder is a DSL and ini-based templating language for PHP to assist in constructing URL query strings for use with Graphite graphs.
Graphite provides several interfaces for creating graphs and dashboards, but one of its powerful features is an render 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. 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.
Install using Composer:
$ composer require ondram/graphite-graph
<?php $graphUrl = Graphite\GraphBuilder::builder() ->title('Memory') ->vtitle('MiB') ->width(800) ->height(600) ->from('-2days') ->buildSeries('memory-free') ->cactiStyle() ->color('green') ->alias('Free') ->scale(1 / (1024 * 1024)) // B to MiB ->build() ->build() ; echo '<img src="http://graphite.example.com/render?' . $graphUrl . '">';
For more usage examples see files in examples/ directory.
Updated to use PHP namespaces etc. by Ondrej Machulda.
Inspired by https://github.com/ripienaar/graphite-graph-dsl/.