Permalink
Browse files

Add DataCollector for CouchDB

  • Loading branch information...
1 parent 8ca1c86 commit 7b9935486d3b4e9d6170a7b81df877f44d17954e @beberlei beberlei committed Jun 20, 2011
@@ -0,0 +1,65 @@
+<?php
+/*
+ * Doctrine CouchDB Bundle
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to kontakt@beberlei.de so I can send you a copy immediately.
+ */
+
+namespace Doctrine\Bundle\CouchDBBundle\DataCollector;
+
+use Symfony\Component\HttpKernel\DataCollector\DataCollector;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
+use Doctrine\CouchDB\HTTP\LoggingClient;
+
+class CouchDBDataCollector extends DataCollector
+{
+ private $clients = array();
+
+ public function addLoggingClient(LoggingClient $client, $name)
+ {
+ $this->clients[$name] = $client;
+ }
+
+ public function collect(Request $request, Response $response, \Exception $exception = null)
+ {
+ $this->data = array('duration' => array(), 'requests' => array(), 'requestcount' => 0, 'total_duration' => 0);
+ foreach ($this->clients AS $name => $client) {
+ $this->data['duration'][$name] = $client->totalDuration;
+ $this->data['requests'][$name] = $client->requests;
+ $this->data['requestcount'] += count($client->requests);
+ $this->data['total_duration'] += $client->totalDuration;
+ }
+ }
+
+ public function getDuration()
+ {
+ return $this->data['duration'];
+ }
+
+ public function getRequests()
+ {
+ return $this->data['requests'];
+ }
+
+ public function getRequestCount()
+ {
+ return $this->data['requestcount'];
+ }
+
+ public function getTotalDuration()
+ {
+ return $this->data['total_duration'];
+ }
+
+ public function getName()
+ {
+ return 'couchdb';
+ }
+}
@@ -78,6 +78,21 @@ protected function loadClientConnection($name, array $connection, ContainerBuild
$connection,
))
;
+
+ if (isset($connection['logging']) && $connection['logging'] === true) {
+ $def = new Definition('Doctrine\CouchDB\HTTP\Client');
+ $def->setFactoryService(sprintf('doctrine_couchdb.client.%s_connection', $name));
+ $def->setFactoryMethod('getHttpClient');
+ $def->setPublic(false);
+
+ $container->setDefinition(sprintf('doctrine_couchdb.httpclient.%s_client', $name), $def);
+
+ $def = $container->getDefinition('doctrine_couchdb.datacollector');
+ $def->addMethodCall('addLoggingClient', array(
+ new Reference(sprintf('doctrine_couchdb.httpclient.%s_client', $name)),
+ $name
+ ));
+ }
}
private function odmLoad($config, $container)
@@ -7,15 +7,18 @@
<parameters>
<parameter key="doctrine_couchdb.client.connection.class">Doctrine\CouchDB\CouchDBClient</parameter>
+ <parameter key="doctrine_couchdb.datacollector.class">Doctrine\Bundle\CouchDBBundle\DataCollector\CouchDBDataCollector</parameter>
</parameters>
<services>
- <service
- id="doctrine_couchdb.client.connection"
+ <service id="doctrine_couchdb.client.connection"
class="%doctrine_couchdb.client.connection.class%"
factory-class="%doctrine_couchdb.client.connection.class%"
factory-method="create"
abstract="true"
/>
+ <service id="doctrine_couchdb.datacollector" class="%doctrine_couchdb.datacollector.class%">
+ <tag name="data_collector" template="DoctrineCouchDBBundle:Collector:couchdb" id="couchdb" />
+ </service>
</services>
</container>
@@ -28,6 +28,10 @@
</parameters>
<services>
+ <service id="doctrine_couchdb.odm.metadata.annotation_reader" class="%doctrine.orm.metadata.annotation_reader.class%" public="false">
+ <argument type="service" id="annotation_reader" />
+ </service>
+
<service
id="doctrine_couchdb.odm.configuration"
class="%doctrine_couchdb.odm.configuration.class%"
@@ -0,0 +1,51 @@
+{% extends 'WebProfilerBundle:Profiler:layout.html.twig' %}
+
+{% block toolbar %}
+ {% set icon %}
+ <img width="28" height="28" alt="CouchDB" style="border-width: 0; vertical-align: middle; margin-right: 5px;" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAYAAAByDd+UAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sGFBUeCVNmlcQAAAOuSURBVEjH7Za7SytbFMZ/+5EQB3ygeYiKSkRF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TgQPpW0HmWdj3K5TDQaBaCrqwspJbZt//zvqQ5QH/UI6yU7OzvzIw+FQiQSiUAm/zQ+fl+n0+m/jahUKgWynJqaIhKJ+FX4N9bT04P40Vvbx378WdM/uvG/Av25tf1/AL8BJnMMRmFAbJ0AAAAASUVORK5CYII=" />
+ {% endset %}
+ {% set text %}
+ <span title="{{ '%0.2f'|format(collector.totalDuration * 1000) }} ms">{{ collector.requestCount }}</span>
+ {% endset %}
+ {% include 'WebProfilerBundle:Profiler:toolbar_item.html.twig' with { 'link': profiler_url } %}
+{% endblock %}
+
+{% block menu %}
+<span class="label">
+ <span class="icon"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAYAAAByDd+UAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sGFBUeCVNmlcQAAAOuSURBVEjH7Za7SytbFMZ/+5EQB3ygeYiKSkRFI0E7FWwsbMXCyr/B3tI/wkYEewsrwdZGVIIICikkCkoSDJqgxkdmRmfmFJcMGT3ee+65h1NczoLNHmbvNd9a6/vWni08z/P4jSb5zfYH8NcDftSM53l8T0e/Qlue56GFENze3rKxscHi4iJDQ0MAZDIZtra2mJiYYH5+nubmZlzX5fn5Gdd1aW5uplarcXZ2xvb2NlrrL4He3t5YWVkhHo/j77IsC9M0/U3RaJTl5WX6+/sBME2TnZ0dstksruvS1dXF4+MjtVqNtra2L8GEEDw8PPgV8gFt2+b29hbHcVBKkUwmfafHx0d2dnbI5XIopZBSUiqV/uJESjzPQwjxZRkb6dAAhmEwOztLKpX6rlO5XKZQKCCEwHVdAFpbW4nFYoTDYS4vL7FtGym/1mB9TVcqFQzDYG5uLhCVEMKf+/v7mZ6e5ujoiHg8Tl9fH729vfT29qK15vDwkP39fV5fX5FSBnzrVqlUkFKi4vH4qmEYdHZ2cnFxQSgUIhKJBECllMRiMZLJJOl0mpGREdrb21FKIYSgu7ubWCxGPp/HNE0ftDGBQqHAyckJKpVKrY6OjtLS0sLW1hahUIienh6/BHXQcDhMa2srTU1NgVLVOY9GowwODpLP57m/v8dxHF5eXlBKEQ6HfY2o6enpVdu2qVarXF1dcX5+zvj4OIZhBJTW2ItCCAqFAmtra+RyOUZHR9FaYxgG6XQaIQTZbBbLsmhqavKFZpomanJyctV1XYrFIo7jUC6X8TyP4eFhX4GNoI7jsLu7y+bmJtVqlWKxSLFYJJlMEolEkFIyMDDAzMwMlmVRKpXQWiOEoFaroaamplbr2SilMAyD6+trEokEHR0dPk8A+Xye9fV1jo+P0VqjlCIUCnF3d8fe3h4ADw8PFItFKpUKjuNwc3ODEMIH/HQ8KKV8PpeWlhgbG/PXDg4OqFarxONxn+NGVWYymUDPSSnRWgffNfLkOA6WZWFZFlprcrlcgLtkMklLS4sP4DgOtm1jmiamaeK6Lq7r4jgO7+/vvL294bpuQLGBDN/f33l6evJb4vT0lIWFBd8hkUhQq9WoVqufTpHGuf6slEJrHTgQPpW0HmWdj3K5TDQaBaCrqwspJbZt//zvqQ5QH/UI6yU7OzvzIw+FQiQSiUAm/zQ+fl+n0+m/jahUKgWynJqaIhKJ+FX4N9bT04P40Vvbx378WdM/uvG/Av25tf1/AL8BJnMMRmFAbJ0AAAAASUVORK5CYII=" alt="" /></span>
+ <strong>Doctrine CouchDB</strong>
+ <span class="count">
+ <span>{{ collector.requestCount }}</span>
+ <span>{{ '%0.0f'|format(collector.totalDuration * 1000) }} ms</span>
+ </span>
+</span>
+{% endblock %}
+
+{% block panel %}
+ <h2>CouchDB HTTP Requests</h2>
+
+ {% if not collector.requestCount %}
+ <p>
+ <em>No http requests to a CouchDB.</em>
+ </p>
+ {% else %}
+ {% for conn,requests in collector.requests %}
+ <h3>Database {{ conn }}</h3>
+
+ <ul class="alt">
+ {% for i, request in requests %}
+ <li class="{{ i is odd ? 'odd' : 'even' }}">
+ <div><strong>{{ request.method }}</strong> {{ request.path }}</div>
+ <small>
+ <strong>Status</strong>: {{ request.response_status }}<br />
+ <strong>Duration</strong>: {{ '%0.2f'|format(request.duration * 1000) }} ms<br />
+ <strong>Request-Size</strong>: {{ request.request_size }}
+ </small>
+ <div><code>{{ request.response|json_encode }}</code></div>
+ </li>
+ {% endfor %}
+ </ul>
+ {% endfor %}
+ {% endif %}
+
+{% endblock %}

0 comments on commit 7b99354

Please sign in to comment.