Skip to content
This repository has been archived by the owner on Jan 21, 2021. It is now read-only.

Commit

Permalink
Fixed a bug with the warning/error thresholds
Browse files Browse the repository at this point in the history
Removed time multiplication from template
  • Loading branch information
chrisjohnson00 committed Nov 22, 2013
1 parent 3649083 commit 6ffac3c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
14 changes: 8 additions & 6 deletions DataCollector/APIRequestDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public function __construct($warningThreshold, $errorThreshold)
public function collect(SymfonyRequest $request, SymfonyResponse $response, \Exception $exception = null)
{
$this->data = array(
'api_request' => $this->dataStore
'api_request' => array('data' => $this->dataStore,
'warningThreshold' => $this->warningThreshold,
'errorThreshold' => $this->errorThreshold)
);
}

Expand All @@ -56,30 +58,30 @@ public function attachData($url, $method, $requestHeaders = array(), $requestBod

public function getAPIData()
{
return $this->data['api_request'];
return $this->data['api_request']['data'];
}

public function warning()
{
return ($this->getTime() > $this->warningThreshold) ? true : false;
return ($this->getTime() > $this->data['api_request']['warningThreshold']) ? true : false;
}

public function error()
{
return ($this->getTime() > $this->errorThreshold) ? true : false;
return ($this->getTime() > $this->data['api_request']['errorThreshold']) ? true : false;
}

public function getTime()
{
$requestTime = 0;
foreach ($this->data['api_request'] as $data)
foreach ($this->data['api_request']['data'] as $data)
$requestTime = $requestTime + $data->getTime();
return $requestTime;
}

public function getCount()
{
return $this->data['api_request']->count();
return $this->data['api_request']['data']->count();
}

public function getName()
Expand Down
10 changes: 5 additions & 5 deletions Resources/views/DataCollector/apiRequest.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{% set status_color = "red" %}
{% endif %}
<span class="sf-toolbar-status">{{ collector.getCount }}</span> in
<span class="sf-toolbar-status sf-toolbar-status-{{ status_color }}">{{ '%0.2f'|format(collector.getTime*1000) }} ms</span>
<span class="sf-toolbar-status sf-toolbar-status-{{ status_color }}">{{ '%0.2f'|format(collector.getTime) }} ms</span>
</a>
</div>
<div class="sf-toolbar-info">
Expand All @@ -27,7 +27,7 @@
</div>
<div class="sf-toolbar-info-piece">
<b>Request Time</b>
<span>{{ '%0.2f'|format(collector.getTime*1000) }} ms</span>
<span>{{ '%0.2f'|format(collector.getTime) }} ms</span>
</div>
</div>
</div>
Expand All @@ -46,7 +46,7 @@
<strong>API</strong>
<span class="count">
<span>{{ collector.getCount }}</span>
<span>{{ '%0.2f'|format(collector.getTime*1000) }} ms</span>
<span>{{ '%0.2f'|format(collector.getTime) }} ms</span>
</span>
</span>
{% endblock %}
Expand All @@ -58,7 +58,7 @@
{% if collector.getAPIData %}
<ul class="alt">
{% for data in collector.getAPIData %}
<li class="{{ cycle(['odd', 'even'], loop.index) }}{% if data.response.statusCode and data.response.statusCode >= 500 %} error{% elseif data.getTime >= 300 %} warning{% endif %}">
<li class="{{ cycle(['odd', 'even'], loop.index) }}{% if data.response.statusCode and data.response.statusCode >= 500 %} error{% endif %}">
{{ apiRequest.display_message(data) }}
</li>
{{ apiRequest.display_details(data,apiRequest) }}
Expand Down Expand Up @@ -98,7 +98,7 @@
style="display: inline;">
<img id="minus{{ dataObj.getKey }}" alt="-" src="{{ asset('bundles/framework/images/blue_picto_less.gif') }}"
style="display: none;">
<span>{{ dataObj.request.method }} on <code>{{ dataObj.request.url }}</code> took {{ '%0.5f'|format(dataObj.response.time*1000) }}
<span>{{ dataObj.request.method }} on <code>{{ dataObj.request.url }}</code> took {{ '%0.5f'|format(dataObj.response.time) }}
ms and responded with a {{ dataObj.response.statusCode }}</span>
</div>
{% endmacro %}
Expand Down

0 comments on commit 6ffac3c

Please sign in to comment.