Created
November 23, 2012 15:17
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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