Skip to content

Instantly share code, notes, and snippets.

@tristanbes
Created November 23, 2012 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tristanbes/4136092 to your computer and use it in GitHub Desktop.
Save tristanbes/4136092 to your computer and use it in GitHub Desktop.
Controller Example of Monitor your Symfony2 application via Stats.d and Graphite (2/2)
<?php
namespace SeekTeam\PremiumBundle\Event\Listener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
use SeekTeam\PremiumBundle\Event\Events;
class StatsListener implements EventSubscriberInterface
{
protected $statsdFactory;
protected $statsdClient;
public function __construct($statsdFactory, $statsdClient)
{
$this->statsdFactory = $statsdFactory;
$this->statsdClient = $statsdClient;
}
public static function getSubscribedEvents()
{
return array(
Events::PREMIUM_SUCCESS => 'onPremiumSuccess',
Events::PREMIUM_START => 'onPremiumStart',
Events::PREMIUM_CANCEL => 'onPremiumCancel',
Events::PREMIUM_ERROR => 'onPremiumError',
);
}
public function onPremiumSuccess(GenericEvent $event)
{
$data = $this->statsdFactory->createStatsDataIncrement('premium.success');
$this->statsdClient->send($data);
}
public function onPremiumCancel(GenericEvent $event)
{
$data = $this->statsdFactory->createStatsDataIncrement('premium.cancel');
$this->statsdClient->send($data);
}
public function onPremiumStart(GenericEvent $event)
{
$data = $this->statsdFactory->createStatsDataIncrement('premium.start');
$this->statsdClient->send($data);
}
public function onPremiumError(GenericEvent $event)
{
$data = $this->statsdFactory->createStatsDataIncrement('premium.error');
$this->statsdClient->send($data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment