Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

195 lines (136 sloc) 4.273 kB

Installation

  • 1 First, add the dependent bundles to the vendor/bundles directory. Add the following lines to the composer.json file
"require": {
    # ..
    "liuggio/statsd-client-bundle": ">1.0.0",
    # ..
}
  • 2 Then run composer install

  • 3 Then add in your app/AppKernel

 class AppKernel extends Kernel
 {
     public function registerBundles()
     {
         $bundles = array(
         // ...
            new Liuggio\StatsDClientBundle\LiuggioStatsDClientBundle(),
         // ...
  • 4 Then add to config/yaml the minimal configuration
# app/config/config.yml
liuggio_stats_d_client:
  connection:
    host: localhost
    port: 8125

Working with the Service

StatsdDataFactory

This service creates the (StatsDataInterface) object to send

Reference: liuggio_stats_d_client.factory

$data = $this->get('liuggio_stats_d_client.factory')->increment('log.error');

StatsDClient

Reference: liuggio_stats_d_client.service

This service SENDS the data over the UDP interface

from a controller call $this->get('liuggio_stats_d_client.service')->send($data)

the $data is the object created by the factory

the send method will optimise the data sent in order to speed up the connection.

Working with Monolog

To monitor your logs, add the following lines to your application configuration file, in order to enable the StatsDHandler

# app/config/config.yml

liuggio_stats_d_client:
  connection:
    host: localhost
    port: 8125
    protocol: udp
    reduce_packet: true
    fail_silently: true
  enable_collector: false #default is false
  monolog:
    enable: true
    prefix: 'log'
    formatter: 'monolog.formatter.shortline' # optional but this will prettify the statsd key
    level: 'warning'
    context_logging: false # with this option you could also have the monolog context variable in your graphs

But you also have to say to Monolog to use that handler

# app/config/config.yml

monolog:
    handlers:
        main:
            type:         fingers_crossed
            action_level: warning
            handler:      grouped
        grouped:
            type:    group
            members: [streamed, stats_d]
        stats_d:
            type:  service
            id: monolog.handler.statsd
            level: warning
#            channels:
#                type:     exclusive # Include all, except those listed below
#                elements: [ ]
        streamed
            type:  stream
            path:  %kernel.logs_dir%/%kernel.environment%.log
            level: critical

Working with Personal Collector

If the information from Monolog is not enough for you, you can use the Collectors that collect the information and then send the data to the StatsD Server.

# app/config/config.yml
liuggio_stats_d_client:
  connection:
    host: localhost
    port: 8125
    protocol: udp
    reduce_packet: true
    fail_silently: true
  enable_collector: true
  collectors:
    liuggio_stats_d_client.collector.dbal: 'collect.query'
    liuggio_stats_d_client.collector.visitor: 'collect.visitor'
    liuggio_stats_d_client.collector.memory: 'collect.memory'
    liuggio_stats_d_client.collector.user: 'collect.user'
    liuggio_stats_d_client.collector.exception: 'collect.exception'

For example the liuggio_stats_d_client.collector.dbal will collect a lot of the information provided by the doctrine logging.

Full Configuration / Max Power

then add to config/yaml

# app/config/config.yml
liuggio_stats_d_client:
  monolog:
    enable: true
    prefix: 'log'
    formatter: 'monolog.formatter.shortline'
    level: 'warning'
    context_logging: true
  connection:
    host: localhost
    port: 8125
    protocol: udp
    reduce_packet: true
    fail_silently: true
  enable_collector: true
  collectors:
    liuggio_stats_d_client.collector.dbal: 'tvision.query'
    liuggio_stats_d_client.collector.visitor: 'tvision.visitor'
    liuggio_stats_d_client.collector.memory: 'tvision.memory'
    liuggio_stats_d_client.collector.user: 'tvision.user'
    liuggio_stats_d_client.collector.exception: 'tvision.exception'


Jump to Line
Something went wrong with that request. Please try again.