This article is the last part of Install Stats.d / Graphite on a debian server in order to monitor a Symfony2 application (1/2).

Last week, we saw that StatsDClientBundle provides great metrics for your application,. But what if I want to monitor my own things in my application ? During the last part of this tutorial, we will see how to monitor our own application events. I'll assume you did the first part of the tutorial.

In my personnal application (named Seek Team), gamers can purchase a premium account in order to unlock additional features on the website.

users 150x150 Monitor your Symfony2 application via Stats.d and Graphite (2/2) I wanted to display on my graphite dashboard, which looked like the screen on the left, the statistics on how many premium accounts were ordered, cancelled, activated or finished.

So here's what I did :

The following code is pretty simple. In the Controller functions, we dispatch 2 events named Events::PREMIUM_CANCEL and Events::PREMIUM_SUCCESS using the EventDispatcher and a GenericEvent whether the payment was complete or not.

Next thing to do, is to create & plug our listener and tell him to listen to those events.

You have noticed in the constructor the presence of 2 services that we need in order to send to Stats.d the data. Each time you'll add a "." to your stats category (in the example I used premium.success, it'll create a subfolder in your graphite dashboard).

So let's inject them via the DI.

And it's done, if you go on your graphite dashboard, you can now see the new category called "premium"premium stat 256x300 Monitor your Symfony2 application via Stats.d and Graphite (2/2)