2017 © Pedro Peláez
 

library metrics

PHP library for collecting metrics.

image

edisonlabs/metrics

PHP library for collecting metrics.

  • Thursday, July 26, 2018
  • by jkribeiro
  • Repository
  • 5 Watchers
  • 1 Stars
  • 116 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 2 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Build Status Coverage Status, (*1)

Metrics Collector

Overview

The Metrics Collector is a simple library that provides base classes to easily extend and collect custom metrics., (*2)

Usage

This library does not provide any metrics by default. To create new metrics, create a Composer package and then add a dependency to this package:, (*3)

composer require edisonlabs/metrics

Now create the metrics classes extending edisonlabs/metrics classes., (*4)

Example: Number of PHP files., (*5)

// src/EdisonLabs/Metric/NumberOfPhpFiles.php

namespace EdisonLabs\Metric;

use EdisonLabs\Metrics\Metric\AbstractMetricBase;

class NumberOfPhpFiles extends AbstractMetricBase
{
    public function getName()
    {
        return 'Number of PHP files';
    }

    public function getDescription()
    {
        return 'The total number of PHP files';
    }

    public function getMetric()
    {
        // Put the logic to calculate the total of PHP files here.
        // ..

        // Random example.
        return rand(10, 50);
    }
}

Configure the autoload in composer.json:, (*6)

"autoload": {
    "psr-4": {
        "EdisonLabs\\Metric\\": "src/EdisonLabs/Metric"
    }
}

Re-create the Composer autoloader:, (*7)

composer dump-autoload

Collecting metrics

There are two ways to collect the metrics: programmatically and by command-line., (*8)

Programmatically

// collector.php

use EdisonLabs\Metrics\Collector;

$date = strtotime('now');
$config = array();

$collector = new Collector($date, $config);
$metrics = $collector->getMetrics();

Command

The command is located at vendor/bin/metrics. Include the vendor/bin directory in the system $PATH to run this command from anywhere., (*9)

Type metrics --help to see all the available options., (*10)

Saving metrics

Create datastore classes to save your metrics:, (*11)

// src/EdisonLabs/Metric/Datastore/SqLite.php

namespace EdisonLabs\Metric\Datastore;

use EdisonLabs\Metrics\Metric\Datastore\AbstractMetricDatastore;

class SqLite extends AbstractMetricDatastore
{
    public function getName()
    {
        return 'SQLite';
    }

    public function getDescription()
    {
        return 'Stores metrics to SQLite';
    }

    public function save()
    {
        $metrics = $this->getMetrics();

        // Put your logic to store the metrics to SQLite here.
        return true;
    }
}

Programmatically

// datastore.php

use EdisonLabs\Metrics\Collector;
use EdisonLabs\Metrics\DatastoreHandler;

$date = strtotime('now');
$config = array();

$collector = new Collector($date, $config);
$metrics = $collector->getMetrics();

$datastoreHandler = new DatastoreHandler($date, $config);
$datastore = $datastoreHandler->getDatastoreByName('SQLite');
$datastore->setMetrics($metrics);
$datastore->save();

Command

Use the option --save to list and save your metrics., (*12)

metrics --save=SQLite

The --save option accepts multiple values., (*13)

metrics --save=SQLite,MySql,MyCustomDatastore

The Versions

26/07 2018
26/07 2018

1.x-dev

1.9999999.9999999.9999999-dev

PHP library for collecting metrics.

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

25/07 2018

dev-sort-table

dev-sort-table

PHP library for collecting metrics.

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

18/07 2018

1.0.0-alpha1

1.0.0.0-alpha1

PHP library for collecting metrics.

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires