PHPackages                             socloz/monitoring-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. socloz/monitoring-bundle

ActiveSymfony-bundle[Logging &amp; Monitoring](/categories/logging)

socloz/monitoring-bundle
========================

A profiling/monitoring Symfony2 bundle for production servers - alerts on exceptions, logs profiling data &amp; sends data to statsd/graphite

1.2.5(6y ago)6944.2k6[7 issues](https://github.com/SoCloz/SoclozMonitoringBundle/issues)MITPHPPHP &gt;=5.3.2CI failing

Since Dec 16Pushed 6y ago17 watchersCompare

[ Source](https://github.com/SoCloz/SoclozMonitoringBundle)[ Packagist](https://packagist.org/packages/socloz/monitoring-bundle)[ Docs](https://github.com/SoCloz/SoclozMonitoringBundle)[ RSS](/packages/socloz-monitoring-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (7)Versions (11)Used By (0)

SoclozMonitoringBundle
======================

[](#soclozmonitoringbundle)

[![Build Status](https://camo.githubusercontent.com/f98592461fcbfa9b993db9409b1fd445dc602493bde401fe29e5d2801440fabd/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f536f436c6f7a2f536f636c6f7a4d6f6e69746f72696e6742756e646c652e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/SoCloz/SoclozMonitoringBundle)

Warning
-------

[](#warning)

**First stable version was released and tagged, if you don't want to change anything, you should use version 1.0.0, otherwise see [CHANGELOG.md](CHANGELOG.md) to see what has changed**

Introduction
------------

[](#introduction)

A monitoring Symfony2 bundle for production servers that :

- sends emails on unhandled exceptions,
- profiles PHP code and sends profiling information to statsd,
- logs request profiling information,
- *new* adds Request IDs/pid to log files/HTTP headers to troubleshoot bugs.

Dependencies
------------

[](#dependencies)

Exceptions catching : none.

Profiling :

- *(optional)* [xhprof](http://pecl.php.net/package/xhprof)
- *(optional)* [StatsD](https://github.com/etsy/statsd) (+ any graphing backend, e.g. [Graphite](http://graphite.wikidot.com))

Profiled data
-------------

[](#profiled-data)

- *request* : number of HTTP requests (handled by Symfony) / duration of requests
- *mongodb* : number of mongodb calls (insert/batchInsert/update/save/remove/count/find/findOne) / total duration (requires xhprof)
- *redis* : number of redis calls / total duration (only phpredis calls are tracked - ) (requires xhprof)
- *sphinx* : number of sphinx calls (query/runQueries/updateAttributes/buildExcerpts/buildKeywords) / total duration (requires xhprof)
- *curl* : number or curl calls (curl\_exec/curl\_multi\_exec) / total duration (requires xhprof)

For each piece of data, you get :

- a global graph,
- a per route graph.

What do I get ?
---------------

[](#what-do-i-get-)

Thanks to graphite, you can get some nice graphs : \[TODO\]

You also get the following log messages :

```
[2013-06-10 10:38:31] app.INFO: /page/page_slug : 2041 ms mongodb : 6 calls/108 ms redis : 9 calls/2 ms [] {"request_id":"785317517bccd92b4da08d88b4c09fe5","pid":5503}

```

Debugging using Request IDs
---------------------------

[](#debugging-using-request-ids)

For each HTTP request (or script), a Request ID is computed. It enabled you to correlate logs from various services (webservices, database requests, ...).

This Request ID is forwarded to external webservices called using Guzzle using the X-RequestID HTTP header.

The Request ID is automatically :

- added to the HTTP response as a X-RequestID header,
- added to all log lines (as long as the pid),
- added to all Guzzle outgoing requests as a X-RequestID header.

If a X-RequestID HTTP header is found, its value will be used for the Request ID. If you call a SoclozMonitoringBundle powered webservice using Guzzle, the logs for the webservice will use the same request\_id as the master request.

You should forward the Request ID to all the external services used. For example, you can add the Request ID to all your database queries as a SQL comment :

```
$requestId = $this->get("socloz_monitoring.request_id")->getRequestId();
$sql = "SELECT /* {"request_id":"$requestId"} */ * FROM my_table WHERE col = ?";
```

FAQ
---

[](#faq)

1. *Is it helpful ?*

    If you are not convinced that profiling on production servers is helpful, this module is not for you.
2. *What can I do to limit the overhead ?*

    On large sites, the recommended setup is :

- activate xhprof only on a couple servers (or on none if the overhead is really too important). The module will disable profiling if xhprof is absent.
- enable sampling. By default, all requests are profiled; you can lower the number of requests profiled by setting `socloz_monitoring.profiler.sampling` (a value 50 will profile 50% of requests).

3. *Can it profile database calls ? memcached calls ?*

    Yes (as long as the calls can be identified in xprof data). Contributions are welcomed for new parsers (mysql, pgsql, ...). See `Resources/config/profiler.xml` for examples.
4. *I don't like receiving emails on errors. Can I use rollbar/airbrake/sentry instead ?*

    Yes. Monolog already has a decent support for those tools. Please refer to the [monolog doc](https://github.com/Seldaek/monolog#log-specific-servers-and-networked-logging).
5. *Are yo hiring ?*

    Yes. If you are looking for a job in Paris, France, send a mail to techjobs AT socloz DOT com

Setup
-----

[](#setup)

- Install `xhprof`, `statsd` and a graphing backend (i.e. `graphite`)
- Install &amp; activate the module
- Configure the module : `socloz_monitoring.mailer.from` (source email of the exception alert mails), `socloz_monitoring.mailer.to` (destination email of the exception alert mails), `socloz_monitoring.statsd.host` (IP address/hostname of the statsd server), `socloz_monitoring.statsd.port` (port ot the statsd server), `socloz_monitoring.statsd.prefix` (prefix of the statsd keys)
- Decide what you want to profile : `socloz_monitoring.profiling.request` (HTTP requests), `socloz_monitoring.profiling.mongodb` (MongoDB calls)

If you are using statsd version 0.4 or later :

- set `socloz_monitoring.statsd.merge_packets` to `true`
- if the statsd server isn't on the same LAN as your server, set `socloz_monitoring.statsd.packet_size` to `512`, otherwise keep the default value

The default configuration is :

```
socloz_monitoring:
    exceptions:
        enable: true
        ignore: ['Symfony\Component\HttpKernel\Exception\NotFoundHttpException','Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException']
    profiler:
        enable: true
        sampling: 100
        mongodb: false
        request: false
        redis: false
        sphinx: false
    mailer:
        enable: true
        from:
        to:
    statsd:
        enable: false
        host:
        port:
        prefix: socloz_monitoring
        always_flush: false
        merge_packets: false
        packet_size: 1432
    request_id:
        enable: true
        add_pid: true
    logger:
        enable: false
```

Graphing application data
-------------------------

[](#graphing-application-data)

It is possible to send some application data to statsd :

Counters :

```
$container->get('socloz_monitoring.statsd')->updateStats("counter_name", $number);
```

Gauges :

```
$container->get('socloz_monitoring.statsd')->gauge("gauge_name", $number);
```

Timers :

```
$start = microtime(true);
// do some stuff
$end = microtime(true);
$container->get('socloz_monitoring.statsd')->timing("timer_name", ($end-$start)*1000);
```

Just make sure you don't have any name collisions between your counters/timers and the standard ones.

Stats are buffered and sent at the end of the script/request. In long running scripts, you should flush statsd regularly :

```
$container->get('socloz_monitoring.statsd')->flush();
```

You can also configure statsd to always send data immediately :

```
socloz_monitoring:
    statsd:
        always_flush: true
```

Finding data in graphite
------------------------

[](#finding-data-in-graphite)

The statsd data is (on unmodified configs) :

- `stats.timers.prefix.{mongodb,request, ...}.{lower,mean_90,upper,upper_90}` - timing information
- `stats.prefix.{mongodb,request, ...} / stats_counts.prefix.{mongodb,request, ...}` - counters
- `stats.timers.prefix.per_route.{mongodb,request, ...}.{route}.{lower,mean_90,upper,upper_90}` - per route timing information
- `stats.prefix.per_route.{mongodb,request, ...}.{route}` - per route counters

Hints
-----

[](#hints)

Graphite hints

- *number of mongodb calls per request* : `divideSeries(stats_counts.socloz_monitoring.mongodb, stats_counts.socloz_monitoring.request)`

Roadmap
-------

[](#roadmap)

- Parsers : mysql, memcached
- Integrated graphite templates
- Tracking of events (code releases, ...)
- Rate limiting of mails

Thanks
------

[](#thanks)

Exception handling inspired by [RoxWayErrorNotifyBundle](https://github.com/szymek/RoxWayErrorNotifyBundle)

StatsD client taken from Etsy [StatsD](https://github.com/etsy/statsd)

Xhprof listener inpired by [JnsXhprofBundle](https://github.com/jonaswouters/XhprofBundle)

License
-------

[](#license)

This bundle is released under the MIT license (see LICENSE).

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~214 days

Recently: every ~450 days

Total

10

Last Release

2239d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ddf0032ce996c1e739b1ce4084c2dfe77dec9bb58c5281aa3b3cca5722346364?d=identicon)[noisebynorthwest](/maintainers/noisebynorthwest)

---

Top Contributors

[![mhor](https://avatars.githubusercontent.com/u/4103719?v=4)](https://github.com/mhor "mhor (44 commits)")[![jfbus](https://avatars.githubusercontent.com/u/808338?v=4)](https://github.com/jfbus "jfbus (43 commits)")[![NoiseByNorthwest](https://avatars.githubusercontent.com/u/1461284?v=4)](https://github.com/NoiseByNorthwest "NoiseByNorthwest (7 commits)")[![jdecool](https://avatars.githubusercontent.com/u/433926?v=4)](https://github.com/jdecool "jdecool (3 commits)")[![Ouark](https://avatars.githubusercontent.com/u/119316?v=4)](https://github.com/Ouark "Ouark (2 commits)")[![jamyouss](https://avatars.githubusercontent.com/u/1369214?v=4)](https://github.com/jamyouss "jamyouss (1 commits)")

---

Tags

monitoringstatsdemailprofilingexceptionsxhprofproductiongraphitealerting

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/socloz-monitoring-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/socloz-monitoring-bundle/health.svg)](https://phpackages.com/packages/socloz-monitoring-bundle)
```

###  Alternatives

[rollbar/rollbar

Monitors errors and exceptions and reports them to Rollbar

33723.7M82](/packages/rollbar-rollbar)[liip/monitor-bundle

Liip Monitor Bundle

4728.7M16](/packages/liip-monitor-bundle)[datadog/php-datadogstatsd

An extremely simple PHP datadogstatsd client

19124.6M15](/packages/datadog-php-datadogstatsd)[liuggio/statsd-client-bundle

Provides a statsd client and simple ready-to-use support for #Symfony2 Application

164730.7k](/packages/liuggio-statsd-client-bundle)[liuggio/statsd-php-client

Statsd (Object Oriented) client library for PHP

1153.9M9](/packages/liuggio-statsd-php-client)[slickdeals/statsd

a PHP client for statsd

264.5M8](/packages/slickdeals-statsd)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
