Skip to content

Commit ab6a293

Browse files
authored
Merge pull request #19 from mpchadwick/release/v0.4
Release v0.4.0 -> Master
2 parents 29fecb6 + dbf9a08 commit ab6a293

File tree

6 files changed

+67
-19
lines changed

6 files changed

+67
-19
lines changed

README.md

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,33 @@ All configuration is done through an XML file in the `/app/etc` directory. This
88

99
- `Mpchadwick_PageCacheHitRate_Model_Processor` is added as a `<request_processor>`.
1010
- **Note:** `request_processor`s are loaded alphabetically based on the file name in `/app/etc`. It is important that `Mpchadwick_PageCacheHitRate_Model_Processor` be the final `request_processor` to know for sure if this is a full hit. By default the `Enterprise_PageCache_Model_Processor` is defined in `enterprise.xml` and will be loaded first, however if your are using something else to process the result of `Enterprise_PageCache_Model_Processor` you may need to change the file name in `/app/etc`.
11-
- A `<tracker>` can be configured your `<full_page_cache>` configuration. If this node is omitted, hit rate will not be tracked.
11+
- `<tracker>`s can be configured in your `<full_page_cache>` configuration under the `<mpchadwick_pagecachehitrate>` node. If no trackers are specified, hit rate will not be tracked.
1212
- There is a `<track_container_misses>` setting which can be used to track individual container misses in the case of partial page hits.
13-
- A `<metadata_source>` can be configured under the `<full_page_cache>` configuration in the case where Enterprise_PageCache_Model_Processor is not the correct class to provide metadata. This can happen if the `<ee>` request processor is changed, notably with `Elastera_EnterprisePageCache`.
13+
- A `<metadata_source>` can be configured under the `<full_page_cache>` configuration in the case where `Enterprise_PageCache_Model_Processor` is not the correct class to provide metadata. This can happen if the `<ee>` request processor is changed, notably with `Elastera_EnterprisePageCache`.
1414

1515
###Trackers
1616

1717
The following trackers are available...
1818

1919
- **`Mpchadwick_PageCacheHitRate_Model_Tracker_File`** A log file will be used for for tracking hit rate. A new file will be created each day.
20-
- **`Mpchadwick_PageCacheHitRate_Model_Tracker_NewRelic`** Hits and misses will be tracked as [New Relic custom events](https://docs.newrelic.com/docs/insights/new-relic-insights/adding-querying-data/inserting-custom-events-new-relic-apm-agents).
20+
- **`Mpchadwick_PageCacheHitRate_Model_Tracker_NewRelic`** [New Relic custom events](https://docs.newrelic.com/docs/insights/new-relic-insights/adding-querying-data/inserting-custom-events-new-relic-apm-agents) will be used for tracking hit rate.
21+
- **`Mpchadwick_PageCacheHitRate_Model_Tracker_Redis`** Hit rate will be tracked in Redis. The intention is to scrape this data periodically and store it in a tool such as [InfluxDb](https://docs.influxdata.com/influxdb/v0.13/) or [Prometheus](https://prometheus.io/).
2122

2223
You can easily create your own tracker if you'd prefer a different means of tracking. Simply implement the `Mpchadwick_PageCacheHitRate_Model_TrackerInterface` interface and configure your class as the `<tracker>` in an xml file in `/app/etc`.
2324

24-
###Metrics
25+
###Dimensions
2526

2627
In addition to a full hit and a full miss, `Enterprise_PageCache` can also have partial hits. This happens if a cached response is found, but it has containers that need additional processing. The `type` metric is thus tracked as either a `hit`, a `miss`, or a `partial`.
2728

28-
In addition to `type`, the following metrics are tracked for each response `route`, `url` and `ip` are also tracked for each request. For example, you may want to see your cache hit rate for a single route such as `/catalog/product/view` or know your cache hit rate for a single IP address if your are seeing crawling / bot activity creating performance impact on your site.
29+
In addition to `type`, the following dimensions are tracked...
30+
31+
- `route`,
32+
- `url`
33+
- `ip`
34+
- `hostname`
35+
- `customerGroup`
36+
37+
For example, you may want to see your cache hit rate for a single route such as `/catalog/product/view` or know your cache hit rate for a single IP address if your are seeing crawling / bot activity creating performance impact on your site.
2938

3039
Here are some example entries using the `Mpchadwick_PageCacheHitRate_Model_Tracker_File` tracker...
3140

@@ -40,3 +49,34 @@ Container misses will be recorded to a separate file (if enabled). The entries w
4049
```
4150
2016-06-02T03:18:14+00:00 DEBUG (7): {"url":"http:\/\/magento-1_14_1_0.dev\/women\/women-new-arrivals.html","ip":"172.16.9.1","route":"catalog\/category\/view","container":"Enterprise_PageCache_Model_Container_Catalognavigation"}
4251
```
52+
53+
Also note that you can configure multiple trackers. You may want to store data in both New Relic and Redis, for example.
54+
55+
###Cardinality
56+
57+
By default, highly cardinal dimensions are tracked such as IP address and URL. For the `Mpchadwick_PageCacheHitRate_Model_Tracker_File` and `Mpchadwick_PageCacheHitRate_Model_Tracker_NewRelic` trackers this is probably fine. However if you are using `Mpchadwick_PageCacheHitRate_Model_Tracker_Redis` and sending the data to InfluxDb or Prometheus you'll probably want to decrease the cardinality of the data.
58+
59+
You can specify dimensions to strip on a per tracker-basis. E.g...
60+
61+
```xml
62+
<config>
63+
<global>
64+
<full_page_cache>
65+
<mpchadwick_pagecachehitrate>
66+
<trackers>
67+
<redis>
68+
<class>Mpchadwick_PageCacheHitRate_Model_Tracker_Redis</class>
69+
<server>127.0.0.1</server>
70+
<port>6379</port>
71+
<database>1</database>
72+
<strip>
73+
<ip />
74+
<url />
75+
</strip>
76+
</redis>
77+
</trackers>
78+
</mpchadwick_pagecachehitrate>
79+
</full_page_cache>
80+
</global>
81+
</config>
82+
```

app/code/community/Mpchadwick/PageCacheHitRate/Model/Observer.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
class Mpchadwick_PageCacheHitRate_Model_Observer
44
{
5-
const XML_PATH_TRACK_CONTAINER_MISSES = 'global/full_page_cache/mpchadwick_pagecachehitrate/track_container_misses';
6-
75
/**
86
* Handle the controller_front_send_response_before event.
97
*
@@ -35,7 +33,7 @@ public function handleControllerFrontSendResponseBefore(Varien_Event_Observer $o
3533
$tracker->track('RequestResponse', $params, $alias);
3634

3735
// Track any container misses for a partial cache response
38-
$trackContainerMisses = (string)Mage::getConfig()->getNode(self::XML_PATH_TRACK_CONTAINER_MISSES);
36+
$trackContainerMisses = (string)$config->get('track_container_misses');
3937
if ($type === 'partial' && $trackContainerMisses) {
4038
unset($params['type']);
4139
$tracker->trackContainerMisses($params);

app/code/community/Mpchadwick/PageCacheHitRate/Model/Tracker/Abstract.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@
22

33
abstract class Mpchadwick_PageCacheHitRate_Model_Tracker_Abstract
44
{
5-
abstract protected function _track($type, array $args, $alias);
5+
/** @var Mpchadwick_PageCacheHitRate_Model_Config */
6+
protected $config;
7+
8+
/** @var Mpchadwick_PageCacheHitRate_Model_SystemLog */
9+
protected $logger;
10+
11+
public function __construct()
12+
{
13+
$this->config = new Mpchadwick_PageCacheHitRate_Model_Config;
14+
$this->logger = new Mpchadwick_PageCacheHitRate_Model_SystemLog;
15+
}
616

717
public function track($type, array $args, $alias)
818
{
@@ -27,4 +37,6 @@ public function trackContainerMisses($params)
2737
));
2838
}
2939
}
40+
41+
abstract protected function _track($type, array $args, $alias);
3042
}

app/code/community/Mpchadwick/PageCacheHitRate/Model/Tracker/NewRelic.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ class Mpchadwick_PageCacheHitRate_Model_Tracker_NewRelic
77
protected function _track($type, array $args, $alias)
88
{
99
if (!function_exists('newrelic_record_custom_event')) {
10-
Mage::logException(new Exception('You are using the New Relic tracker, but don\'t have the agent set up properly'));
10+
$msg = 'You are using the New Relic tracker, but don\'t have the agent set up properly';
11+
$this->logger->log($msg);
1112
return;
1213
}
1314

app/code/community/Mpchadwick/PageCacheHitRate/Model/Tracker/Redis.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,10 @@ class Mpchadwick_PageCacheHitRate_Model_Tracker_Redis
99
/** @var Credis_Client */
1010
protected $redis;
1111

12-
/** @var Mpchadwick_PageCacheHitRate_Model_Config */
13-
protected $config;
14-
15-
public function __construct()
12+
public function connection()
1613
{
17-
$this->config = new Mpchadwick_PageCacheHitRate_Model_Config;
18-
$this->logger = new Mpchadwick_PageCacheHitRate_Model_SystemLog;
14+
$this->setupConnection();
15+
return $this->redis;
1916
}
2017

2118
protected function _track($type, array $args, $alias)
@@ -36,7 +33,7 @@ protected function _track($type, array $args, $alias)
3633
protected function setupConnection($alias)
3734
{
3835
if (!is_null($this->redis)) {
39-
return;
36+
return true;
4037
}
4138

4239
$prefix = 'trackers/' . $alias . '/';
@@ -57,7 +54,7 @@ protected function setupConnection($alias)
5754
$this->redis->connect();
5855
$this->redis->select($this->config->get($prefix . 'database'));
5956
} catch (Exception $e) {
60-
$this->logger->log('Could not establish Redis connection', Zend_Log::ERR);
57+
$this->logger->log($e->getMessage(), Zend_Log::ERR);
6158
return false;
6259
}
6360

app/code/community/Mpchadwick/PageCacheHitRate/etc/config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<config>
33
<modules>
44
<Mpchadwick_PageCacheHitRate>
5-
<version>0.3.0</version>
5+
<version>0.4.0</version>
66
</Mpchadwick_PageCacheHitRate>
77
</modules>
88
<global>

0 commit comments

Comments
 (0)