项目作者: oceandba

项目描述 :
Graphitti provides an expressive, fluent interface to Graphite's Render Url API
高级语言: PHP
项目地址: git://github.com/oceandba/graphitti.git
创建时间: 2019-11-18T10:34:18Z
项目社区:https://github.com/oceandba/graphitti

开源协议:MIT License

下载



Graphitti


Latest Stable Version
Latest Unstable Version
Build Status
StyleCI
License
Total Downloads

Introduction

The aim of Graphitti is to ease the use of the Render URL API provided by graphite.
Graphitti provides a expressive fluid API around the Render URL API.

License

Graphitti is open-sourced software licensed under the MIT license

Installation

This packages works for Laravel versions 5.* and ^6.0 only.

Install Graphitti as you would with any other dependency managed by Composer:

  1. composer require oceandba/graphitti

Configuration

To publish the configuration use the command :

  1. php artisan vendor:publish --provider="OceanDBA\Graphitti\GraphittiServiceProvider" --tag="graphitti-config"

This will create the file config/graphitti.php. Use this file to configure your graphite hosts; the file should be self-explanatory and
contains the appropriate configurations needed for you to get started.

Usage

Using Targets

You can create a new Target using the OceanDBA\Graphitti\Metrics\Target class as
follows :

  1. use OceanDBA\Graphitti\Metrics\Target;
  2. $target = Target::make('oceandba.server1.load', 'Server-load-1');

You may also add a precision to the Target object which will serve to round DataPoints when retrieved.

  1. $target = Target::make('oceandba.server1.load', 'Server-load-1')->precision(2);

The Target takes two parameters :
1) The path
2) An optional name for the Target

Applying functions to Target

To apply a function to the Target use the function name as a method call on the Target instance and pass parameters to it :

  1. Target::make('oceandba.server1.load', 'Server-load-1')->add(10);

You can also chain the function calls :

  1. Target::make('oceandba.server1.load', 'Server-load-1')
  2. ->add(10)
  3. ->aggregate('sum');

Refer to the Graphite Docs for list of available functions.

The Target class uses the Macroable trait of Laravel. So you are free to add your own methods to the class.

  1. use OceanDBA\Graphitti\Metrics\Target;
  2. // ...
  3. public function boot()
  4. {
  5. Target::macro('validate', function () {
  6. if(strpos($this->value(), 'oceandba') === false) {
  7. throw new \InvalidArgumentException('Target is invalid');
  8. }
  9. return $this;
  10. });
  11. }
  1. Target::make('oceandba.server1.load', 'Server-load-1')->validate();

Using GraphitePoints

The GraphitePoints class provides an expressive syntax to retrieve DataPoints from Graphite. You should supply at least one Target to the

  1. ```php
  2. use GraphitePoints;
  3. use OceanDBA\Graphitti\Metrics\Target;
  4. $dataPointsCollection = GraphitePoints::addTarget(Target::make('oceandba.server1.load', 'Server-load-1'))
  5. ->addTarget(Target::make('oceandba.server2.load', 'Server-load-2'))
  6. ->render();

This will return a OceanDBA\Graphitti\Series\DataPointsCollection. The object contains a collection of OceanDBA\Graphitti\Series\DataPoints,
both classes are Macroable.

Contraint from/until

You can add time period constrains using the from and until methods available on the GraphitePoints.

  1. GraphitePoints::addTarget(Target::make('oceandba.server1.load', 'Server-load-1'))
  2. ->addTarget(Target::make('oceandba.server2.load', 'Server-load-2'))
  3. ->from('-1h')
  4. ->until('now')
  5. ->render()

The methods accept Carbon instances as well as relative time string. Refer to the Graphite Docs
for how to form relative time string.

Additional graph parameters

You can add graph parameters using addParameter method on GraphitePoints :

  1. GraphitePoints::addTarget(Target::make('oceandba.server1.load', 'Server-load-1'))
  2. ->addTarget(Target::make('oceandba.server2.load', 'Server-load-2'))
  3. ->from('-1h')
  4. ->until('now')
  5. ->addParameter('maxDataPoints', 50)
  6. ->render()

Refer to the Graphite Docs for full list of accepted parameters.

Credits

Big Thanks to all developers who worked hard to create something amazing!

Creator

OceanDBA Ltd

Twitter: @OceanDBA


GitHub: OceanDBA Ltd