ondram/graphite-graph

Graphite graph DSL to build URL query string for a graph (PSR-4 and PHP7 compatible)

2.1.0 2017-02-06 00:25 UTC

This package is auto-updated.

Last update: 2024-10-24 05:18:33 UTC


README

Latest Stable Version Build Status License

GraphBuilder is a DSL and ini-based templating language for PHP to assist in constructing URL query strings for use with Graphite graphs.

This is version 2 of the library (introducing eg. PSR-4 namespaces), based on original version by Bryan Davis.

About

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.

Installation

Install using Composer:

$ composer require ondram/graphite-graph

Examples

<?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.

Credits

Originally written by Bryan Davis with support from Keynetics.

Updated to use PHP namespaces etc. by Ondrej Machulda.

Inspired by https://github.com/ripienaar/graphite-graph-dsl/.