Yireo_NewRelic - Version 1.0.4

Version Notes

This module adds NewRelic to Magento

Download this release

Release Info

Developer Magento Core Team
Extension Yireo_NewRelic
Version 1.0.4
Comparing to
See all releases


Version 1.0.4

app/code/community/Varien/Profiler.php ADDED
@@ -0,0 +1,13 @@
1
+ <?php
2
+ /**
3
+ * NewRelic plugin for Magento
4
+ *
5
+ * @package Yireo_NewRelic
6
+ * @author Yireo
7
+ * @copyright Copyright (c) 2011 Yireo (http://www.yireo.com/)
8
+ * @license Open Software License
9
+ */
10
+
11
+ class Varien_Profiler extends Yireo_NewRelic_Model_Profiler
12
+ {
13
+ }
app/code/community/Yireo/NewRelic/Helper/Data.php ADDED
@@ -0,0 +1,35 @@
1
+ <?php
2
+ /**
3
+ * NewRelic plugin for Magento
4
+ *
5
+ * @package Yireo_NewRelic
6
+ * @author Yireo
7
+ * @copyright Copyright (c) 2011 Yireo (http://www.yireo.com/)
8
+ * @license Open Software License
9
+ */
10
+
11
+ class Yireo_NewRelic_Helper_Data extends Mage_Core_Helper_Abstract
12
+ {
13
+ /*
14
+ * Check whether this module can be used
15
+ *
16
+ * @access public
17
+ * @param null
18
+ * @return bool
19
+ */
20
+ public function isEnabled()
21
+ {
22
+ if(!extension_loaded('newrelic')) {
23
+ return false;
24
+ }
25
+
26
+ return true;
27
+ }
28
+
29
+ public function getConfigValue($key = null, $default_value = null)
30
+ {
31
+ $value = Mage::getStoreConfig('newrelic/settings/'.$key);
32
+ if(empty($value)) $value = $default_value;
33
+ return $value;
34
+ }
35
+ }
app/code/community/Yireo/NewRelic/Model/Observer.php ADDED
@@ -0,0 +1,73 @@
1
+ <?php
2
+ /**
3
+ * NewRelic plugin for Magento
4
+ *
5
+ * @category design_default
6
+ * @package Yireo_NewRelic
7
+ * @author Yireo (http://www.yireo.com/)
8
+ * @copyright Copyright (c) 2010 Yireo (http://www.yireo.com/)
9
+ * @license Open Software License
10
+ */
11
+
12
+ class Yireo_NewRelic_Model_Observer
13
+ {
14
+ /*
15
+ * Listen to the event core_block_abstract_to_html_after
16
+ *
17
+ * @access public
18
+ * @parameter Varien_Event_Observer $observer
19
+ * @return $this
20
+ */
21
+ public function coreBlockAbstractToHtmlAfter($observer)
22
+ {
23
+ // Check whether NewRelic can be used
24
+ if(Mage::helper('newrelic')->isEnabled() == false) {
25
+ return $this;
26
+ }
27
+
28
+ // Check whether NewRelic Real User Monitoring is active
29
+ if(Mage::helper('newrelic')->getConfigValue('real_user_monitoring') == false) {
30
+ return $this;
31
+ }
32
+
33
+ // Fetch objects from this event
34
+ $transport = $observer->getEvent()->getTransport();
35
+ $block = $observer->getEvent()->getBlock();
36
+
37
+ // Add JavaScript to the header
38
+ if($block->getNameInLayout() == 'head') {
39
+ $extraHtml = newrelic_get_browser_timing_header();
40
+ $html = $transport->getHtml()."\n".$extraHtml;
41
+ $transport->setHtml($html);
42
+ }
43
+
44
+ // Add JavaScript to the footer
45
+ if($block->getNameInLayout() == 'root') {
46
+ $extraHtml = newrelic_get_browser_timing_footer();
47
+ $html = str_replace('</body>', $extraHtml."\n".'</body>', $transport->getHtml());
48
+ $transport->setHtml($html);
49
+ }
50
+
51
+ return $this;
52
+ }
53
+
54
+ /*
55
+ * Listen to the event model_save_after
56
+ *
57
+ * @access public
58
+ * @parameter Varien_Event_Observer $observer
59
+ * @return $this
60
+ */
61
+ public function modelSaveAfter($observer)
62
+ {
63
+ // Check whether NewRelic can be used
64
+ if(Mage::helper('newrelic')->isEnabled() == false) {
65
+ return $this;
66
+ }
67
+
68
+ $object = $observer->getEvent()->getObject();
69
+ newrelic_custom_metric('Saving '.get_class($object), 1);
70
+
71
+ return $this;
72
+ }
73
+ }
app/code/community/Yireo/NewRelic/Model/Profiler.php ADDED
@@ -0,0 +1,102 @@
1
+ <?php
2
+ /**
3
+ * NewRelic plugin for Magento
4
+ *
5
+ * @category design_default
6
+ * @package Yireo_NewRelic
7
+ * @author Yireo (http://www.yireo.com/)
8
+ * @copyright Copyright (c) 2010 Yireo (http://www.yireo.com/)
9
+ * @license Open Software License
10
+ */
11
+
12
+ class Yireo_NewRelic_Model_Profiler
13
+ {
14
+ public static function init()
15
+ {
16
+ // Only continue when the PHP-extension "newrelic" is found
17
+ if(!extension_loaded('newrelic')) {
18
+ return;
19
+ }
20
+
21
+ // Add generic NewRelic calls that don't have dependancies on Magento
22
+ static $initialized = false;
23
+ if($initialized == false) {
24
+ newrelic_add_custom_tracer('Mage::getModel');
25
+ newrelic_add_custom_tracer('Mage::getSingleton');
26
+ newrelic_add_custom_tracer('Mage::helper');
27
+ newrelic_add_custom_tracer('include');
28
+ newrelic_add_custom_tracer('include_once');
29
+ newrelic_add_custom_tracer('require');
30
+ newrelic_add_custom_tracer('require_once');
31
+ $initialized = true;
32
+ }
33
+
34
+ // Register the Magento request (once it is loaded in Magento) with NewRelic
35
+ static $request_logged = false;
36
+ if($request_logged == false) {
37
+ $request = Mage::app()->getRequest();
38
+ if(!empty($request)) {
39
+ newrelic_name_transaction($request->getRequestUri());
40
+ }
41
+ $request_logged = true;
42
+ }
43
+
44
+ // Register the Magento customers name with NewRelic
45
+ // @todo: Load this through an event
46
+ /*static $customer_logged = false;
47
+ if($customer_logged == false) {
48
+ if(Mage::app()->getStore()->isAdmin() == false) {
49
+ $session = Mage::getModel('customer/session');
50
+ if($session->isLoggedIn()) {
51
+ $customer = $session->getCustomer();
52
+ if($customer->getId() > 0) {
53
+ newrelic_add_custom_parameter('customer', $customer->getName());
54
+ }
55
+ }
56
+ }
57
+ $customer_logged = true;
58
+ }*/
59
+ }
60
+
61
+ public static function enable()
62
+ {
63
+ self::init();
64
+ return;
65
+ }
66
+
67
+ public static function disable()
68
+ {
69
+ self::init();
70
+ return;
71
+ }
72
+
73
+ public static function reset($timerName)
74
+ {
75
+ self::init();
76
+ return;
77
+ }
78
+
79
+ public static function resume($timerName)
80
+ {
81
+ self::init();
82
+ return;
83
+ }
84
+
85
+ public static function start($timerName)
86
+ {
87
+ self::init();
88
+ return;
89
+ }
90
+
91
+ public static function pause($timerName)
92
+ {
93
+ self::init();
94
+ return;
95
+ }
96
+
97
+ public static function stop($timerName)
98
+ {
99
+ self::init();
100
+ return;
101
+ }
102
+ }
app/code/community/Yireo/NewRelic/etc/config.xml ADDED
@@ -0,0 +1,79 @@
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * NewRelic plugin for Magento
5
+ *
6
+ * @category design_default
7
+ * @package Yireo_NewRelic
8
+ * @author Yireo
9
+ * @copyright Copyright (c) 2011 Yireo (http://www.yireo.com/)
10
+ * @license Open Software License
11
+ */
12
+ -->
13
+ <config>
14
+ <modules>
15
+ <Yireo_NewRelic>
16
+ <version>1.0.4</version>
17
+ </Yireo_NewRelic>
18
+ </modules>
19
+
20
+ <global>
21
+ <blocks>
22
+ <newrelic>
23
+ <class>Yireo_NewRelic_Block</class>
24
+ </newrelic>
25
+ </blocks>
26
+ <helpers>
27
+ <newrelic>
28
+ <class>Yireo_NewRelic_Helper</class>
29
+ </newrelic>
30
+ </helpers>
31
+ <models>
32
+ <newrelic>
33
+ <class>Yireo_NewRelic_Model</class>
34
+ </newrelic>
35
+ </models>
36
+ <events>
37
+ <core_block_abstract_to_html_after>
38
+ <observers>
39
+ <newrelic_core_block_abstract_to_html_after>
40
+ <type>singleton</type>
41
+ <class>Yireo_NewRelic_Model_Observer</class>
42
+ <method>coreBlockAbstractToHtmlAfter</method>
43
+ </newrelic_core_block_abstract_to_html_after>
44
+ </observers>
45
+ </core_block_abstract_to_html_after>
46
+ <model_save_after>
47
+ <observers>
48
+ <newrelic_model_save_after>
49
+ <type>singleton</type>
50
+ <class>Yireo_NewRelic_Model_Observer</class>
51
+ <method>modelSaveAfter</method>
52
+ </newrelic_model_save_after>
53
+ </observers>
54
+ </model_save_after>
55
+ </events>
56
+ </global>
57
+
58
+ <adminhtml>
59
+ <acl>
60
+ <resources>
61
+ <admin>
62
+ <children>
63
+ <system>
64
+ <children>
65
+ <config>
66
+ <children>
67
+ <newrelic translate="title" module="newrelic">
68
+ <title>NewRelic</title>
69
+ </newrelic>
70
+ </children>
71
+ </config>
72
+ </children>
73
+ </system>
74
+ </children>
75
+ </admin>
76
+ </resources>
77
+ </acl>
78
+ </adminhtml>
79
+ </config>
app/code/community/Yireo/NewRelic/etc/system.xml ADDED
@@ -0,0 +1,47 @@
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * NewRelic plugin for Magento
5
+ *
6
+ * @category design_default
7
+ * @package Yireo_NewRelic
8
+ * @author Yireo
9
+ * @copyright Copyright (c) 2011 Yireo (http://www.yireo.com/)
10
+ * @license Open Software License
11
+ */
12
+ -->
13
+ <config>
14
+ <sections>
15
+ <newrelic translate="label" module="newrelic">
16
+ <label>NewRelic</label>
17
+ <tab>advanced</tab>
18
+ <frontend_type>text</frontend_type>
19
+ <sort_order>342</sort_order>
20
+ <show_in_default>1</show_in_default>
21
+ <show_in_website>1</show_in_website>
22
+ <show_in_store>1</show_in_store>
23
+ <groups>
24
+ <settings translate="label">
25
+ <label>Settings</label>
26
+ <frontend_type>text</frontend_type>
27
+ <sort_order>1</sort_order>
28
+ <show_in_default>1</show_in_default>
29
+ <show_in_website>1</show_in_website>
30
+ <show_in_store>1</show_in_store>
31
+ <fields>
32
+ <real_user_monitoring translate="label">
33
+ <label>Real User Monitoring</label>
34
+ <comment><![CDATA[Enable when your NewRelic subscription includes this feature]]></comment>
35
+ <frontend_type>select</frontend_type>
36
+ <source_model>adminhtml/system_config_source_yesno</source_model>
37
+ <sort_order>1</sort_order>
38
+ <show_in_default>1</show_in_default>
39
+ <show_in_website>1</show_in_website>
40
+ <show_in_store>1</show_in_store>
41
+ </real_user_monitoring>
42
+ </fields>
43
+ </settings>
44
+ </groups>
45
+ </newrelic>
46
+ </sections>
47
+ </config>
app/etc/modules/Yireo_NewRelic.xml ADDED
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Yireo NewRelic-module for Magento
5
+ *
6
+ * @package Yireo_NewRelic
7
+ * @author Yireo (http://www.yireo.com/)
8
+ * @copyright Copyright (c) 2011 Yireo (http://www.yireo.com/)
9
+ * @license Open Software License
10
+ */
11
+ -->
12
+ <config>
13
+ <modules>
14
+ <Yireo_NewRelic>
15
+ <active>true</active>
16
+ <codePool>community</codePool>
17
+ </Yireo_NewRelic>
18
+ </modules>
19
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Yireo_NewRelic</name>
4
+ <version>1.0.4</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.opensource.org/licenses/osl-3.0.php/">Open Software License</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>This module adds NewRelic to Magento</summary>
10
+ <description>This module adds NewRelic to Magento</description>
11
+ <notes>This module adds NewRelic to Magento</notes>
12
+ <authors><author><name>Yireo</name><user>auto-converted</user><email>info@yireo.com</email></author></authors>
13
+ <date>2011-06-22</date>
14
+ <time>15:38:57</time>
15
+ <contents><target name="magecommunity"><dir name="Varien"><file name="Profiler.php" hash="296d3f7a5a0686ce8db7cda71639e8eb"/></dir><dir name="Yireo"><dir name="NewRelic"><dir name="Model"><file name="Observer.php" hash="22b013daa3c0214dbfbcf8790e93d62d"/><file name="Profiler.php" hash="c4103657241fbd8de67a9144ddf884cb"/></dir><dir name="Helper"><file name="Data.php" hash="7661aee7c080d2af887e934cc9b12f71"/></dir><dir name="etc"><file name="config.xml" hash="a46cd581d34af6a9be5ca9b91aee5161"/><file name="system.xml" hash="2dab0268fd0c5d36b0e7efcc6ffc4cbc"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Yireo_NewRelic.xml" hash="ca797759fe9ecc807f986141989cee17"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies/>
18
+ </package>