2017 © Pedro PelĂĄez
 

library metrics

Simple library to talk to metrics collector services.

image

beberlei/metrics

Simple library to talk to metrics collector services.

  • Tuesday, July 17, 2018
  • by beberlei
  • Repository
  • 12 Watchers
  • 249 Stars
  • 299,456 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 30 Forks
  • 7 Open issues
  • 19 Versions
  • 5 % Grown

The README.md

Metrics

Build Status, (*1)

Simple library that abstracts different metrics collectors. I find this necessary to have a consistent and simple metrics API that doesn't cause vendor lock-in., (*2)

It also ships with a Symfony Bundle. This is not a library for displaying metrics., (*3)

Currently supported backends:, (*4)

  • Doctrine DBAL
  • Graphite
  • InfluxDB
  • Telegraf
  • Librato
  • Logger (Psr\Log\LoggerInterface)
  • Null (Dummy that does nothing)
  • Prometheus
  • StatsD
  • Zabbix
  • DogStatsD

Installation

Using Composer:, (*5)

composer require beberlei/metrics

API

You can instantiate clients:, (*6)

<?php

$collector = \Beberlei\Metrics\Factory::create('statsd');

You can measure stats:, (*7)

<?php

$collector->increment('foo.bar');
$collector->decrement('foo.bar');

$start = microtime(true);
$diff  = microtime(true) - $start;
$collector->timing('foo.bar', $diff);

$value = 1234;
$collector->measure('foo.bar', $value);

Some backends defer sending and aggregate all information, make sure to call flush:, (*8)

<?php

$collector->flush();

Configuration

<?php
$statsd = \Beberlei\Metrics\Factory::create('statsd');

$zabbix = \Beberlei\Metrics\Factory::create('zabbix', array(
    'hostname' => 'foo.beberlei.de',
    'server'   => 'localhost',
    'port'     => 10051,
));

$zabbixConfig = \Beberlei\Metrics\Factory::create('zabbix_file', array(
    'hostname' => 'foo.beberlei.de',
    'file'     => '/etc/zabbix/zabbix_agentd.conf'
));

$librato = \Beberlei\Metrics\Factory::create('librato', array(
    'hostname' => 'foo.beberlei.de',
    'username' => 'foo',
    'password' => 'bar',
));

$null = \Beberlei\Metrics\Factory::create('null');

Symfony Bundle Integration

Register Bundle into Kernel:, (*9)

<?php

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        //..
        $bundles[] = new \Beberlei\Bundle\MetricsBundle\BeberleiMetricsBundle();
        //..
    }
}

Do Configuration:, (*10)

# app/config/config.yml
beberlei_metrics:
    default: foo
    collectors:
        foo:
            type: statsd
        bar:
            type: zabbix
            prefix: foo.beberlei.de
            host: localhost
            port: 10051
        baz:
            type: zabbix_file
            prefix: foo.beberlei.de
            file: /etc/zabbix/zabbix_agentd.conf
        librato:
            type: librato
            username: foo
            password: bar
            source: hermes10
        dbal:
            type: doctrine_dbal
            connection: metrics # using the connection named "metrics"
        monolog:
            type: monolog
        influxdb:
            type: influxdb
            influxdb_client: influxdb_client_service # using the InfluxDB client service named "influxdb_client_service"
            tags:
                dc: "west"
                node_instance: "hermes10"
        prometheus:
            type: prometheus
            prometheus_collector_registry: prometheus_collector_registry_service # using the Prometheus collector registry service named "prometheus_collector_registry_service"
            namespace: app_name # optional
            tags:
                dc: "west"
                node_instance: "hermes10"

This adds collectors to the Metrics registry. The functions are automatically included in the Bundle class so that in your code you can just start using the convenient functions. Metrics are also added as services:, (*11)

<?php

$metrics = $container->get('beberlei_metrics.collector.foo');

and the default collector can be fetched:, (*12)

<?php

$metrics = $container->get('beberlei_metrics.collector');

The Versions

19/10 2016

v2.2.0

2.2.0.0

Simple library to talk to metrics collector services.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Benjamin Eberlei

logging metrics

19/09 2016

v2.1.0

2.1.0.0

Simple library to talk to metrics collector services.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Benjamin Eberlei

logging metrics

05/11 2015

v2.0.3

2.0.3.0

Simple library to talk to metrics collector services.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Benjamin Eberlei

logging metrics

22/10 2015

v2.0.2

2.0.2.0

Simple library to talk to metrics collector services.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Benjamin Eberlei

logging metrics

21/06 2015

v2.0.1

2.0.1.0

Simple library to talk to metrics collector services.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Benjamin Eberlei

logging metrics

20/02 2015

v2.0.0

2.0.0.0

Simple library to talk to metrics collector services.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Benjamin Eberlei

logging metrics

21/01 2015

v2.0.0-RC1

2.0.0.0-RC1

Simple library to talk to metrics collector services.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Benjamin Eberlei

logging metrics

15/01 2015

v1.1.2

1.1.2.0

Simple library to talk to metrics collector services.

  Sources   Download

MIT

The Development Requires

by Benjamin Eberlei

logging metrics

09/01 2014

v1.1.1

1.1.1.0

Simple library to talk to metrics collector services.

  Sources   Download

MIT

The Development Requires

by Benjamin Eberlei

logging metrics

08/01 2014

v1.1.0

1.1.0.0

Simple library to talk to metrics collector services.

  Sources   Download

MIT

The Development Requires

by Benjamin Eberlei

logging metrics

02/06 2012

v1.0

1.0.0.0

Simple library to talk to metrics collector services.

  Sources   Download

MIT

The Development Requires

by Benjamin Eberlei

logging metrics