PHPackages                             myoperator/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. myoperator/metrics

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

myoperator/metrics
==================

Metrics wrapper that pushes your metrics to StatsD server

2.2.0(10y ago)03MITPHPPHP &gt;= 5.3.0CI failing

Since Dec 9Pushed 6y agoCompare

[ Source](https://github.com/myoperator/metrics)[ Packagist](https://packagist.org/packages/myoperator/metrics)[ Docs](https://domnikl.github.com/statsd-php)[ RSS](/packages/myoperator-metrics/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (1)Versions (7)Used By (0)

Metrics
=======

[](#metrics)

This library serves as a base for application metrics for myoperator PHP based applications.

Dependencies
------------

[](#dependencies)

- codeasashu/statsd-php (Composer package)
- php &gt;= 7.2
- UDP statsd connection

Quick Start
-----------

[](#quick-start)

Install this library as composer dependecy in any project you want to add metrics to.

```
composer require myoperator/metrics
```

or simple add this to your `composer.json`

```
{
    "require": {
        "myoperator/metrics": "^1"
    }
}
```

Then initialise `Metrics` instance in your bootstrap script or any init'able script

```
use MyOperator\Metrics\Metrics;

Metrics::setApplication('your-app-name'); // Your metrics base name
Metrics::setConnection('localhost', 8125); // UDP connection host and port
```

Then you can get `Metrics` instance anywhere in your application and can send metrics. For instance, to send `timing` metrics for a time taking function:

```
Metrics::getInstance()->startTiming('fn.time');
$this->consumeTime();
Metrics::getInstance()->endTiming('fn.time'); //Same name that you started logging time with
```

**NOTE** This repo is extension of source code at

To see all documentation, please go through documentation and see the availble methods and logging mechanism

Metric Types
------------

[](#metric-types)

Following metric types are supported, and their method names are same as well

### Counter

[](#counter)

Counter sends a arbitary count of anything, *which can only increase by time*

for example:

```
$user->login(); //some method to login user
metrics::getinstance()->count('user.login', 1); //increase user login by 1
```

counters can be used to log:

- Number of requests served
- Tasks completed (user login, invoices generated)
- Errors or exceptions

### Gauge

[](#gauge)

Gauges are used to metric any arbitary random number which can increase or decrease by time

for example:

```
$items = $queue->getItems(); //some method to get items in queue
metrics::getinstance()->count('queue.item.count', count($items)); //Send number of items in queue
```

Gauges can be used to log:

- Number of items in queues
- Memory size of cache
- Number of active process/threads/containers

### Timers

[](#timers)

Timers forms a very cruitial component for any metrics, add it forms the basis of SLOs. Also, timing can be used to calculate averages, sum etc.

Timing can be recorded in following ways:

#### Start and Stop based timers

[](#start-and-stop-based-timers)

Here, we start the timer and stop when the task is done. This is best suited for cases where we are doing the task in same script.

```
Metric::getInstance()->startTiming('task.time'); //String for reference
$task->takeTime(); //Time taking task
Metric::getInstance()->endTiming('task.time'); //End the time
```

#### Self time calculation

[](#self-time-calculation)

If you want to time your metric yourself, you can do so by using `timing` method:

```
$starttime = microtime(true);
$task->takeTime(); //Some time taking task
$timeconsmed = (microtime(true) - $starttime) * 1000;
Metric::getInstance()->timing('task.time', $timeconsmed);
```

#### Callback based approach

[](#callback-based-approach)

```
Metric::getInstance()->time("task.time", function() {
    $task->takeTime(); //Some time taking task
});
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~357 days

Recently: every ~430 days

Total

6

Last Release

2388d ago

PHP version history (3 changes)2.0.1PHP &gt;= 5.4.0

2.2.0PHP &gt;= 5.3.0

1.0PHP &gt;= 7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/13e9ef65aca6c94519bd96b589043034c126905d9d219f0d1d2362c9a06482ff?d=identicon)[codeasashu](/maintainers/codeasashu)

---

Top Contributors

[![codeasashu](https://avatars.githubusercontent.com/u/1492350?v=4)](https://github.com/codeasashu "codeasashu (13 commits)")

---

Tags

monitoringstatsdMetricsstatisticsudp

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[slickdeals/statsd

a PHP client for statsd

264.5M8](/packages/slickdeals-statsd)[datadog/php-datadogstatsd

An extremely simple PHP datadogstatsd client

19124.6M15](/packages/datadog-php-datadogstatsd)[liuggio/statsd-php-client

Statsd (Object Oriented) client library for PHP

1153.9M9](/packages/liuggio-statsd-php-client)[krenor/prometheus-client

A PHP Client for Prometheus

1020.9k](/packages/krenor-prometheus-client)

PHPackages © 2026

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