PHPackages                             edisonlabs/metrics - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. edisonlabs/metrics

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

edisonlabs/metrics
==================

PHP library for collecting metrics.

1.x-dev(7y ago)2465[1 PRs](https://github.com/EdisonLabs/metrics/pulls)GPL-2.0+PHP

Since Jul 18Pushed 7y ago6 watchersCompare

[ Source](https://github.com/EdisonLabs/metrics)[ Packagist](https://packagist.org/packages/edisonlabs/metrics)[ RSS](/packages/edisonlabs-metrics/feed)WikiDiscussions 1.x Synced 2mo ago

READMEChangelogDependenciesVersions (4)Used By (0)

[![Build Status](https://camo.githubusercontent.com/1e90a9942aefc6a91e7e9c5b41f470099658fa0e9cb801eb9ddc612f53c7640b/68747470733a2f2f7472617669732d63692e636f6d2f456469736f6e4c6162732f6d6574726963732e7376673f6272616e63683d312e78)](https://travis-ci.com/EdisonLabs/metrics)[![Coverage Status](https://camo.githubusercontent.com/ba09d3cd48966a51bc18e6f852d39a08e5d43528ed6b2112eab90c842cf7d972/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f456469736f6e4c6162732f6d6574726963732f62616467652e737667)](https://coveralls.io/github/EdisonLabs/metrics)

Metrics Collector
=================

[](#metrics-collector)

Overview
--------

[](#overview)

The Metrics Collector is a simple library that provides base classes to easily extend and collect custom metrics.

Usage
-----

[](#usage)

This library does not provide any metrics by default. To create new metrics, [create a Composer package](https://getcomposer.org/doc/01-basic-usage.md) and then add a dependency to this package:

```
composer require edisonlabs/metrics

```

Now create the metrics classes extending `edisonlabs/metrics` classes.

Example: Number of PHP files.

```
// 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`:

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

Re-create the Composer autoloader:

```
composer dump-autoload

```

Collecting metrics
------------------

[](#collecting-metrics)

There are two ways to collect the metrics: programmatically and by command-line.

#### Programmatically

[](#programmatically)

```
// collector.php

use EdisonLabs\Metrics\Collector;

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

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

#### Command

[](#command)

The command is located at `vendor/bin/metrics`. Include the `vendor/bin` directory in the system `$PATH` to run this command from anywhere.

Type `metrics --help` to see all the available options.

Saving metrics
--------------

[](#saving-metrics)

Create datastore classes to save your metrics:

```
// 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

[](#programmatically-1)

```
// 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

[](#command-1)

Use the option `--save` to list and save your metrics.

```
metrics --save=SQLite

```

The `--save` option accepts multiple values.

```
metrics --save=SQLite,MySql,MyCustomDatastore

```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 82.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~123 days

Total

3

Last Release

2606d ago

### Community

---

Top Contributors

[![jkribeiro](https://avatars.githubusercontent.com/u/1932061?v=4)](https://github.com/jkribeiro "jkribeiro (32 commits)")[![manuee](https://avatars.githubusercontent.com/u/105582?v=4)](https://github.com/manuee "manuee (5 commits)")[![douggreen](https://avatars.githubusercontent.com/u/1244341?v=4)](https://github.com/douggreen "douggreen (1 commits)")[![kmoll](https://avatars.githubusercontent.com/u/4575507?v=4)](https://github.com/kmoll "kmoll (1 commits)")

### Embed Badge

![Health badge](/badges/edisonlabs-metrics/health.svg)

```
[![Health](https://phpackages.com/badges/edisonlabs-metrics/health.svg)](https://phpackages.com/packages/edisonlabs-metrics)
```

###  Alternatives

[psr/log

Common interface for logging libraries

10.4k1.2B9.1k](/packages/psr-log)[itsgoingd/clockwork

php dev tools in your browser

5.9k27.6M94](/packages/itsgoingd-clockwork)[graylog2/gelf-php

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

41838.2M137](/packages/graylog2-gelf-php)[bugsnag/bugsnag-psr-logger

Official Bugsnag PHP PSR Logger.

32132.5M2](/packages/bugsnag-bugsnag-psr-logger)[consolidation/log

Improved Psr-3 / Psr\\Log logger based on Symfony Console components.

15462.2M7](/packages/consolidation-log)[datadog/php-datadogstatsd

An extremely simple PHP datadogstatsd client

19124.6M15](/packages/datadog-php-datadogstatsd)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
