Skip to content

This repository is still in development, please, don't use in production until tagged V1.0 !!! ZF2 module for automating monitoring/profiling tasks within a Zend Framework 2 with StatsD

Notifications You must be signed in to change notification settings

corentin-larose/zf-statsd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zf Statsd

Build Status

Introduction

zf-statsd is a ZF2 module for automating monitoring/profiling tasks within a Zend Framework 2 with StatsD.

Installation

Run the following composer command:

$ composer require "corentin-larose/zf-statsd:dev-master"

Alternately, manually add the following to your composer.json, in the require section:

"require": {
    "corentin-larose/zf-statsd": "dev-master"
}

And then run composer update to ensure the module is installed.

Finally, add the module name to your project's config/application.config.php under the modules key:

return array(
    /* ... */
    'modules' => array(
        /* ... */
        'ZF\Statsd',
    ),
    /* ... */
);

Configuration

User Configuration

As a rule of thumb, avoid as much as possible using anonymous functions since it prevents you from caching your configuration.

The top-level configuration key for user configuration of this module is zf-statsd.

The config/module.config.php file contains a self-explanative example of configuration.

Key: enable

The enable key is utilized for enabling/disabling the statsd module at run time. If you no longer need this module, rather consider removing the module from the application.config.php list.

Example:

'zf-statsd' => array(
    /* ... */
    'enable' => true, // Statsd module is enabled.
    /* ... */
),    

Key: memory_pattern

The memory_pattern key is utilized to configure the metric name pattern for the memory related data. All token surrounded by % will be replaced with the corresponding value (see the available token list below). You can remove, add and sort tokens at your will.

Example:

'zf-statsd' => array(
    /* ... */
    'memory_pattern' => '%hostname%.%controller%.%http-method%.%http-code%.%response-content-type%.%mvc-event%.memory',
    /* ... */
),    

Key: timer_pattern

The timer_pattern key is utilized to configure the metric name pattern for the time related data. All token surrounded by % will be replaced with the corresponding value (see the available token list below). You can remove, add and sort tokens at your will.

Example:

'zf-statsd' => array(
    /* ... */
    'timer_pattern' => '%hostname%.%controller%.%http-method%.%http-code%.%response-content-type%.%mvc-event%.duration',
    /* ... */
),    
Token: %hostname%

Will be replaced with the value returned by hostname() function.

Token: %controller%

Will be replaced with the value returned by Zend\Mvc\MvcEvent::getRouteMatch()->getParam('controller') method.

Token: %http-method%

Will be replaced with the value returned by Zend\Http\Request::getMethod() method.

Token: %http-code%

Will be replaced with the value returned by Zend\Http\Response::getStatusCode() method.

Token: %response-content-type%

Will be replaced with the value returned by Zend\Http\Response::getHeaders()->get('content-type')->getFieldValue() method.

Token: %mvc-event%

Will be replaced with the value returned by Zend\Mvc\MvcEvent::getName() method.

Key: metric_tokens_callback

Callback used to override the case of the metric names, must be a valid PHP callback.

Example:

'zf-statsd' => array(
    /* ... */
    'metric_tokens_callback' => 'strtolower',
    /* ... */
),    

Key: replace_dots_in_tokens

Whether to override a . found in a string used in the metric name. If true, . will be replaced with the value of the replace_special_chars_with key.

Example:

'zf-statsd' => array(
    /* ... */
    'replace_dots_in_tokens' => true,
    /* ... */
),    

Key: replace_special_chars_with

Char used to replace all special chars encountererd within a string used in the metric name.

Example:

'zf-statsd' => array(
    /* ... */
    'replace_special_chars_with' => '-',
    /* ... */
),    

Key: statsd

Statsd host and port.

Example:

'zf-statsd' => array(
    /* ... */
    'statsd' => array(
        'host' => '127.0.0.1',
        'port' => '8125',
    ),
    /* ... */
),    

ZF2 Events

Listeners

ZF\Statsd\StatsdListener

This listener is attached twice on each Zend\Mvc\Application event, once with the very low priority of -10000 to collect metrics before event propagation, once with the very high priority of 10000 to collect metrics after event propagation.

Display events in console

Install NodeJs an NPM:

apt-get install nodejs npm

Clone StatsD

git clone https://github.com/etsy/statsd.git

Create a config

cd statsd && cp exampleConfig.js config.js

Edit config.js

{
port: 8125
, backends: [ "./backends/console" ]
}

Start StatsD

node stats.js ./config.js

About

This repository is still in development, please, don't use in production until tagged V1.0 !!! ZF2 module for automating monitoring/profiling tasks within a Zend Framework 2 with StatsD

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages