CoScale - Version 0.17.1

Version Notes

The CoScale module is still under development. All feedback is welcome.

Download this release

Release Info

Developer CoScale Developer
Extension CoScale
Version 0.17.1
Comparing to
See all releases


Version 0.17.1

Files changed (37) hide show
  1. app/code/community/CoScale/Monitor/Helper/Data.php +86 -0
  2. app/code/community/CoScale/Monitor/Model/Cronjob.php +24 -0
  3. app/code/community/CoScale/Monitor/Model/Event.php +292 -0
  4. app/code/community/CoScale/Monitor/Model/Event/Cache.php +169 -0
  5. app/code/community/CoScale/Monitor/Model/Event/Observer.php +87 -0
  6. app/code/community/CoScale/Monitor/Model/Event/Reindex.php +43 -0
  7. app/code/community/CoScale/Monitor/Model/Event/Store.php +38 -0
  8. app/code/community/CoScale/Monitor/Model/Metric.php +173 -0
  9. app/code/community/CoScale/Monitor/Model/Metric/Abstract.php +116 -0
  10. app/code/community/CoScale/Monitor/Model/Metric/Customer.php +98 -0
  11. app/code/community/CoScale/Monitor/Model/Metric/File.php +88 -0
  12. app/code/community/CoScale/Monitor/Model/Metric/Observer.php +44 -0
  13. app/code/community/CoScale/Monitor/Model/Metric/Order.php +855 -0
  14. app/code/community/CoScale/Monitor/Model/Metric/Page.php +46 -0
  15. app/code/community/CoScale/Monitor/Model/Metric/Product.php +219 -0
  16. app/code/community/CoScale/Monitor/Model/Metric/Rewrite.php +63 -0
  17. app/code/community/CoScale/Monitor/Model/Metric/System.php +39 -0
  18. app/code/community/CoScale/Monitor/Model/Output/Generator.php +47 -0
  19. app/code/community/CoScale/Monitor/Model/Resource/Event.php +49 -0
  20. app/code/community/CoScale/Monitor/Model/Resource/Event/Collection.php +21 -0
  21. app/code/community/CoScale/Monitor/Model/Resource/Metric.php +55 -0
  22. app/code/community/CoScale/Monitor/Model/Resource/Metric/Collection.php +20 -0
  23. app/code/community/CoScale/Monitor/etc/config.xml +292 -0
  24. app/code/community/CoScale/Monitor/etc/system.xml +57 -0
  25. app/code/community/CoScale/Monitor/sql/coscale_monitor_setup/install-0.1.0.php +175 -0
  26. app/code/community/CoScale/Monitor/sql/coscale_monitor_setup/upgrade-0.1.0-0.2.0.php +18 -0
  27. app/code/community/CoScale/Monitor/sql/coscale_monitor_setup/upgrade-0.12.0-0.13.0.php +37 -0
  28. app/code/community/CoScale/Monitor/sql/coscale_monitor_setup/upgrade-0.14.0-0.15.0.php +21 -0
  29. app/code/community/CoScale/Monitor/sql/coscale_monitor_setup/upgrade-0.2.0-0.3.0.php +20 -0
  30. app/code/community/CoScale/Monitor/sql/coscale_monitor_setup/upgrade-0.3.0-0.4.0.php +25 -0
  31. app/code/community/CoScale/Monitor/sql/coscale_monitor_setup/upgrade-0.4.0-0.5.0.php +24 -0
  32. app/design/frontend/base/default/layout/coscale_monitor.xml +12 -0
  33. app/design/frontend/base/default/template/coscale_monitor/rum.phtml +1 -0
  34. app/etc/modules/CoScale_Monitor.xml +9 -0
  35. package.xml +18 -0
  36. shell/coscale.php +45 -0
  37. shell/coscale_reset.php +38 -0
app/code/community/CoScale/Monitor/Helper/Data.php ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * CoScale module helper
5
+ *
6
+ * @package CoScale_Monitor
7
+ * @author Rian Orie <rian.orie@supportdesk.nu>
8
+ * @created 2015-07-03
9
+ * @version 1.0
10
+ */
11
+ class CoScale_Monitor_Helper_Data extends Mage_Core_Helper_Abstract
12
+ {
13
+ protected $debug = false;
14
+ protected $timer = array();
15
+ protected $logs = array();
16
+
17
+ public function isEnabled()
18
+ {
19
+ if (!Mage::getStoreConfig('system/coscale_monitor/enabled')) {
20
+ return false;
21
+ }
22
+
23
+ $resource = Mage::getSingleton('core/resource');
24
+ $connection = $resource->getConnection('core_write');
25
+
26
+ try {
27
+ $this->debugStart('Module checking');
28
+ $tables = Mage::getConfig()->getNode('global/models/coscale_monitor_resource/entities')->asArray();
29
+
30
+ foreach ($tables as $id => $data) {
31
+ $metricTable = $resource->getTableName($data['table']);
32
+ if (! $connection->isTableExists($metricTable)) {
33
+ $this->debugEndError('Module checking', new Exception('Table ' . $metricTable . ' not found!'));
34
+ return false;
35
+ }
36
+ }
37
+ $this->debugEnd('Module checking');
38
+ } catch (Exception $ex) {
39
+ $this->debugEndError('Module checking', $ex);
40
+ return false;
41
+ }
42
+ return true;
43
+ }
44
+
45
+ public function writeDebug($msg)
46
+ {
47
+ if ($this->debug) {
48
+ Mage::log($msg, Zend_Log::DEBUG, 'coscale-collect.log', true);
49
+ }
50
+ }
51
+
52
+ public function debugStart($name)
53
+ {
54
+ $this->writeDebug('Start: ' . $name);
55
+ $this->timer[$name] = microtime(true);
56
+ }
57
+
58
+ public function debugEnd($name)
59
+ {
60
+ $startTime = isset($this->timer[$name]) ? $this->timer[$name]:microtime(true);
61
+ $duration = microtime(true)-$startTime;
62
+
63
+ $this->writeDebug('Completed: ' . $name . ' (' . number_format($duration, 6) . 's)');
64
+ }
65
+
66
+ public function debugEndError($name, $ex)
67
+ {
68
+ $startTime = isset($this->timer[$name]) ? $this->timer[$name]:microtime(true);
69
+ $duration = microtime(true)-$startTime;
70
+ $msg = 'Error: ' . $name . ' (' . number_format($duration, 6) . 's) [' . $ex->getMessage() . ']';
71
+ array_push($this->logs, $msg);
72
+ $this->writeDebug($msg);
73
+ }
74
+
75
+ public function enableDebug()
76
+ {
77
+ $this->debug = true;
78
+ }
79
+
80
+ public function getLogs()
81
+ {
82
+ $tmp_logs = implode(", ", $this->logs);
83
+ $this->logs = array();
84
+ return $tmp_logs;
85
+ }
86
+ }
app/code/community/CoScale/Monitor/Model/Cronjob.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Cronjob director to run daily metric data reset/generation
4
+ *
5
+ * @package CoScale_Monitor
6
+ * @author Vladimir Kerkhoff <v.kerkhoff@genmato.com>
7
+ * @version 1.0
8
+ * @created 2015-08-18
9
+ */
10
+
11
+ class CoScale_Monitor_Model_Cronjob
12
+ {
13
+ /**
14
+ * Daily cronjob to update daily values
15
+ */
16
+
17
+ public function dailyCron()
18
+ {
19
+ // Customer metric data
20
+ Mage::getSingleton('coscale_monitor/metric_customer')->dailyCron();
21
+ Mage::getSingleton('coscale_monitor/metric_product')->dailyCron();
22
+ Mage::getSingleton('coscale_monitor/metric_order')->dailyCron();
23
+ }
24
+ }
app/code/community/CoScale/Monitor/Model/Event.php ADDED
@@ -0,0 +1,292 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * CoScale Event interaction model
5
+ *
6
+ * @package CoScale_Monitor
7
+ * @author Rian Orie <rian.orie@supportdesk.nu>
8
+ * @created 2015-07-03
9
+ * @version 1.0
10
+ *
11
+ * @method $this setId(int $eventId)
12
+ * @method $this setName(string $name)
13
+ * @method $this setDescription(string $description)
14
+ * @method $this setSource(string $source)
15
+ * @method $this setVersion(int $version)
16
+ * @method $this setDuration(int $duration)
17
+ * @method $this setTimestampStart(int $timestamp)
18
+ * @method $this setTimestampEnd(int $timestamp)
19
+ * @method $this setUpdatedAt(string $date)
20
+ * @method int getId()
21
+ * @method string getName()
22
+ * @method string getDescription()
23
+ * @method string getType()
24
+ * @method string getSource()
25
+ * @method int getState()
26
+ * @method int getTimestampStart()
27
+ * @method int getTimestampEnd()
28
+ * @method int getDuration()
29
+ * @method string getUpdatedAt()
30
+ */
31
+ class CoScale_Monitor_Model_Event extends Mage_Core_Model_Abstract
32
+ {
33
+ /**
34
+ * Disabled state for events
35
+ */
36
+ const STATE_DISABLED = -1;
37
+
38
+ /**
39
+ * Inactive state for events
40
+ */
41
+ const STATE_INACTIVE = 0;
42
+
43
+ /**
44
+ * Enabled/active state for events
45
+ */
46
+ const STATE_ENABLED = 1;
47
+
48
+ const GROUP_ADMIN = 'Admin actions';
49
+ const GROUP_CRON = 'Cron Jobs';
50
+
51
+ /**
52
+ * Event type for adding stores
53
+ */
54
+ const TYPE_STORE_ADD = 'STORE_ADD';
55
+
56
+ /**
57
+ * Event type for flushing the page cache
58
+ */
59
+ const TYPE_FLUSH_SYSTEM_CACHE = 'FLUSH_SYSTEM_CACHE';
60
+ const TYPE_FLUSH_ALL_CACHE = 'FLUSH_ALL_CACHE';
61
+ const TYPE_MASS_REFRESH_CACHE = 'MASS_REFRESH_CACHE';
62
+
63
+ /**
64
+ * Event for flushing the asset cache
65
+ */
66
+ const TYPE_FLUSH_ASSET_CACHE = 'FLUSH_ASSET_CACHE';
67
+
68
+ /**
69
+ * Event for flushing the image cache
70
+ */
71
+ const TYPE_FLUSH_IMAGE_CACHE = 'FLUSH_IMAGE_CACHE';
72
+
73
+ /**
74
+ * Event for the reindexing
75
+ */
76
+ const TYPE_REINDEX = 'REINDEX';
77
+
78
+ /**
79
+ * Construct the event model
80
+ */
81
+ protected function _construct()
82
+ {
83
+ $this->_init('coscale_monitor/event');
84
+ }
85
+
86
+ /**
87
+ * Make sure the version is always an integer, even when it's null
88
+ *
89
+ * @return int
90
+ */
91
+ public function getVersion()
92
+ {
93
+ if (is_null($this->getData('version'))) {
94
+ return 0;
95
+ }
96
+
97
+ return $this->getData('version');
98
+ }
99
+
100
+ /**
101
+ * Return the event data as an array, rather than the json string
102
+ *
103
+ * @return array
104
+ */
105
+ public function getEventData()
106
+ {
107
+ return json_decode($this->getData('event_data'), true);
108
+ }
109
+
110
+ /**
111
+ * Set the state for an event
112
+ *
113
+ * @param int $state Set the state to one of the predefined states in the system
114
+ *
115
+ * @return $this
116
+ * @throws Exception
117
+ */
118
+ public function setState($state)
119
+ {
120
+ if (!in_array($state, array(self::STATE_DISABLED, self::STATE_ENABLED, self::STATE_INACTIVE))) {
121
+ throw new Exception('State must be one of the predefined state levels.');
122
+ }
123
+
124
+ return $this->setData('state', $state);
125
+ }
126
+
127
+ /**
128
+ * Set the event type
129
+ *
130
+ * @param string $type Set the type of the event to one of the predefined types
131
+ *
132
+ * @return $this
133
+ *
134
+ * @throws Exception
135
+ */
136
+ public function setType($type)
137
+ {
138
+ if (!in_array($type, $this->getTypes())) {
139
+ throw new Exception('Only predefined types can be used.');
140
+ }
141
+
142
+ return $this->setData('type', $type);
143
+ }
144
+
145
+ /**
146
+ * Store the event data as a json string rather than a raw array
147
+ *
148
+ * @param array $data An array of data to expose to CoScale
149
+ *
150
+ * @return $this
151
+ */
152
+ public function setEventData(array $data)
153
+ {
154
+ return $this->setData('event_data', json_encode($data));
155
+ }
156
+
157
+ /**
158
+ * Shorthand for adding new events
159
+ *
160
+ * @param string $type The event type as predefined in this model
161
+ * @param string $name Short name for the event
162
+ * @param string $description Description of the event
163
+ * @param array $data An array of data to expose to CoScale
164
+ * @param string $source The causer of the event, logged in user, etc
165
+ * @param int $state The state of the event
166
+ *
167
+ * @return $this
168
+ */
169
+ public function addEvent($type, $name, $description, array $data, $source, $state = null)
170
+ {
171
+ $this->setType($type)
172
+ ->setName($name)
173
+ ->setDescription($description)
174
+ ->setEventData($data)
175
+ ->setDuration(0)
176
+ ->setTimestampStart(time())
177
+ ->setSource($source)
178
+ ->setState($state);
179
+
180
+ // By default we're assuming events don't do much and we're simply logging them
181
+ // if an event takes longer, the enabled state needs to be defined in the call
182
+ if (is_null($state)) {
183
+ $this->setState(self::STATE_INACTIVE)
184
+ ->setTimestampEnd(time());
185
+ }
186
+
187
+ try {
188
+ $this->save();
189
+ } catch (Exception $ex) {
190
+ Mage::log($ex->getMessage(), null, 'coscale.log', true);
191
+ }
192
+
193
+ return $this;
194
+ }
195
+
196
+ /**
197
+ * Shorthand to update an event
198
+ *
199
+ * @param string $type The predefined type to load the event by
200
+ * @param int $state The state of the event
201
+ * @param string $source Source of the event, who triggered it
202
+ * @param array $data Event data to store
203
+ *
204
+ * @throws Exception
205
+ */
206
+ public function updateEvent($type, $state, $source = null, array $data = null)
207
+ {
208
+ $this->loadLastByType($type);
209
+ $this->setTimestampEnd(time())
210
+ ->setState($state);
211
+
212
+ if (!is_null($source)) {
213
+ $this->setSource($source);
214
+ }
215
+
216
+ if (!is_null($data)) {
217
+ $this->setEventData($data);
218
+ }
219
+
220
+ try {
221
+ $this->save();
222
+ } catch (Exception $ex) {
223
+ Mage::log($ex->getMessage(), null, 'coscale.log', true);
224
+ }
225
+ }
226
+
227
+ /**
228
+ * Load an event by it's type
229
+ *
230
+ * @param string $type The predefined type to load the event by
231
+ *
232
+ * @return $this
233
+ *
234
+ * @throws Exception
235
+ */
236
+ public function loadLastByType($type)
237
+ {
238
+ if (!in_array($type, $this->getTypes())) {
239
+ throw new Exception('Type should be one of the predefined keys');
240
+ }
241
+
242
+ $this->_getResource()->loadByType($this, $type);
243
+ return $this;
244
+ }
245
+
246
+ /**
247
+ * Type groups for the reporting and grouping of types
248
+ *
249
+ * @return string
250
+ */
251
+ public function getTypeGroup()
252
+ {
253
+ switch ($this->getType()) {
254
+ case self::TYPE_STORE_ADD:
255
+ case self::TYPE_MASS_REFRESH_CACHE:
256
+ case self::TYPE_FLUSH_ASSET_CACHE:
257
+ case self::TYPE_FLUSH_IMAGE_CACHE:
258
+ case self::TYPE_FLUSH_SYSTEM_CACHE:
259
+ case self::TYPE_FLUSH_ALL_CACHE:
260
+ case self::TYPE_REINDEX:
261
+ return self::GROUP_ADMIN;
262
+ }
263
+ }
264
+
265
+ /**
266
+ * Set some defaults before saving an event to the database
267
+ *
268
+ * @return $this
269
+ */
270
+ protected function _beforeSave()
271
+ {
272
+ $date = Mage::getModel('core/date');
273
+
274
+ $this->setUpdatedAt($date->date())
275
+ ->setVersion($this->getVersion() + 1);
276
+
277
+ return $this;
278
+ }
279
+
280
+ /**
281
+ * Retrieve the available types as an array
282
+ *
283
+ * @return array
284
+ */
285
+ protected function getTypes()
286
+ {
287
+ return array(self::TYPE_REINDEX, self::TYPE_STORE_ADD,
288
+ self::TYPE_FLUSH_ASSET_CACHE, self::TYPE_FLUSH_IMAGE_CACHE,
289
+ self::TYPE_MASS_REFRESH_CACHE, self::TYPE_FLUSH_SYSTEM_CACHE,
290
+ self::TYPE_FLUSH_ALL_CACHE);
291
+ }
292
+ }
app/code/community/CoScale/Monitor/Model/Event/Cache.php ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Event observer for reindexing related features
5
+ *
6
+ * @package Coscale_Monitor
7
+ * @author Rian Orie <rian.orie@supportdesk.nu>
8
+ * @created 2015-07-06
9
+ * @version 1.0
10
+ */
11
+ class CoScale_Monitor_Model_Event_Cache
12
+ {
13
+ /**
14
+ * Trigger adding an event at the start of the flush system cache process
15
+ *
16
+ * @param Varien_Event_Observer $event
17
+ */
18
+ public function startFlushSystem(Varien_Event_Observer $event)
19
+ {
20
+ /** @var CoScale_Monitor_Model_Event $coscale */
21
+ $coscale = Mage::getModel('coscale_monitor/event');
22
+ $coscale->addEvent(
23
+ $coscale::TYPE_FLUSH_SYSTEM_CACHE,
24
+ 'Cache',
25
+ 'Flush System Cache!',
26
+ array(),
27
+ Mage::getSingleton('admin/session')->getUser()->getUsername(),
28
+ $coscale::STATE_ENABLED
29
+ );
30
+ }
31
+
32
+ /**
33
+ * Trigger ending an event at the end of the flush system cache process
34
+ *
35
+ * @param Varien_Event_Observer $event
36
+ */
37
+ public function endFlushSystem(Varien_Event_Observer $event)
38
+ {
39
+ /** @var CoScale_Monitor_Model_Event $coscale */
40
+ $coscale = Mage::getModel('coscale_monitor/event');
41
+ $coscale->updateEvent($coscale::TYPE_FLUSH_SYSTEM_CACHE, $coscale::STATE_INACTIVE);
42
+ }
43
+
44
+ /**
45
+ * Trigger adding an event at the start of the flush all cache process
46
+ *
47
+ * @param Varien_Event_Observer $event
48
+ */
49
+ public function startFlushAll(Varien_Event_Observer $event)
50
+ {
51
+ /** @var CoScale_Monitor_Model_Event $coscale */
52
+ $coscale = Mage::getModel('coscale_monitor/event');
53
+ $coscale->addEvent(
54
+ $coscale::TYPE_FLUSH_ALL_CACHE,
55
+ 'Cache',
56
+ 'Flush All Cache!',
57
+ array(),
58
+ Mage::getSingleton('admin/session')->getUser()->getUsername(),
59
+ $coscale::STATE_ENABLED
60
+ );
61
+ }
62
+
63
+ /**
64
+ * Trigger ending an event at the end of the flush all cache process
65
+ *
66
+ * @param Varien_Event_Observer $event
67
+ */
68
+ public function endFlushAll(Varien_Event_Observer $event)
69
+ {
70
+ /** @var CoScale_Monitor_Model_Event $coscale */
71
+ $coscale = Mage::getModel('coscale_monitor/event');
72
+ $coscale->updateEvent($coscale::TYPE_FLUSH_ALL_CACHE, $coscale::STATE_INACTIVE);
73
+ }
74
+
75
+ /**
76
+ * Trigger adding an event at the start of the flush Image cache process
77
+ *
78
+ * @param Varien_Event_Observer $event
79
+ */
80
+ public function startCleanImages(Varien_Event_Observer $event)
81
+ {
82
+ /** @var CoScale_Monitor_Model_Event $coscale */
83
+ $coscale = Mage::getModel('coscale_monitor/event');
84
+ $coscale->addEvent(
85
+ $coscale::TYPE_FLUSH_IMAGE_CACHE,
86
+ 'Cache',
87
+ 'Flush Image Cache!',
88
+ array(),
89
+ Mage::getSingleton('admin/session')->getUser()->getUsername(),
90
+ $coscale::STATE_ENABLED
91
+ );
92
+ }
93
+
94
+ /**
95
+ * Trigger ending an event at the end of the flush Image cache process
96
+ *
97
+ * @param Varien_Event_Observer $event
98
+ */
99
+ public function endCleanImages(Varien_Event_Observer $event)
100
+ {
101
+ /** @var CoScale_Monitor_Model_Event $coscale */
102
+ $coscale = Mage::getModel('coscale_monitor/event');
103
+ $coscale->updateEvent($coscale::TYPE_FLUSH_IMAGE_CACHE, $coscale::STATE_INACTIVE);
104
+ }
105
+
106
+ /**
107
+ * Trigger adding an event at the start of the flush css/js cache process
108
+ *
109
+ * @param Varien_Event_Observer $event
110
+ */
111
+ public function startCleanAssets(Varien_Event_Observer $event)
112
+ {
113
+ /** @var CoScale_Monitor_Model_Event $coscale */
114
+ $coscale = Mage::getModel('coscale_monitor/event');
115
+ $coscale->addEvent(
116
+ $coscale::TYPE_FLUSH_ASSET_CACHE,
117
+ 'Cache',
118
+ 'Flush Asset (CSS/JS) Cache!',
119
+ array(),
120
+ Mage::getSingleton('admin/session')->getUser()->getUsername(),
121
+ $coscale::STATE_ENABLED
122
+ );
123
+ }
124
+
125
+ /**
126
+ * Trigger ending an event at the end of the flush css/js cache process
127
+ *
128
+ * @param Varien_Event_Observer $event
129
+ */
130
+ public function endCleanAssets(Varien_Event_Observer $event)
131
+ {
132
+ /** @var CoScale_Monitor_Model_Event $coscale */
133
+ $coscale = Mage::getModel('coscale_monitor/event');
134
+ $coscale->updateEvent($coscale::TYPE_FLUSH_ASSET_CACHE, $coscale::STATE_INACTIVE);
135
+ }
136
+
137
+ /**
138
+ * Trigger adding an event at the start of the mass refresh cache process
139
+ *
140
+ * @param Varien_Event_Observer $event
141
+ */
142
+ public function startMassRefresh(Varien_Event_Observer $event)
143
+ {
144
+ $types = Mage::app()->getRequest()->getPost('types', array());
145
+
146
+ /** @var CoScale_Monitor_Model_Event $coscale */
147
+ $coscale = Mage::getModel('coscale_monitor/event');
148
+ $coscale->addEvent(
149
+ $coscale::TYPE_MASS_REFRESH_CACHE,
150
+ 'Cache',
151
+ 'Mass Cache Refresh!',
152
+ array('types'=>$types),
153
+ Mage::getSingleton('admin/session')->getUser()->getUsername(),
154
+ $coscale::STATE_ENABLED
155
+ );
156
+ }
157
+
158
+ /**
159
+ * Trigger ending an event at the end of the mass refresh cache process
160
+ *
161
+ * @param Varien_Event_Observer $event
162
+ */
163
+ public function endMassRefresh(Varien_Event_Observer $event)
164
+ {
165
+ /** @var CoScale_Monitor_Model_Event $coscale */
166
+ $coscale = Mage::getModel('coscale_monitor/event');
167
+ $coscale->updateEvent($coscale::TYPE_MASS_REFRESH_CACHE, $coscale::STATE_INACTIVE);
168
+ }
169
+ }
app/code/community/CoScale/Monitor/Model/Event/Observer.php ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class CoScale_Monitor_Model_Event_Observer
4
+ {
5
+ public function generate(Varien_Event_Observer $observer)
6
+ {
7
+ $event = $observer->getEvent();
8
+
9
+ /** @var CoScale_Monitor_Helper_Data $logger */
10
+ $logger = $event->getLogger();
11
+ /** @var CoScale_Monitor_Model_Output_Generator $output */
12
+ $output = $event->getOutput();
13
+
14
+ // Get Events Collection
15
+ try {
16
+ $logger->debugStart('Events Collection');
17
+
18
+ $collection = Mage::getModel('coscale_monitor/event')->getCollection();
19
+ /** @var CoScale_Monitor_Model_Event $event */
20
+ foreach ($collection as $event) {
21
+ $output->addEvent(
22
+ array(
23
+ 'type' => $event->getTypeGroup(),
24
+ 'message' => $event->getDescription(),
25
+ 'data' => array_merge(
26
+ array('originator' => $event->getSource()),
27
+ $event->getEventData()
28
+ ),
29
+ 'start_time' => (int)(time() - $event->getTimestampStart()),
30
+ 'stop_time' => (int)($event->getTimestampEnd() != 0 ? (time() - $event->getTimestampEnd()) : 0),
31
+ )
32
+ );
33
+
34
+ $event->delete();
35
+ if ($event->getState() != $event::STATE_ENABLED) {
36
+ //$event->delete();
37
+ }
38
+ }
39
+ $logger->debugEnd('Events Collection');
40
+ } catch (Exception $ex) {
41
+ $logger->debugEndError('Events Collection', $ex);
42
+ }
43
+
44
+ // Get Cronjob Collection
45
+ try {
46
+ $logger->debugStart('Cronjob Collection');
47
+
48
+ $endDateTime = date('U');
49
+ $collection = Mage::getModel('cron/schedule')->getCollection()
50
+ ->addFieldToFilter('finished_at', array('from' => date('Y-m-d H:i:s', $endDateTime-65)))
51
+ ->setOrder('finished_at', 'DESC');
52
+ /** @var Mage_Cron_Model_Schedule $event */
53
+ foreach ($collection as $cron) {
54
+ $output->addEvent(
55
+ array(
56
+ 'type' => CoScale_Monitor_Model_Event::GROUP_CRON,
57
+ 'message' => $cron->getJobCode(),
58
+ 'status' => $cron->getStatus(),
59
+ 'start_time' => (int)(time() - strtotime($cron->getExecutedAt())),
60
+ 'stop_time' => (int)(time() - strtotime($cron->getFinishedAt())),
61
+ )
62
+ );
63
+ }
64
+ $logger->debugEnd('Cronjob Collection');
65
+ } catch (Exception $ex) {
66
+ $logger->debugEndError('Events Collection', $ex);
67
+ }
68
+
69
+ try {
70
+ $logger->debugStart('Maintenance Flag');
71
+ if (file_exists(Mage::getBaseDir('base') . DS . 'maintenance.flag')) {
72
+ $output->addEvent(
73
+ array(
74
+ 'type' => CoScale_Monitor_Model_Event::GROUP_ADMIN,
75
+ 'message' => 'Maintenance mode enabled',
76
+ 'start_time' => 0,
77
+ 'stop_time' => 0,
78
+ )
79
+ );
80
+ }
81
+ $logger->debugEnd('Maintenance Flag');
82
+ } catch (Exception $ex) {
83
+ $logger->debugEndError('Maintenance Flag', $ex);
84
+ }
85
+
86
+ }
87
+ }
app/code/community/CoScale/Monitor/Model/Event/Reindex.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Event observer for reindexing related features
5
+ *
6
+ * @package Coscale_Monitor
7
+ * @author Rian Orie <rian.orie@supportdesk.nu>
8
+ * @created 2015-07-06
9
+ * @version 1.0
10
+ */
11
+ class CoScale_Monitor_Model_Event_Reindex
12
+ {
13
+ /**
14
+ * Trigger adding an event at the start of the reindexing process
15
+ *
16
+ * @param Varien_Event_Observer $event
17
+ */
18
+ public function startIndex(Varien_Event_Observer $event)
19
+ {
20
+ /** @var CoScale_Monitor_Model_Event $coscale */
21
+ $coscale = Mage::getModel('coscale_monitor/event');
22
+ $coscale->addEvent(
23
+ $coscale::TYPE_REINDEX,
24
+ 'Reindexing',
25
+ 'Reindexing the indexes!',
26
+ array(),
27
+ Mage::getSingleton('admin/session')->getUser()->getUsername(),
28
+ $coscale::STATE_ENABLED
29
+ );
30
+ }
31
+
32
+ /**
33
+ * Trigger ending an event at the end of the reindexing process
34
+ *
35
+ * @param Varien_Event_Observer $event
36
+ */
37
+ public function endIndex(Varien_Event_Observer $event)
38
+ {
39
+ /** @var CoScale_Monitor_Model_Event $coscale */
40
+ $coscale = Mage::getModel('coscale_monitor/event');
41
+ $coscale->updateEvent($coscale::TYPE_REINDEX, $coscale::STATE_INACTIVE);
42
+ }
43
+ }
app/code/community/CoScale/Monitor/Model/Event/Store.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * CoScale Event interaction model
5
+ *
6
+ * @package CoScale_Monitor
7
+ * @author Rian Orie <rian.orie@supportdesk.nu>
8
+ * @created 2015-07-03
9
+ * @version 1.0
10
+ */
11
+ class CoScale_Monitor_Model_Event_Store
12
+ {
13
+ /**
14
+ * Track the adding of a new store
15
+ *
16
+ * @param Varien_Event_Observer $event
17
+ */
18
+ public function addNew(Varien_Event_Observer $event)
19
+ {
20
+ /** @var Mage_Core_Model_Store $store */
21
+ $store = $event->getStore();
22
+
23
+ $event = Mage::getModel('coscale_monitor/event');
24
+ $event->addEvent(
25
+ $event::TYPE_STORE_ADD,
26
+ 'Store added',
27
+ 'A new store was added',
28
+ array(
29
+ 'id' => $store->getId(),
30
+ 'name' => $store->getName(),
31
+ 'code' => $store->getCode(),
32
+ 'website' => $store->getWebsiteId()
33
+ ),
34
+ Mage::getSingleton('admin/session')->getUser()->getUsername()
35
+ );
36
+
37
+ }
38
+ }
app/code/community/CoScale/Monitor/Model/Metric.php ADDED
@@ -0,0 +1,173 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * CoScale metric interaction model
5
+ *
6
+ * @package CoScale_Monitor
7
+ * @author Rian Orie <rian.orie@supportdesk.nu>
8
+ * @created 2015-07-03
9
+ * @version 1.0
10
+ *
11
+ * @method $this setKey(int $metricId)
12
+ * @method $this setStoreId(int $store)
13
+ * @method $this setName(string $name)
14
+ * @method $this setDescription(string $description)
15
+ * @method $this setType(int $type)
16
+ * @method $this setValue(string $value)
17
+ * @method $this setUnit(string $unit)
18
+ * @method $this setTimestamp(int $timestamp)
19
+ * @method $this setUpdatedAt(string $date)
20
+ * @method int getKey()
21
+ * @method int getStoreId()
22
+ * @method int getType()
23
+ * @method string getName()
24
+ * @method string getDescription()
25
+ * @method mixed getValue()
26
+ * @method string getUnit()
27
+ * @method int getTimestamp()
28
+ * @method string getUpdatedAt()
29
+ */
30
+ class CoScale_Monitor_Model_Metric extends Mage_Core_Model_Abstract
31
+ {
32
+ /**
33
+ * Type for server-based metrics
34
+ */
35
+ const TYPE_SERVER = 1;
36
+
37
+ /**
38
+ * Type for application-based metrics
39
+ */
40
+ const TYPE_APPLICATION = 2;
41
+
42
+ const CALC_DIFFERENCE = 1;
43
+ const CALC_INSTANT = 2;
44
+ const CALC_AVERAGE = 3;
45
+
46
+ /**
47
+ * Construct the metric model
48
+ */
49
+ protected function _construct()
50
+ {
51
+ $this->_init('coscale_monitor/metric');
52
+ }
53
+
54
+ /**
55
+ * Shorthand to add or update a metric to the system
56
+ *
57
+ * @param int $key A key as predefined in this model
58
+ * @param int $store The store id
59
+ * @param int $type A predefined type for the metric
60
+ * @param string $name The name of the metric
61
+ * @param string $description A longer description of the metric
62
+ * @param mixed $value The value to set
63
+ * @param string $unit The unit the value is saved in
64
+ * @param int $calctype Calculation Type
65
+ *
66
+ * @throws Exception
67
+ */
68
+ public function updateMetric($key, $store, $type, $name, $description, $value, $unit, $calctype = 0)
69
+ {
70
+ $this->loadByKey($key, $store);
71
+
72
+ $this->setKey($key)
73
+ ->setStoreId($store)
74
+ ->setType($type)
75
+ ->setCalculationType($calctype)
76
+ ->setName($name)
77
+ ->setDescription($description)
78
+ ->setValue($value)
79
+ ->setUnit($unit);
80
+
81
+ try {
82
+ $this->save();
83
+ } catch (Exception $ex) {
84
+ Mage::log($ex->getMessage(), null, 'coscale.log', true);
85
+ }
86
+ }
87
+
88
+ /**
89
+ * Shorthand to add or increment a numerical metric in the system
90
+ *
91
+ * @param int $key A key as predefined in this model
92
+ * @param int $store The store the metric belongs to
93
+ * @param string $type A predefined type for the metric
94
+ * @param string $name The name of the metric
95
+ * @param string $description A longer description of the metric
96
+ * @param mixed $value The value to set
97
+ * @param string $unit The unit the value is saved in
98
+ * @param int $calctype Calculation Type
99
+ */
100
+ public function incrementMetric($key, $store, $type, $name, $description, $value, $unit, $calctype = 0)
101
+ {
102
+ $this->loadByKey($key, $store);
103
+
104
+ $this->updateMetric($key, $store, $type, $name, $description, ($this->getValue() + $value), $unit, $calctype);
105
+ }
106
+
107
+ /**
108
+ * Return the textual version of the metric type
109
+ *
110
+ * @return string
111
+ */
112
+ public function getTypeText()
113
+ {
114
+ switch ($this->getType()) {
115
+ case self::TYPE_SERVER:
116
+ return 'S';
117
+ break;
118
+ case self::TYPE_APPLICATION:
119
+ return 'A';
120
+ break;
121
+
122
+ }
123
+ }
124
+
125
+ /**
126
+ * Load a metric by it's key
127
+ *
128
+ * @param int $key The predefined key to load the metric from
129
+ * @param int $store The store to load the metric for
130
+ *
131
+ * @return $this
132
+ *
133
+ * @throws Exception
134
+ */
135
+ public function loadByKey($key, $store)
136
+ {
137
+ $this->_getResource()->loadByKey($this, $key, $store);
138
+ return $this;
139
+ }
140
+
141
+ public function getCalculationTypeCode()
142
+ {
143
+ switch ($this->getCalculationType()) {
144
+ case self::CALC_INSTANT:
145
+ $code = 'Instant';
146
+ break;
147
+ case self::CALC_AVERAGE:
148
+ $code = 'Average';
149
+ break;
150
+ case self::CALC_DIFFERENCE:
151
+ $code = 'Difference';
152
+ break;
153
+ default:
154
+ $code = false;
155
+ }
156
+ return $code;
157
+ }
158
+
159
+ /**
160
+ * Set some defaults before saving an event to the database
161
+ *
162
+ * @return $this
163
+ */
164
+ protected function _beforeSave()
165
+ {
166
+ $date = Mage::getModel('core/date');
167
+
168
+ $this->setTimestamp($date->timestamp())
169
+ ->setUpdatedAt($date->date());
170
+
171
+ return $this;
172
+ }
173
+ }
app/code/community/CoScale/Monitor/Model/Metric/Abstract.php ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Abstract class for processing metric data
4
+ *
5
+ * @package CoScale_Monitor
6
+ * @author Vladimir Kerkhoff <v.kerkhoff@genmato.com>
7
+ * @version 1.0
8
+ * @created 2015-08-18
9
+ */
10
+ class CoScale_Monitor_Model_Metric_Abstract
11
+ {
12
+ protected $_metric = false;
13
+ protected $_metricData = array();
14
+ protected $_helper = false;
15
+
16
+ protected $_metricType = CoScale_Monitor_Model_Metric::TYPE_APPLICATION;
17
+
18
+ const ACTION_UPDATE = 1;
19
+ const ACTION_INCREMENT=2;
20
+
21
+ public function __construct()
22
+ {
23
+ $this->_metric = Mage::getModel('coscale_monitor/metric');
24
+ $this->_helper = Mage::helper('coscale_monitor');
25
+ $this->_contruct();
26
+ }
27
+
28
+ /**
29
+ * Public contructor
30
+ */
31
+ public function _contruct()
32
+ {
33
+
34
+ }
35
+
36
+ /**
37
+ * Shorthand to add/update or increment a metric to the system
38
+ *
39
+ * @param int $action Specify action
40
+ * @param int $key A key as predefined in this model
41
+ * @param int $store The store id
42
+ * @param int|bool $type A predefined type for the metric
43
+ * @param string|bool $name The name of the metric
44
+ * @param string|bool $descr A longer description of the metric
45
+ * @param mixed $value The value to set
46
+ * @param string|bool $unit The unit the value is saved in
47
+ *
48
+ * @throws Exception
49
+ */
50
+ protected function setMetric($action, $key, $store, $value, $unit = false, $type = false, $name = false, $descr = false)
51
+ {
52
+ if (!$type) {
53
+ $type = $this->_metricType;
54
+ }
55
+
56
+ if (!$name && isset($this->_metricData[$key]['name'])) {
57
+ $name = $this->_metricData[$key]['name'];
58
+ }
59
+
60
+ if (!$descr && isset($this->_metricData[$key]['description'])) {
61
+ $descr = $this->_metricData[$key]['description'];
62
+ }
63
+
64
+ if (!$unit && isset($this->_metricData[$key]['unit'])) {
65
+ $unit = $this->_metricData[$key]['unit'];
66
+ }
67
+
68
+ if (!$name || !$descr || !$unit) {
69
+ throw new Exception('Invalid metric data supplied');
70
+ }
71
+ $calctype = 0;
72
+ if (isset($this->_metricData[$key]['calctype'])) {
73
+ $calctype = $this->_metricData[$key]['calctype'];
74
+ }
75
+
76
+ if ($action == self::ACTION_UPDATE) {
77
+ $this->_metric->updateMetric($key, $store, $type, $name, $descr, $value, $unit, $calctype);
78
+ } else {
79
+ $this->_metric->incrementMetric($key, $store, $type, $name, $descr, $value, $unit, $calctype);
80
+ if (isset($this->_metricData[$key]['combine']) && $this->_metricData[$key]['combine']) {
81
+ $this->_metric->incrementMetric($key, 0, $type, $name, $descr, $value, $unit, $calctype);
82
+ }
83
+ }
84
+ }
85
+
86
+ /**
87
+ * @param $key
88
+ * @param $store
89
+ * @return int
90
+ */
91
+ protected function getMetric($key, $store)
92
+ {
93
+ if (!$data = $this->getMetricData($key, $store)) {
94
+ return 0;
95
+ }
96
+ return $data->getValue();
97
+ }
98
+
99
+ /**
100
+ * @param $key
101
+ * @param $store
102
+ * @return $data|bool
103
+ */
104
+ protected function getMetricData($key, $store)
105
+ {
106
+ /** @var CoScale_Monitor_Model_Metric $data */
107
+ $data = $this->_metric->loadByKey($key, $store);
108
+
109
+ if (!$data->getId()) {
110
+ return false;
111
+ }
112
+ return $data;
113
+ }
114
+
115
+
116
+ }
app/code/community/CoScale/Monitor/Model/Metric/Customer.php ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Observer for the metrics related to customers
5
+ *
6
+ * @package CoScale_Monitor
7
+ * @author Rian Orie <rian.orie@supportdesk.nu>
8
+ * @version 1.0
9
+ * @created 2015-07-03
10
+ */
11
+ class CoScale_Monitor_Model_Metric_Customer extends CoScale_Monitor_Model_Metric_Abstract
12
+ {
13
+ /**
14
+ * Identifier for the total number of customers in the system
15
+ */
16
+ const KEY_CUSTOMER_TOTAL = 1000;
17
+ /**
18
+ * Identifier for the total number of customers in the system
19
+ */
20
+ const KEY_CUSTOMER_TODAY = 1001;
21
+
22
+ /**
23
+ * Public contructor function
24
+ */
25
+ public function _contruct()
26
+ {
27
+ $this->_metricData[self::KEY_CUSTOMER_TOTAL] = array(
28
+ 'name' => 'Customers',
29
+ 'description' => 'The total number of customers in the system',
30
+ 'unit' => 'customers'
31
+ );
32
+ }
33
+
34
+ /**
35
+ * Observe the adding of new customers to the system
36
+ *
37
+ * @param Varien_Event_Observer $observer
38
+ */
39
+ public function addNew(Varien_Event_Observer $observer)
40
+ {
41
+ if (!$this->_helper->isEnabled()) {
42
+ return;
43
+ }
44
+
45
+ /** @var Mage_Customer_Model_Customer $customer */
46
+ $customer = $observer->getEvent()->getCustomer();
47
+
48
+ if ($customer->getOrigData('entity_id') == $customer->getId()) {
49
+ return;
50
+ }
51
+
52
+ $this->setMetric(
53
+ self::ACTION_INCREMENT,
54
+ self::KEY_CUSTOMER_TOTAL,
55
+ $customer->getStore()->getId(),
56
+ 1
57
+ );
58
+ }
59
+
60
+ /**
61
+ * Cronjob to update the total number of customers
62
+ */
63
+ public function dailyCron()
64
+ {
65
+ if (!$this->_helper->isEnabled()) {
66
+ return;
67
+ }
68
+ $this->updateTotalCount();
69
+ }
70
+
71
+ /**
72
+ * Daily update full numbers of customers
73
+ */
74
+ public function updateTotalCount()
75
+ {
76
+ $collection = Mage::getResourceModel('customer/customer_collection');
77
+ if (!is_object($collection)) {
78
+ return;
79
+ }
80
+ $collection->getSelect()
81
+ ->reset('columns')
82
+ ->columns(array('website_id' => 'e.website_id',
83
+ 'customer_count' => 'COUNT(*)'))
84
+ ->group('e.website_id');
85
+
86
+ foreach ($collection as $customer) {
87
+ $storeIds = Mage::app()->getWebsite($customer->getWebsiteId())->getStoreIds();
88
+ foreach ($storeIds as $storeId) {
89
+ $this->setMetric(
90
+ self::ACTION_UPDATE,
91
+ self::KEY_CUSTOMER_TOTAL,
92
+ $storeId,
93
+ $customer->getCustomerCount()
94
+ );
95
+ }
96
+ }
97
+ }
98
+ }
app/code/community/CoScale/Monitor/Model/Metric/File.php ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Metrics related to files
4
+ *
5
+ * @package CoScale_Monitor
6
+ * @author Vladimir Kerkhoff <v.kerkhoff@genmato.com>
7
+ * @version 1.0
8
+ * @created 2015-08-18
9
+ */
10
+ class CoScale_Monitor_Model_Metric_File extends CoScale_Monitor_Model_Metric_Abstract
11
+ {
12
+ public function generate(Varien_Event_Observer $observer)
13
+ {
14
+ $event = $observer->getEvent();
15
+
16
+ /** @var CoScale_Monitor_Helper_Data $logger */
17
+ $logger = $event->getLogger();
18
+ /** @var CoScale_Monitor_Model_Output_Generator $output */
19
+ $output = $event->getOutput();
20
+
21
+ // Get Error reports
22
+ try {
23
+ $logger->debugStart('Error Reports');
24
+
25
+ $output->addMetric($this->getErrorReports());
26
+
27
+ $logger->debugEnd('Error Reports');
28
+ } catch (Exception $ex) {
29
+ $logger->debugEndError('Error Reports', $ex);
30
+ }
31
+
32
+ // Get Logfiles (name and size)
33
+ try {
34
+ $logger->debugStart('Logfiles');
35
+
36
+ foreach ($this->getLogFiles() as $data) {
37
+ $output->addMetric($data);
38
+ }
39
+ $logger->debugEnd('Logfiles');
40
+ } catch (Exception $ex) {
41
+ $logger->debugEndError('Logfiles', $ex);
42
+ }
43
+ }
44
+
45
+ /**
46
+ * Get amount of reports in var/report
47
+ * @return array
48
+ */
49
+ public function getErrorReports()
50
+ {
51
+ $dir = Mage::getBaseDir('var') . DS . 'report';
52
+
53
+ $contents = scandir($dir);
54
+
55
+ return array(
56
+ 'name' => 'Files in var/report/',
57
+ 'unit' => 'files',
58
+ 'value' => (count($contents)-2),
59
+ 'store_id' => 0,
60
+ 'type' => 'S'
61
+ );
62
+ }
63
+
64
+ /**
65
+ * Get details of logfiles in var/log
66
+ * @return array
67
+ */
68
+ public function getLogFiles()
69
+ {
70
+ $dir = Mage::getBaseDir('var') . DS . 'log';
71
+
72
+ $contents = scandir($dir);
73
+ $output = array();
74
+ foreach ($contents as $logfile) {
75
+ if ($logfile == '.' || $logfile=='..') {
76
+ continue;
77
+ }
78
+ $output[] = array(
79
+ 'name' => 'Logfile var/log/' . $logfile,
80
+ 'unit' => 'bytes',
81
+ 'value' => filesize($dir . DS . $logfile),
82
+ 'store_id' => 0,
83
+ 'type' => 'S'
84
+ );
85
+ }
86
+ return $output;
87
+ }
88
+ }
app/code/community/CoScale/Monitor/Model/Metric/Observer.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class CoScale_Monitor_Model_Metric_Observer
4
+ {
5
+ public function generate(Varien_Event_Observer $observer)
6
+ {
7
+ $event = $observer->getEvent();
8
+
9
+ /** @var CoScale_Monitor_Helper_Data $logger */
10
+ $logger = $event->getLogger();
11
+ /** @var CoScale_Monitor_Model_Output_Generator $output */
12
+ $output = $event->getOutput();
13
+
14
+ // Get Metrics Collection
15
+ try {
16
+ $logger->debugStart('Metrics Collection');
17
+
18
+ $metricOrderDelete = Mage::getSingleton('coscale_monitor/metric_order');
19
+ $collection = Mage::getModel('coscale_monitor/metric')->getCollection();
20
+ /** @var CoScale_Monitor_Model_Metric $metric */
21
+ foreach ($collection as $metric) {
22
+ $data = array(
23
+ 'name' => $metric->getName(),
24
+ 'unit' => $metric->getUnit(),
25
+ 'value' => (float)$metric->getValue(),
26
+ 'store_id' => (int)$metric->getStoreId(),
27
+ 'type' => $metric->getTypeText()
28
+ );
29
+ if ($code = $metric->getCalculationTypeCode()) {
30
+ $data['calctype'] = $code;
31
+ }
32
+ $output->addMetric($data);
33
+
34
+ // Check if metric need to be reset after collection
35
+ if ($metricOrderDelete->resetOnCollect($metric->getKey())) {
36
+ $metric->setValue(0);
37
+ }
38
+ }
39
+ $logger->debugEnd('Metrics Collection');
40
+ } catch (Exception $ex) {
41
+ $logger->debugEndError('Metrics Collection', $ex);
42
+ }
43
+ }
44
+ }
app/code/community/CoScale/Monitor/Model/Metric/Order.php ADDED
@@ -0,0 +1,855 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Observer for the metrics related to orders
5
+ *
6
+ * @package CoScale_Monitor
7
+ * @author Rian Orie <rian.orie@supportdesk.nu>
8
+ * @version 1.0
9
+ * @created 2015-07-07
10
+ */
11
+ class CoScale_Monitor_Model_Metric_Order extends CoScale_Monitor_Model_Metric_Abstract
12
+ {
13
+
14
+ protected $statusPendingPickPack = false;
15
+ protected $statusPickPack = false;
16
+ protected $statusCompletedPickPack = false;
17
+
18
+ protected $stateNewKey = '';
19
+ protected $stateProcessingKey = '';
20
+ protected $stateCompletedKey = '';
21
+ protected $stateCanceledKey = '';
22
+ protected $statusPendingPickPackKey = '';
23
+ protected $statusPickPackKey = '';
24
+ protected $statusCompletedPickPackKey = '';
25
+
26
+ /**
27
+ * Identifier for total orders
28
+ */
29
+ const KEY_ORDER_TOTAL = 2000;
30
+ const KEY_ORDER_TOTAL_TODAY = 2001;
31
+ const KEY_ORDER_TOTAL_NEW = 2002;
32
+
33
+ /**
34
+ * Identifier for order amount average and total
35
+ */
36
+ const KEY_ORDER_AMOUNT_AVERAGE = 2010;
37
+ const KEY_ORDER_SIZE_TOTAL = 2011;
38
+ const KEY_ORDER_AMOUNT_AVERAGE_NEW = 2012;
39
+ const KEY_ORDER_SIZE_TOTAL_NEW = 2013;
40
+
41
+ /**
42
+ * Identifier for order size average and total
43
+ */
44
+ const KEY_ORDER_SIZE_AVERAGE = 2020;
45
+ const KEY_ORDER_AMOUNT_TOTAL = 2021;
46
+ const KEY_ORDER_SIZE_AVERAGE_NEW = 2022;
47
+ const KEY_ORDER_AMOUNT_TOTAL_NEW = 2023;
48
+
49
+ /**
50
+ * Identifier for order state processing/completed
51
+ */
52
+ const KEY_ORDER_STATE_NEW = 2030;
53
+ const KEY_ORDER_STATE_PROCESSING = 2031;
54
+ const KEY_ORDER_STATE_COMPLETED = 2032;
55
+ const KEY_ORDER_STATE_CANCELED = 2033;
56
+
57
+ /**
58
+ * Identifier for pick order and time calculation
59
+ */
60
+ const KEY_ORDER_STATE_PENDING_PICKPACK = 2040;
61
+ const KEY_ORDER_STATE_CURRENT_PICKPACK = 2041;
62
+ const KEY_ORDER_STATE_COMPLETED_PICKPACK = 2042;
63
+ const KEY_START_PICKPACK = 2043;
64
+ const KEY_PICKED_QTY = 2044;
65
+ const KEY_PICKED_TIME = 2045;
66
+ const KEY_AVGTIME_PICKPACK = 2046;
67
+ const KEY_TIME_PENDING_PICKPACK = 2047;
68
+ const KEY_TIME_CURRENT_PICKPACK = 2048;
69
+
70
+ /**
71
+ * Identifier for abandoned carts
72
+ */
73
+ const KEY_ABANDONED_CARTS = 2060;
74
+ const KEY_ABANDONED_CARTS_VALUE_TOTAL = 2061;
75
+
76
+ /**
77
+ * Public contructor function
78
+ */
79
+ public function _contruct()
80
+ {
81
+ $this->_metricData[self::KEY_ORDER_SIZE_TOTAL_NEW] = array(
82
+ 'name' => 'New Order size total',
83
+ 'description' => 'The total size of orders since last collect for this store',
84
+ 'unit' => 'items'
85
+ );
86
+
87
+ $this->_metricData[self::KEY_ORDER_SIZE_AVERAGE_NEW] = array(
88
+ 'name' => 'Order size average',
89
+ 'description' => 'The average size of orders since last collect for this store',
90
+ 'unit' => 'items'
91
+ );
92
+
93
+ $this->_metricData[self::KEY_ORDER_AMOUNT_TOTAL_NEW] = array(
94
+ 'name' => 'New Order amount total',
95
+ 'description' => 'The total amount of orders since last collect for this store',
96
+ 'unit' => 'Amount'
97
+ );
98
+
99
+ $this->_metricData[self::KEY_ORDER_AMOUNT_AVERAGE_NEW] = array(
100
+ 'name' => 'Order amount average',
101
+ 'description' => 'The average amount of orders since last collect for this store',
102
+ 'unit' => 'Amount'
103
+ );
104
+
105
+ $this->_metricData[self::KEY_ORDER_TOTAL_NEW] = array(
106
+ 'name' => 'Total New Orders',
107
+ 'description' => 'The total number of orders since last collect for this store',
108
+ 'unit' => 'orders'
109
+ );
110
+
111
+ $this->_metricData[self::KEY_ORDER_SIZE_TOTAL] = array(
112
+ 'name' => 'Order size total',
113
+ 'description' => 'The total size of all order in the system for this store',
114
+ 'unit' => 'items'
115
+ );
116
+
117
+ $this->_metricData[self::KEY_ORDER_SIZE_AVERAGE] = array(
118
+ 'name' => 'Order size total average',
119
+ 'description' => 'The average size of an order in the system for this store',
120
+ 'unit' => 'items'
121
+ );
122
+
123
+ $this->_metricData[self::KEY_ORDER_AMOUNT_TOTAL] = array(
124
+ 'name' => 'Order amount total',
125
+ 'description' => 'The total amount of an order in the system for this store',
126
+ 'unit' => 'Amount'
127
+ );
128
+
129
+ $this->_metricData[self::KEY_ORDER_AMOUNT_AVERAGE] = array(
130
+ 'name' => 'Order amount total average',
131
+ 'description' => 'The average amount of an order in the system for this store',
132
+ 'unit' => 'Amount'
133
+ );
134
+
135
+ $this->_metricData[self::KEY_ORDER_TOTAL] = array(
136
+ 'name' => 'Orders',
137
+ 'description' => 'The total number of orders in the system for this store',
138
+ 'unit' => 'orders'
139
+ );
140
+
141
+ $this->_metricData[self::KEY_ORDER_STATE_NEW] = array(
142
+ 'name' => 'Orders new',
143
+ 'description' => 'The total number of orders in new state',
144
+ 'unit' => 'orders'
145
+ );
146
+
147
+ $this->_metricData[self::KEY_ORDER_STATE_PROCESSING] = array(
148
+ 'name' => 'Orders processing',
149
+ 'description' => 'The total number of orders in processing state',
150
+ 'unit' => 'orders'
151
+ );
152
+
153
+ $this->_metricData[self::KEY_ORDER_STATE_COMPLETED] = array(
154
+ 'name' => 'Orders completed',
155
+ 'description' => 'The total number of orders in completed state',
156
+ 'unit' => 'orders'
157
+ );
158
+
159
+ $this->_metricData[self::KEY_ORDER_STATE_CANCELED] = array(
160
+ 'name' => 'Orders canceled',
161
+ 'description' => 'The total number of orders in canceled state',
162
+ 'unit' => 'orders'
163
+ );
164
+
165
+ $this->_metricData[self::KEY_ORDER_STATE_PENDING_PICKPACK] = array(
166
+ 'name' => 'Orders pending pick/pack',
167
+ 'description' => 'The total number of orders in waiting for pick/pack state',
168
+ 'unit' => 'orders',
169
+ 'calctype' => CoScale_Monitor_Model_Metric::CALC_INSTANT,
170
+ 'combine' => true,
171
+ );
172
+
173
+ $this->_metricData[self::KEY_ORDER_STATE_CURRENT_PICKPACK] = array(
174
+ 'name' => 'Orders pick/pack',
175
+ 'description' => 'The total number of orders in pick/pack state',
176
+ 'unit' => 'orders',
177
+ 'calctype' => CoScale_Monitor_Model_Metric::CALC_INSTANT,
178
+ 'combine' => true,
179
+ );
180
+
181
+ $this->_metricData[self::KEY_ORDER_STATE_COMPLETED_PICKPACK] = array(
182
+ 'name' => 'Orders completed pick/pack',
183
+ 'description' => 'The total number of orders in completed pick/pack state',
184
+ 'unit' => 'orders',
185
+ 'calctype' => CoScale_Monitor_Model_Metric::CALC_INSTANT,
186
+ 'combine' => true,
187
+ );
188
+
189
+ $this->_metricData[self::KEY_PICKED_QTY] = array(
190
+ 'name' => 'Picked qty',
191
+ 'description' => 'The qty of orders picked',
192
+ 'unit' => 'qty',
193
+ 'calctype' => CoScale_Monitor_Model_Metric::CALC_INSTANT,
194
+ 'combine' => true,
195
+ );
196
+
197
+ $this->_metricData[self::KEY_PICKED_TIME] = array(
198
+ 'name' => 'Picked time',
199
+ 'description' => 'Total time to pick/pack',
200
+ 'unit' => 'seconds',
201
+ 'calctype' => CoScale_Monitor_Model_Metric::CALC_INSTANT,
202
+ 'combine' => true,
203
+ );
204
+
205
+ $this->_metricData[self::KEY_AVGTIME_PICKPACK] = array(
206
+ 'name' => 'Avg time pick/pack',
207
+ 'description' => 'Avg time to pick/pack an order',
208
+ 'unit' => 'seconds',
209
+ 'calctype' => CoScale_Monitor_Model_Metric::CALC_INSTANT,
210
+ 'combine' => true,
211
+ );
212
+
213
+ $this->_metricData[self::KEY_TIME_PENDING_PICKPACK] = array(
214
+ 'name' => 'Time pending pick/pack',
215
+ 'description' => 'The total time needed to pick/pack new orders',
216
+ 'unit' => 'seconds',
217
+ 'calctype' => CoScale_Monitor_Model_Metric::CALC_INSTANT,
218
+ 'combine' => true,
219
+ );
220
+
221
+ $this->_metricData[self::KEY_TIME_CURRENT_PICKPACK] = array(
222
+ 'name' => 'Time current pick/pack',
223
+ 'description' => 'The total time needed to pick/pack current orders in pick/pack state',
224
+ 'unit' => 'seconds',
225
+ 'calctype' => CoScale_Monitor_Model_Metric::CALC_INSTANT,
226
+ 'combine' => true,
227
+ );
228
+
229
+ $this->_metricData[self::KEY_ABANDONED_CARTS] = array(
230
+ 'name' => 'Abandonned carts',
231
+ 'description' => 'Abandonned carts',
232
+ 'unit' => 'orders',
233
+ );
234
+
235
+ $this->_metricData[self::KEY_ABANDONED_CARTS_VALUE_TOTAL] = array(
236
+ 'name' => 'Total value of abandoned carts',
237
+ 'description' => 'Total value of abandoned carts',
238
+ 'unit' => 'Amount',
239
+ );
240
+
241
+ $this->statusPendingPickPack = Mage::getStoreConfig('system/coscale_monitor/status_pickpack_pending');
242
+ $this->statusPickPack = Mage::getStoreConfig('system/coscale_monitor/status_pickpack');
243
+ $this->statusCompletedPickPack = Mage::getStoreConfig('system/coscale_monitor/status_pickpack_completed');
244
+
245
+ $this->stateNewKey = Mage::getStoreConfig('system/coscale_monitor/state_new_key');
246
+ $this->stateProcessingKey = Mage::getStoreConfig('system/coscale_monitor/state_processing_key');
247
+ $this->stateCompletedKey = Mage::getStoreConfig('system/coscale_monitor/state_completed_key');
248
+ $this->stateCanceledKey = Mage::getStoreConfig('system/coscale_monitor/state_canceled_key');
249
+ $this->statusPendingPickPackKey = Mage::getStoreConfig('system/coscale_monitor/status_pickpack_pending_key');
250
+ $this->statusPickPackKey = Mage::getStoreConfig('system/coscale_monitor/status_pickpack_key');
251
+ $this->statusCompletedPickPackKey = Mage::getStoreConfig('system/coscale_monitor/status_pickpack_completed_key');
252
+ }
253
+
254
+ public function resetOnCollect($key)
255
+ {
256
+ $resetKeys = array(
257
+ self::KEY_ORDER_TOTAL_NEW,
258
+ self::KEY_ORDER_AMOUNT_AVERAGE_NEW,
259
+ self::KEY_ORDER_SIZE_TOTAL_NEW,
260
+ self::KEY_ORDER_SIZE_AVERAGE_NEW,
261
+ self::KEY_ORDER_AMOUNT_TOTAL_NEW,
262
+ );
263
+
264
+ if (in_array($key, $resetKeys)) {
265
+ return true;
266
+ }
267
+ return false;
268
+ }
269
+
270
+ /**
271
+ * Initialize metrics in case they are not already set
272
+ *
273
+ * @param $storeId
274
+ */
275
+ public function initDefaultMetrics($storeId)
276
+ {
277
+ $initKeys = array(
278
+ self::KEY_ORDER_TOTAL_NEW,
279
+ self::KEY_ORDER_AMOUNT_AVERAGE_NEW,
280
+ self::KEY_ORDER_SIZE_TOTAL_NEW,
281
+ self::KEY_ORDER_SIZE_AVERAGE_NEW,
282
+ self::KEY_ORDER_AMOUNT_TOTAL_NEW,
283
+ self::KEY_ORDER_SIZE_AVERAGE,
284
+ self::KEY_PICKED_QTY,
285
+ self::KEY_PICKED_TIME,
286
+ self::KEY_AVGTIME_PICKPACK,
287
+ self::KEY_TIME_PENDING_PICKPACK,
288
+ self::KEY_TIME_CURRENT_PICKPACK,
289
+ self::KEY_ABANDONED_CARTS,
290
+ self::KEY_ABANDONED_CARTS_VALUE_TOTAL,
291
+ );
292
+
293
+ $amountUnit = Mage::getStoreConfig('currency/options/base', $storeId);
294
+
295
+ foreach ($initKeys as $key)
296
+ {
297
+ $metricData = $this->getMetric($key, $storeId);
298
+
299
+ // 'Amount' unit of a metric should always be replaced by the store currency
300
+ $unit = ($this->_metricData[$key]['unit'] == 'Amount' ? $amountUnit : $this->_metricData[$key]['unit']);
301
+ if (empty($metricData)) {
302
+ $this->setMetric(
303
+ self::ACTION_UPDATE,
304
+ $key,
305
+ $storeId,
306
+ 0,
307
+ $unit
308
+ );
309
+ }
310
+ }
311
+ }
312
+
313
+ /**
314
+ * Observe the adding of new orders to the system
315
+ *
316
+ * @param Varien_Event_Observer $observer
317
+ */
318
+ public function salesOrderPlaceAfter(Varien_Event_Observer $observer)
319
+ {
320
+ if (!$this->_helper->isEnabled()) {
321
+ return;
322
+ }
323
+
324
+ /** @var Mage_Sales_Model_Order $order */
325
+ $order = $observer->getEvent()->getOrder();
326
+ $amountUnit = Mage::getStoreConfig('currency/options/base', $order->getStoreId());
327
+
328
+ $this->setMetric(
329
+ self::ACTION_INCREMENT,
330
+ self::KEY_ORDER_SIZE_TOTAL,
331
+ $order->getStoreId(),
332
+ $order->getTotalItemCount()
333
+ );
334
+
335
+ $this->setMetric(
336
+ self::ACTION_INCREMENT,
337
+ self::KEY_ORDER_AMOUNT_TOTAL,
338
+ $order->getStoreId(),
339
+ $order->getBaseGrandTotal(),
340
+ $amountUnit
341
+ );
342
+
343
+ $this->setMetric(
344
+ self::ACTION_INCREMENT,
345
+ self::KEY_ORDER_TOTAL,
346
+ $order->getStoreId(),
347
+ 1
348
+ );
349
+
350
+ $this->setMetric(
351
+ self::ACTION_INCREMENT,
352
+ self::KEY_ORDER_SIZE_TOTAL_NEW,
353
+ $order->getStoreId(),
354
+ $order->getTotalItemCount()
355
+ );
356
+
357
+ $this->setMetric(
358
+ self::ACTION_INCREMENT,
359
+ self::KEY_ORDER_AMOUNT_TOTAL_NEW,
360
+ $order->getStoreId(),
361
+ $order->getBaseGrandTotal(),
362
+ $amountUnit
363
+ );
364
+
365
+ $this->setMetric(
366
+ self::ACTION_INCREMENT,
367
+ self::KEY_ORDER_TOTAL_NEW,
368
+ $order->getStoreId(),
369
+ 1
370
+ );
371
+
372
+ $this->updateAvgOrderValues($order->getStoreId());
373
+ }
374
+
375
+ /**
376
+ * Save order status changes on order save
377
+ *
378
+ * @param Varien_Event_Observer $observer
379
+ */
380
+ public function salesOrderSaveAfter(Varien_Event_Observer $observer)
381
+ {
382
+ $keys = array();
383
+ if (!$this->_helper->isEnabled()) {
384
+ return;
385
+ }
386
+
387
+ /** @var Mage_Sales_Model_Order $order */
388
+ $order = $observer->getEvent()->getOrder();
389
+
390
+ // Update state/status statistics (only if changed)
391
+ if ($order->getState() != $order->getOrigData('state')) {
392
+ // Decrease qty for previous state
393
+ switch ($order->getOrigData('state')) {
394
+ case Mage_Sales_Model_Order::STATE_NEW:
395
+ $keys[self::KEY_ORDER_STATE_NEW] = -1;
396
+ break;
397
+ case Mage_Sales_Model_Order::STATE_PROCESSING:
398
+ $keys[self::KEY_ORDER_STATE_PROCESSING] = -1;
399
+ break;
400
+ }
401
+ // Increase qty for current state
402
+ switch ($order->getData('state')) {
403
+ case Mage_Sales_Model_Order::STATE_NEW:
404
+ $keys[self::KEY_ORDER_STATE_NEW] = 1;
405
+ break;
406
+ case Mage_Sales_Model_Order::STATE_PROCESSING:
407
+ $keys[self::KEY_ORDER_STATE_PROCESSING] = 1;
408
+ break;
409
+ case Mage_Sales_Model_Order::STATE_COMPLETE:
410
+ $keys[self::KEY_ORDER_STATE_COMPLETED] = 1;
411
+ break;
412
+ case Mage_Sales_Model_Order::STATE_CANCELED:
413
+ $keys[self::KEY_ORDER_STATE_CANCELED] = 1;
414
+ break;
415
+ }
416
+ }
417
+
418
+ if ($order->getStatus() != $order->getOrigData('status')) {
419
+ // Decrease qty for previous state
420
+ switch ($order->getOrigData('status')) {
421
+ case $this->statusPendingPickPack:
422
+ $keys[self::KEY_ORDER_STATE_PENDING_PICKPACK] = -1;
423
+ break;
424
+ case $this->statusPickPack:
425
+ $keys[self::KEY_ORDER_STATE_CURRENT_PICKPACK] = -1;
426
+ break;
427
+ case $this->statusCompletedPickPack:
428
+ $keys[self::KEY_ORDER_STATE_COMPLETED_PICKPACK] = -1;
429
+ break;
430
+ }
431
+ // Increase qty for current state
432
+ switch ($order->getData('status')) {
433
+ case $this->statusPendingPickPack:
434
+ $keys[self::KEY_ORDER_STATE_PENDING_PICKPACK] = 1;
435
+ break;
436
+ case $this->statusPickPack:
437
+ $keys[self::KEY_ORDER_STATE_CURRENT_PICKPACK] = 1;
438
+ break;
439
+ case $this->statusCompletedPickPack:
440
+ $keys[self::KEY_ORDER_STATE_COMPLETED_PICKPACK] = 1;
441
+ break;
442
+ }
443
+ }
444
+ if (count($keys)>0) {
445
+ // Check if order picked data decreases
446
+ if (isset($keys[self::KEY_ORDER_STATE_CURRENT_PICKPACK]) &&
447
+ $keys[self::KEY_ORDER_STATE_CURRENT_PICKPACK]<0) {
448
+ // Get difference between last timestamp and now (time used for orderpicking)
449
+ $timeUsed = 1;
450
+ if ($metricData = $this->getMetricData(self::KEY_PICKED_TIME, $order->getStoreId())) {
451
+ $currentDate = date('U', Mage::getModel('core/date')->timestamp(time()));
452
+ $lastDate = date('U', strtotime($metricData->getUpdatedAt()));
453
+ $timeUsed = $currentDate - $lastDate;
454
+ }
455
+ $keys[self::KEY_PICKED_TIME] = $timeUsed;
456
+ $keys[self::KEY_PICKED_QTY] = 1;
457
+ }
458
+
459
+ foreach ($keys as $key => $qty) {
460
+ if ($qty <> 0) {
461
+ $this->setMetric(
462
+ self::ACTION_INCREMENT,
463
+ $key,
464
+ $order->getStoreId(),
465
+ $qty
466
+ );
467
+ }
468
+
469
+ }
470
+ $this->updateAvgPickValues($order->getStoreId());
471
+ }
472
+
473
+ }
474
+
475
+ /**
476
+ * Update pick/pack average values
477
+ *
478
+ * @param $storeId
479
+ */
480
+ public function updateAvgPickValues($storeId)
481
+ {
482
+ $pickTime = $this->getMetric(self::KEY_PICKED_TIME, $storeId);
483
+ $pickQty = $this->getMetric(self::KEY_PICKED_QTY, $storeId);
484
+
485
+ // Update avg pick time
486
+ if ($pickQty>0) {
487
+ $avgPickTime = floor($pickTime/$pickQty);
488
+ $this->setMetric(
489
+ self::ACTION_UPDATE,
490
+ self::KEY_AVGTIME_PICKPACK,
491
+ $storeId,
492
+ $avgPickTime,
493
+ 'seconds'
494
+ );
495
+
496
+ $updateAvgKeys = array(
497
+ self::KEY_ORDER_STATE_PENDING_PICKPACK=>self::KEY_TIME_PENDING_PICKPACK,
498
+ self::KEY_ORDER_STATE_CURRENT_PICKPACK=>self::KEY_TIME_CURRENT_PICKPACK
499
+ );
500
+ // Update avg values for keys
501
+ foreach ($updateAvgKeys as $from => $to) {
502
+ $qty = $this->getMetric($from, $storeId);
503
+
504
+ $this->setMetric(
505
+ self::ACTION_UPDATE,
506
+ $to,
507
+ $storeId,
508
+ ($qty*$avgPickTime),
509
+ 'qty'
510
+ );
511
+ }
512
+ }
513
+ }
514
+
515
+ /**
516
+ * Update Avarage values for order details
517
+ *
518
+ * @param $storeId
519
+ */
520
+ public function updateAvgOrderValues($storeId)
521
+ {
522
+ $amountUnit = Mage::getStoreConfig('currency/options/base', $storeId);
523
+
524
+ $orderTotal = $this->getMetric(self::KEY_ORDER_TOTAL, $storeId);
525
+ $orderItems = $this->getMetric(self::KEY_ORDER_SIZE_TOTAL, $storeId);
526
+ $orderAmount = $this->getMetric(self::KEY_ORDER_AMOUNT_TOTAL, $storeId);
527
+
528
+ $newOrderTotal = $this->getMetric(self::KEY_ORDER_TOTAL_NEW, $storeId);
529
+ $newOrderItems = $this->getMetric(self::KEY_ORDER_SIZE_TOTAL_NEW, $storeId);
530
+ $newOrderAmount = $this->getMetric(self::KEY_ORDER_AMOUNT_TOTAL_NEW, $storeId);
531
+
532
+ $this->setMetric(
533
+ self::ACTION_UPDATE,
534
+ self::KEY_ORDER_SIZE_AVERAGE,
535
+ $storeId,
536
+ ($orderItems/$orderTotal)
537
+ );
538
+
539
+ $this->setMetric(
540
+ self::ACTION_UPDATE,
541
+ self::KEY_ORDER_AMOUNT_AVERAGE,
542
+ $storeId,
543
+ ($orderAmount/$orderTotal),
544
+ $amountUnit
545
+ );
546
+
547
+ if ($newOrderTotal > 0) {
548
+ $this->setMetric(
549
+ self::ACTION_UPDATE,
550
+ self::KEY_ORDER_SIZE_AVERAGE_NEW,
551
+ $storeId,
552
+ ($newOrderItems / $newOrderTotal)
553
+ );
554
+
555
+ $this->setMetric(
556
+ self::ACTION_UPDATE,
557
+ self::KEY_ORDER_AMOUNT_AVERAGE_NEW,
558
+ $storeId,
559
+ ($newOrderAmount / $newOrderTotal),
560
+ $amountUnit
561
+ );
562
+ }
563
+ }
564
+
565
+
566
+ public function initOrderData()
567
+ {
568
+ if (!$this->_helper->isEnabled()) {
569
+ return;
570
+ }
571
+
572
+ $collection = Mage::getResourceModel('sales/order_collection');
573
+ if (!is_object($collection)) {
574
+ return;
575
+ }
576
+ $collection->getSelect()
577
+ ->reset('columns')
578
+ ->columns(array('amount' => 'SUM(main_table.base_grand_total)',
579
+ 'items' => 'SUM(main_table.total_item_count)',
580
+ 'store_id' => 'main_table.store_id',
581
+ 'state' => 'main_table.state',
582
+ 'count' => 'COUNT(*)'))
583
+ ->group(array('main_table.store_id','main_table.state'));
584
+
585
+ $data = array();
586
+ foreach ($collection as $order) {
587
+ if (!$order->getStoreId()) {
588
+ continue;
589
+ }
590
+ if (!isset($data[$order->getStoreId()])) {
591
+ $data[$order->getStoreId()] = array(
592
+ 'items' => 0,
593
+ 'amount' => 0,
594
+ 'count' => 0,
595
+ 'new' => 0,
596
+ 'processing' => 0,
597
+ 'complete' => 0,
598
+ );
599
+ }
600
+ $data[$order->getStoreId()]['items'] += $order->getItems();
601
+ $data[$order->getStoreId()]['amount'] += $order->getAmount();
602
+ $data[$order->getStoreId()]['count'] += $order->getCount();
603
+ if ($order->getState() == Mage_Sales_Model_Order::STATE_NEW) {
604
+ $data[$order->getStoreId()]['new'] += $order->getCount();
605
+ }
606
+
607
+ if ($order->getState() == Mage_Sales_Model_Order::STATE_PROCESSING) {
608
+ $data[$order->getStoreId()]['processing'] += $order->getCount();
609
+ }
610
+
611
+ if ($order->getState() == Mage_Sales_Model_Order::STATE_COMPLETE) {
612
+ $data[$order->getStoreId()]['complete'] += $order->getCount();
613
+ }
614
+
615
+ if ($order->getState() == Mage_Sales_Model_Order::STATE_CANCELED) {
616
+ $data[$order->getStoreId()]['canceled'] += $order->getCount();
617
+ }
618
+
619
+ if ($order->getState() == Mage_Sales_Model_Order::STATE_HOLDED) {
620
+ $data[$order->getStoreId()]['holded'] += $order->getCount();
621
+ }
622
+ }
623
+ $status_collection = Mage::getResourceModel('sales/order_collection');
624
+ if (!is_object($status_collection)) {
625
+ return;
626
+ }
627
+ $status_collection->getSelect()
628
+ ->reset('columns')
629
+ ->columns(array('store_id' => 'main_table.store_id',
630
+ 'status' => 'main_table.status',
631
+ 'count' => 'COUNT(*)'))
632
+ ->group(array('main_table.store_id','main_table.status'));
633
+ foreach ($status_collection as $order) {
634
+ if (!$order->getStoreId()) {
635
+ continue;
636
+ }
637
+ if (!isset($data[$order->getStoreId()])) {
638
+ $data[$order->getStoreId()] = array(
639
+ 'status_pending' => 0,
640
+ 'status_processing' => 0,
641
+ 'status_complete' => 0
642
+ );
643
+ }
644
+ if ($order->getStatus() == $this->statusPendingPickPackKey) {
645
+ $data[$order->getStoreId()]['status_pending'] += $order->getCount();
646
+ }
647
+
648
+ if ($order->getStatus() == $this->statusPickPackKey) {
649
+ $data[$order->getStoreId()]['status_processing'] += $order->getCount();
650
+ }
651
+
652
+ if ($order->getStatus() == $this->statusCompletedPickPackKey) {
653
+ $data[$order->getStoreId()]['status_complete'] += $order->getCount();
654
+ }
655
+ }
656
+
657
+ foreach ($data as $storeId => $details) {
658
+ $amountUnit = Mage::getStoreConfig('currency/options/base', $storeId);
659
+
660
+ $this->setMetric(
661
+ self::ACTION_UPDATE,
662
+ self::KEY_ORDER_SIZE_TOTAL,
663
+ $storeId,
664
+ $details['items']
665
+ );
666
+
667
+ $this->setMetric(
668
+ self::ACTION_UPDATE,
669
+ self::KEY_ORDER_AMOUNT_TOTAL,
670
+ $storeId,
671
+ $details['amount'],
672
+ $amountUnit
673
+ );
674
+
675
+ $this->setMetric(
676
+ self::ACTION_UPDATE,
677
+ self::KEY_ORDER_TOTAL,
678
+ $storeId,
679
+ $details['count']
680
+ );
681
+
682
+ $this->setMetric(
683
+ self::ACTION_UPDATE,
684
+ self::KEY_ORDER_STATE_NEW,
685
+ $storeId,
686
+ $details['new']
687
+ );
688
+
689
+ $this->setMetric(
690
+ self::ACTION_UPDATE,
691
+ self::KEY_ORDER_STATE_PROCESSING,
692
+ $storeId,
693
+ $details['processing']
694
+ );
695
+
696
+ $this->setMetric(
697
+ self::ACTION_UPDATE,
698
+ self::KEY_ORDER_STATE_COMPLETED,
699
+ $storeId,
700
+ $details['complete']
701
+ );
702
+
703
+ $this->setMetric(
704
+ self::ACTION_UPDATE,
705
+ self::KEY_ORDER_STATE_CANCELED,
706
+ $storeId,
707
+ $details['canceled']
708
+ );
709
+
710
+ $this->setMetric(
711
+ self::ACTION_UPDATE,
712
+ self::KEY_ORDER_STATE_PENDING_PICKPACK,
713
+ $storeId,
714
+ $details['status_pending']
715
+ );
716
+
717
+ $this->setMetric(
718
+ self::ACTION_UPDATE,
719
+ self::KEY_ORDER_STATE_CURRENT_PICKPACK,
720
+ $storeId,
721
+ $details['status_processing']
722
+ );
723
+
724
+ $this->setMetric(
725
+ self::ACTION_UPDATE,
726
+ self::KEY_ORDER_STATE_COMPLETED_PICKPACK,
727
+ $storeId,
728
+ $details['status_complete']
729
+ );
730
+
731
+ $this->updateAvgOrderValues($storeId);
732
+ $this->initDefaultMetrics($storeId);
733
+ }
734
+ }
735
+
736
+ /**
737
+ * Cronjob to update the orders metrics
738
+ */
739
+ public function dailyCron()
740
+ {
741
+ if (!$this->_helper->isEnabled()) {
742
+ return;
743
+ }
744
+ $this->initOrderData();
745
+ }
746
+
747
+ /**
748
+ * Generate output event
749
+ *
750
+ * @param Varien_Event_Observer $observer
751
+ */
752
+ public function generate(Varien_Event_Observer $observer)
753
+ {
754
+ $event = $observer->getEvent();
755
+
756
+ /** @var CoScale_Monitor_Helper_Data $logger */
757
+ $logger = $event->getLogger();
758
+ /** @var CoScale_Monitor_Model_Output_Generator $output */
759
+ $output = $event->getOutput();
760
+
761
+ // Get Abandonned Carts
762
+ try {
763
+ $logger->debugStart('AbandonnedCarts');
764
+
765
+ $carts = $this->getAbandonnedCarts();
766
+ foreach ($carts as $data) {
767
+ $output->addMetric($data);
768
+ }
769
+ $logger->debugEnd('AbandonnedCarts');
770
+ } catch (Exception $ex) {
771
+ $logger->debugEndError('AbandonnedCarts', $ex);
772
+ }
773
+
774
+ // Get Email Queue Size
775
+ try {
776
+ $logger->debugStart('Email Queue Size');
777
+
778
+ foreach ($this->getEmailQueueSize() as $data) {
779
+ $output->addMetric($data);
780
+ }
781
+ $logger->debugEnd('Email Queue Size');
782
+ } catch (Exception $ex) {
783
+ $logger->debugEndError('Email Queue Size', $ex);
784
+ }
785
+ }
786
+
787
+ /**
788
+ * Get Abandonned cart amounts
789
+ * @return array
790
+ */
791
+ public function getAbandonnedCarts()
792
+ {
793
+ /** @var $collection Mage_Reports_Model_Resource_Quote_Collection */
794
+ $collection = Mage::getResourceModel('reports/quote_collection');
795
+ if (!is_object($collection)) {
796
+ return array();
797
+ }
798
+ $collection->prepareForAbandonedReport(array());
799
+ $collection->getSelect()
800
+ ->columns(array('store_id' => 'main_table.store_id',
801
+ 'count' => 'COUNT(*)',
802
+ 'subtotal' => 'SUM(subtotal)'))
803
+ ->group('main_table.store_id');
804
+ $output = array();
805
+ foreach ($collection as $order) {
806
+ $amountUnit = Mage::getStoreConfig('currency/options/base', (int)$order->getStoreId());
807
+
808
+ $this->setMetric(
809
+ self::ACTION_UPDATE,
810
+ self::KEY_ABANDONED_CARTS,
811
+ (int)$order->getStoreId(),
812
+ (float)$order->getCount()
813
+ );
814
+
815
+ $this->setMetric(
816
+ self::ACTION_UPDATE,
817
+ self::KEY_ABANDONED_CARTS_VALUE_TOTAL,
818
+ (int)$order->getStoreId(),
819
+ (float)$order->getSubtotal()
820
+ );
821
+ }
822
+ return $output;
823
+ }
824
+
825
+ public function getEmailQueueSize()
826
+ {
827
+ $edition = method_exists('Mage', 'getEdition') ? Mage::getEdition():false;
828
+
829
+ // Pre CE1.7 version => No e-mail queue available
830
+ if (!$edition) {
831
+ return array();
832
+ }
833
+
834
+ // Pre CE 1.9 version => No e-mail queue available
835
+ if ($edition == 'Community' && version_compare(Mage::getVersion(), '1.9', '<')) {
836
+ return array();
837
+ }
838
+
839
+ // Pre EE 1.14 version => No e-mail queue available
840
+ if ($edition == 'Enterprise' && version_compare(Mage::getVersion(), '1.14', '<')) {
841
+ return array();
842
+ }
843
+ $collection = Mage::getResourceModel('core/email_queue_collection');
844
+ if (!is_object($collection)) {
845
+ return array();
846
+ }
847
+ return array(array(
848
+ 'name' => 'Amount of messages in the e-mail queue',
849
+ 'unit' => 'messages',
850
+ 'value' => $collection->getSize(),
851
+ 'store_id' => 0,
852
+ 'type' => 'A'
853
+ ));
854
+ }
855
+ }
app/code/community/CoScale/Monitor/Model/Metric/Page.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Observer for the metrics related to pages
5
+ *
6
+ * @package CoScale_Monitor
7
+ * @author Mihai Oprea <mihai.oprea@issco.ro>
8
+ * @version 1.0
9
+ * @created 2016-03-28
10
+ */
11
+ class CoScale_Monitor_Model_Metric_Page extends CoScale_Monitor_Model_Metric_Abstract
12
+ {
13
+ /**
14
+ * Identifier for pageviews number total
15
+ */
16
+ const KEY_PAGEVIEWS = 4000;
17
+
18
+ /**
19
+ * Public constructor function
20
+ */
21
+ public function _contruct()
22
+ {
23
+ $this->_metricData[self::KEY_PAGEVIEWS] = array(
24
+ 'name' => 'Pageviews',
25
+ 'description' => 'The total number of pageviews for this store',
26
+ 'unit' => 'views'
27
+ );
28
+ }
29
+
30
+ /**
31
+ * Observe layout load action
32
+ */
33
+ public function startPageLoad(Varien_Event_Observer $observer)
34
+ {
35
+ if (!$this->_helper->isEnabled()) {
36
+ return;
37
+ }
38
+
39
+ $this->setMetric(
40
+ self::ACTION_INCREMENT,
41
+ self::KEY_PAGEVIEWS,
42
+ (int)Mage::app()->getStore()->getId(),
43
+ 1
44
+ );
45
+ }
46
+ }
app/code/community/CoScale/Monitor/Model/Metric/Product.php ADDED
@@ -0,0 +1,219 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Observer for the metrics related to products/categories
5
+ *
6
+ * @package CoScale_Monitor
7
+ * @author Vladimir Kerkhoff <v.kerkhoff@genmato.com>
8
+ * @version 1.0
9
+ * @created 2015-08-18
10
+ */
11
+ class CoScale_Monitor_Model_Metric_Product extends CoScale_Monitor_Model_Metric_Abstract
12
+ {
13
+ /**
14
+ * Identifier for the total number of products in the system
15
+ */
16
+ const KEY_PRODUCT_TOTAL = 3000;
17
+ const KEY_PRODUCT_TODAY = 3001;
18
+ /**
19
+ * Identifier for the total number of categories in the system
20
+ */
21
+ const KEY_CATEGORIES_TOTAL = 3010;
22
+ const KEY_CATEGORIES_TODAY = 3011;
23
+
24
+ /**
25
+ * Public contructor function
26
+ */
27
+ public function _contruct()
28
+ {
29
+ $this->_metricData[self::KEY_PRODUCT_TOTAL] = array(
30
+ 'name' => 'Products',
31
+ 'description' => 'The total number of products in the system',
32
+ 'unit' => 'products'
33
+ );
34
+
35
+ $this->_metricData[self::KEY_PRODUCT_TODAY] = array(
36
+ 'name' => 'New products today',
37
+ 'description' => 'The total number of products created today',
38
+ 'unit' => 'products'
39
+ );
40
+
41
+ $this->_metricData[self::KEY_CATEGORIES_TOTAL] = array(
42
+ 'name' => 'Categories',
43
+ 'description' => 'The total number of categories in the system',
44
+ 'unit' => 'categories'
45
+ );
46
+
47
+ $this->_metricData[self::KEY_CATEGORIES_TODAY] = array(
48
+ 'name' => 'New categories today',
49
+ 'description' => 'The total number of categories created today',
50
+ 'unit' => 'categories'
51
+ );
52
+ }
53
+
54
+ /**
55
+ * Observe the adding of new product to the system
56
+ *
57
+ * @param Varien_Event_Observer $observer
58
+ */
59
+ public function addNewProduct(Varien_Event_Observer $observer)
60
+ {
61
+ if (!$this->_helper->isEnabled()) {
62
+ return;
63
+ }
64
+
65
+ /** @var Mage_Catalog_Model_Product $product */
66
+ $product = $observer->getEvent()->getProduct();
67
+
68
+ if ($product->getOrigData('entity_id') == $product->getId()) {
69
+ return;
70
+ }
71
+
72
+ $this->setMetric(
73
+ self::ACTION_INCREMENT,
74
+ self::KEY_PRODUCT_TOTAL,
75
+ 0,
76
+ 1
77
+ );
78
+
79
+ $this->setMetric(
80
+ self::ACTION_INCREMENT,
81
+ self::KEY_PRODUCT_TODAY,
82
+ 0,
83
+ 1
84
+ );
85
+ }
86
+
87
+ /**
88
+ * Observe the remove of product
89
+ *
90
+ * @param Varien_Event_Observer $observer
91
+ */
92
+ public function removeProduct(Varien_Event_Observer $observer)
93
+ {
94
+ if (!$this->_helper->isEnabled()) {
95
+ return;
96
+ }
97
+
98
+ $this->setMetric(
99
+ self::ACTION_INCREMENT,
100
+ self::KEY_PRODUCT_TOTAL,
101
+ 0,
102
+ -1
103
+ );
104
+ }
105
+
106
+ /**
107
+ * Observe the adding of new category to the system
108
+ *
109
+ * @param Varien_Event_Observer $observer
110
+ */
111
+ public function addNewCategory(Varien_Event_Observer $observer)
112
+ {
113
+ if (!$this->_helper->isEnabled()) {
114
+ return;
115
+ }
116
+
117
+ /** @var Mage_Catalog_Model_Category $category */
118
+ $category = $observer->getEvent()->getCategory();
119
+
120
+ if ($category->getOrigData('entity_id') == $category->getId()) {
121
+ return;
122
+ }
123
+
124
+ $this->setMetric(
125
+ self::ACTION_INCREMENT,
126
+ self::KEY_CATEGORIES_TOTAL,
127
+ 0,
128
+ 1
129
+ );
130
+
131
+ $this->setMetric(
132
+ self::ACTION_INCREMENT,
133
+ self::KEY_CATEGORIES_TODAY,
134
+ 0,
135
+ 1
136
+ );
137
+ }
138
+
139
+ /**
140
+ * Observe the remove of category
141
+ *
142
+ * @param Varien_Event_Observer $observer
143
+ */
144
+ public function removeCategory(Varien_Event_Observer $observer)
145
+ {
146
+ if (!$this->_helper->isEnabled()) {
147
+ return;
148
+ }
149
+
150
+ $this->setMetric(
151
+ self::ACTION_INCREMENT,
152
+ self::KEY_CATEGORIES_TOTAL,
153
+ 0,
154
+ -1
155
+ );
156
+ }
157
+
158
+ /**
159
+ * Cronjob to update the total number of customers
160
+ */
161
+ public function dailyCron()
162
+ {
163
+ if (!$this->_helper->isEnabled()) {
164
+ return;
165
+ }
166
+ $this->resetDayCounter();
167
+ $this->updateTotalCount();
168
+ }
169
+
170
+ /**
171
+ * Reset daily new created products counter
172
+ */
173
+ protected function resetDayCounter()
174
+ {
175
+ $this->setMetric(
176
+ self::ACTION_UPDATE,
177
+ self::KEY_PRODUCT_TODAY,
178
+ 0,
179
+ 0
180
+ );
181
+
182
+ $this->setMetric(
183
+ self::ACTION_UPDATE,
184
+ self::KEY_CATEGORIES_TODAY,
185
+ 0,
186
+ 0
187
+ );
188
+ }
189
+
190
+ /**
191
+ * Daily update full numbers of products
192
+ */
193
+ public function updateTotalCount()
194
+ {
195
+ $collection = Mage::getResourceModel('catalog/product_collection');
196
+ if(!is_object($collection))
197
+ {
198
+ return;
199
+ }
200
+ $this->setMetric(
201
+ self::ACTION_UPDATE,
202
+ self::KEY_PRODUCT_TOTAL,
203
+ 0,
204
+ $collection->getSize()
205
+ );
206
+
207
+ $collection = Mage::getResourceModel('catalog/category_collection');
208
+ if(!is_object($collection))
209
+ {
210
+ return;
211
+ }
212
+ $this->setMetric(
213
+ self::ACTION_UPDATE,
214
+ self::KEY_CATEGORIES_TOTAL,
215
+ 0,
216
+ $collection->getSize()
217
+ );
218
+ }
219
+ }
app/code/community/CoScale/Monitor/Model/Metric/Rewrite.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Metrics related to ReWrites
4
+ *
5
+ * @package CoScale_Monitor
6
+ * @author Vladimir Kerkhoff <v.kerkhoff@genmato.com>
7
+ * @version 1.0
8
+ * @created 2015-08-18
9
+ */
10
+ class CoScale_Monitor_Model_Metric_Rewrite extends CoScale_Monitor_Model_Metric_Abstract
11
+ {
12
+
13
+ public function generate(Varien_Event_Observer $observer)
14
+ {
15
+ $event = $observer->getEvent();
16
+
17
+ /** @var CoScale_Monitor_Helper_Data $logger */
18
+ $logger = $event->getLogger();
19
+ /** @var CoScale_Monitor_Model_Output_Generator $output */
20
+ $output = $event->getOutput();
21
+
22
+ // Get URL Rewrites
23
+ try {
24
+ $logger->debugStart('Rewrites');
25
+
26
+ foreach ($this->getUrlRewrites() as $data) {
27
+ $output->addMetric($data);
28
+ }
29
+
30
+ $logger->debugEnd('Rewrites');
31
+ } catch (Exception $ex) {
32
+ $logger->debugEndError('Rewrites', $ex);
33
+ }
34
+ }
35
+
36
+ /**
37
+ * Get amount of rewrites
38
+ * @return array
39
+ */
40
+ public function getUrlRewrites()
41
+ {
42
+ $collection = Mage::getResourceModel('core/url_rewrite_collection');
43
+ if (!is_object($collection)) {
44
+ return array();
45
+ }
46
+ $collection->getSelect()
47
+ ->reset('columns')
48
+ ->columns(array('store_id' => 'main_table.store_id',
49
+ 'count' => 'COUNT(*)'))
50
+ ->group('main_table.store_id');
51
+
52
+ foreach ($collection as $rewrite) {
53
+ $output[] = array(
54
+ 'name' => 'URL Rewrites',
55
+ 'unit' => 'rewrites',
56
+ 'value' => (float)$rewrite->getCount(),
57
+ 'store_id' => (int)$rewrite->getStoreId(),
58
+ 'type' => 'A'
59
+ );
60
+ }
61
+ return $output;
62
+ }
63
+ }
app/code/community/CoScale/Monitor/Model/Metric/System.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class CoScale_Monitor_Model_Metric_System
4
+ {
5
+ public function generate(Varien_Event_Observer $observer)
6
+ {
7
+ $event = $observer->getEvent();
8
+
9
+ /** @var CoScale_Monitor_Helper_Data $logger */
10
+ $logger = $event->getLogger();
11
+ /** @var CoScale_Monitor_Model_Output_Generator $output */
12
+ $output = $event->getOutput();
13
+
14
+ // Get Installed Modules
15
+ try {
16
+ $logger->debugStart('Installed Modules');
17
+
18
+ $output->addCustom('modules', array('name' => 'core', 'version' => (string)Mage::getVersion()));
19
+ foreach (Mage::getConfig()->getNode('modules')->children() as $module) {
20
+ $output->addCustom('modules', array('name' => $module->getName(), 'version' => (string)$module->version));
21
+ }
22
+ $logger->debugEnd('Installed Modules');
23
+ } catch (Exception $ex) {
24
+ $logger->debugEndError('Installed Modules', $ex);
25
+ }
26
+
27
+ // Get Stores collection
28
+ try {
29
+ $logger->debugStart('Stores');
30
+
31
+ foreach (Mage::app()->getStores() as $store) {
32
+ $output->addCustom('stores', array('name' => $store->getName(), 'id' => (int)$store->getId()));
33
+ }
34
+ $logger->debugEnd('Stores');
35
+ } catch (Exception $ex) {
36
+ $logger->debugEndError('Stores', $ex);
37
+ }
38
+ }
39
+ }
app/code/community/CoScale/Monitor/Model/Output/Generator.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class CoScale_Monitor_Model_Output_Generator extends Varien_Object
4
+ {
5
+ public function __construct()
6
+ {
7
+ $logger = Mage::helper('coscale_monitor');
8
+ Mage::dispatchEvent('coscale_output_generator', array('output' => $this, 'logger'=>$logger));
9
+ }
10
+
11
+ public function addMetric($data)
12
+ {
13
+ return $this->addArray('metrics', $data);
14
+ }
15
+
16
+ public function addEvent($data)
17
+ {
18
+ return $this->addArray('events', $data);
19
+ }
20
+
21
+ public function addCustom($name, $data)
22
+ {
23
+ return $this->addArray($name, $data);
24
+ }
25
+
26
+ protected function addError()
27
+ {
28
+ $logger = Mage::helper('coscale_monitor');
29
+ $logs = $logger->getLogs();
30
+ $this->setData('error', $logs);
31
+ return $this;
32
+ }
33
+
34
+ protected function addArray($name, $data)
35
+ {
36
+ $origData = $this->getData($name);
37
+ $origData[] = $data;
38
+ $this->setData($name, $origData);
39
+ return $this;
40
+ }
41
+
42
+ public function getJsonOutput()
43
+ {
44
+ $this->addError();
45
+ return $this->toJson();
46
+ }
47
+ }
app/code/community/CoScale/Monitor/Model/Resource/Event.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * CoScale event resource model
5
+ *
6
+ * @package CoScale_Monitor
7
+ * @author Rian Orie <rian.orie@supportdesk.nu>
8
+ * @created 2015-07-03
9
+ * @version 1.0
10
+ */
11
+ class CoScale_Monitor_Model_Resource_Event extends Mage_Core_Model_Resource_Db_Abstract
12
+ {
13
+ /**
14
+ * Construct the resource model
15
+ */
16
+ protected function _construct()
17
+ {
18
+ $this->_init('coscale_monitor/event', 'id');
19
+ }
20
+
21
+ /**
22
+ * Load event by type
23
+ *
24
+ * @throws Exception
25
+ *
26
+ * @param CoScale_Monitor_Model_Event $event
27
+ * @param string $type The type identifier to load the event by
28
+ * @return $this
29
+ */
30
+ public function loadByType(CoScale_Monitor_Model_Event $event, $type)
31
+ {
32
+ $adapter = $this->_getReadAdapter();
33
+ $bind = array('type' => $type);
34
+ $select = $adapter->select()
35
+ ->from($this->getTable('coscale_monitor/event'), array('id'))
36
+ ->where('`type` = :type')
37
+ ->order('id DESC');
38
+
39
+
40
+ $eventId = $adapter->fetchOne($select, $bind);
41
+ if ($eventId) {
42
+ $this->load($event, $eventId);
43
+ } else {
44
+ $event->setData(array());
45
+ }
46
+
47
+ return $this;
48
+ }
49
+ }
app/code/community/CoScale/Monitor/Model/Resource/Event/Collection.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * CoScale event collection
5
+ *
6
+ * @package CoScale_Monitor
7
+ * @author Rian Orie <rian.orie@supportdesk.nu>
8
+ * @created 2015-07-03
9
+ * @version 1.0
10
+ */
11
+ class CoScale_Monitor_Model_Resource_Event_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
12
+ {
13
+ /**
14
+ * Construct the event collection
15
+ */
16
+ protected function _construct()
17
+ {
18
+ $this->_init('coscale_monitor/event');
19
+ }
20
+
21
+ }
app/code/community/CoScale/Monitor/Model/Resource/Metric.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * CoScale metric data resource model
5
+ *
6
+ * @package CoScale_Monitor
7
+ * @author Rian Orie <rian.orie@supportdesk_nu>
8
+ * @created 2015-07-03
9
+ * @version 1.0
10
+ */
11
+ class CoScale_Monitor_Model_Resource_Metric extends Mage_Core_Model_Resource_Db_Abstract
12
+ {
13
+ /**
14
+ * Construct the resource model
15
+ */
16
+ protected function _construct()
17
+ {
18
+ $this->_init('coscale_monitor/metric', 'id');
19
+ }
20
+
21
+ /**
22
+ * Load metric by key
23
+ *
24
+ * @param CoScale_Monitor_Model_Metric $metric
25
+ * @param int $key The identifier to load the metric by
26
+ * @param int $store The store to load the metric belongs to
27
+ *
28
+ * @return $this
29
+ *
30
+ * @throws Exception
31
+ */
32
+ public function loadByKey(CoScale_Monitor_Model_Metric $metric, $key, $store)
33
+ {
34
+ $adapter = $this->_getReadAdapter();
35
+ $bind = array('key' => $key, 'store' => $store);
36
+ $select = $adapter->select()
37
+ ->from($this->getTable('coscale_monitor/metric'), array('id'))
38
+ ->where('`key` = :key AND `store_id` = :store');
39
+
40
+
41
+ $metricId = $adapter->fetchOne($select, $bind);
42
+ if ($metricId) {
43
+ $this->load($metric, $metricId);
44
+ } else {
45
+ $metric->setData(array());
46
+ }
47
+
48
+ return $this;
49
+ }
50
+
51
+ public function truncate() {
52
+ $this->_getWriteAdapter()->query('TRUNCATE TABLE '.$this->getMainTable());
53
+ return $this;
54
+ }
55
+ }
app/code/community/CoScale/Monitor/Model/Resource/Metric/Collection.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * CoScale metric data collection
5
+ *
6
+ * @package CoScale_Monitor
7
+ * @author Rian Orie <rian.orie@supportdesk.nu>
8
+ * @created 2015-07-03
9
+ * @version 1.0
10
+ */
11
+ class CoScale_Monitor_Model_Resource_Metric_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
12
+ {
13
+ /**
14
+ * Construct the data collection
15
+ */
16
+ protected function _construct()
17
+ {
18
+ $this->_init('coscale_monitor/metric');
19
+ }
20
+ }
app/code/community/CoScale/Monitor/etc/config.xml ADDED
@@ -0,0 +1,292 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <CoScale_Monitor>
5
+ <version>0.17.1</version>
6
+ </CoScale_Monitor>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <coscale_monitor>
11
+ <class>CoScale_Monitor_Model</class>
12
+ <resourceModel>coscale_monitor_resource</resourceModel>
13
+ </coscale_monitor>
14
+ <coscale_monitor_resource>
15
+ <class>CoScale_Monitor_Model_Resource</class>
16
+ <entities>
17
+ <metric>
18
+ <table>coscale_metric</table>
19
+ </metric>
20
+ <event>
21
+ <table>coscale_event</table>
22
+ </event>
23
+ </entities>
24
+ </coscale_monitor_resource>
25
+ </models>
26
+ <blocks>
27
+ <coscale_monitor>
28
+ <class>CoScale_Monitor_Block</class>
29
+ </coscale_monitor>
30
+ </blocks>
31
+ <helpers>
32
+ <coscale_monitor>
33
+ <class>CoScale_Monitor_Helper</class>
34
+ </coscale_monitor>
35
+ </helpers>
36
+ <resources>
37
+ <coscale_monitor_setup>
38
+ <setup>
39
+ <module>CoScale_Monitor</module>
40
+ </setup>
41
+ </coscale_monitor_setup>
42
+ </resources>
43
+ <events>
44
+ <coscale_output_generator>
45
+ <observers>
46
+ <coscale_generate_metrics>
47
+ <class>coscale_monitor/metric_observer</class>
48
+ <method>generate</method>
49
+ </coscale_generate_metrics>
50
+ <coscale_generate_events>
51
+ <class>coscale_monitor/event_observer</class>
52
+ <method>generate</method>
53
+ </coscale_generate_events>
54
+ <coscale_generate_order_metrics>
55
+ <class>coscale_monitor/metric_order</class>
56
+ <method>generate</method>
57
+ </coscale_generate_order_metrics>
58
+ <coscale_generate_file_metrics>
59
+ <class>coscale_monitor/metric_file</class>
60
+ <method>generate</method>
61
+ </coscale_generate_file_metrics>
62
+ <coscale_generate_rewrite_metrics>
63
+ <class>coscale_monitor/metric_rewrite</class>
64
+ <method>generate</method>
65
+ </coscale_generate_rewrite_metrics>
66
+ <coscale_generate_system_metrics>
67
+ <class>coscale_monitor/metric_system</class>
68
+ <method>generate</method>
69
+ </coscale_generate_system_metrics>
70
+ </observers>
71
+ </coscale_output_generator>
72
+ <store_save_after>
73
+ <observers>
74
+ <coscale_monitor_event_store_add>
75
+ <class>coscale_monitor/event_store</class>
76
+ <method>addNew</method>
77
+ </coscale_monitor_event_store_add>
78
+ </observers>
79
+ </store_save_after>
80
+ <customer_save_after>
81
+ <observers>
82
+ <coscale_monitor_metric_customer_add>
83
+ <class>coscale_monitor/metric_customer</class>
84
+ <method>addNew</method>
85
+ </coscale_monitor_metric_customer_add>
86
+ </observers>
87
+ </customer_save_after>
88
+ <catalog_category_save_after>
89
+ <observers>
90
+ <coscale_monitor_metric_category_add>
91
+ <class>coscale_monitor/metric_product</class>
92
+ <method>addNewCategory</method>
93
+ </coscale_monitor_metric_category_add>
94
+ </observers>
95
+ </catalog_category_save_after>
96
+ <catalog_category_delete_commit_after>
97
+ <observers>
98
+ <coscale_monitor_metric_category_remove>
99
+ <class>coscale_monitor/metric_product</class>
100
+ <method>removeCategory</method>
101
+ </coscale_monitor_metric_category_remove>
102
+ </observers>
103
+ </catalog_category_delete_commit_after>
104
+ <catalog_product_save_after>
105
+ <observers>
106
+ <coscale_monitor_metric_product_add>
107
+ <class>coscale_monitor/metric_product</class>
108
+ <method>addNewProduct</method>
109
+ </coscale_monitor_metric_product_add>
110
+ </observers>
111
+ </catalog_product_save_after>
112
+ <catalog_product_delete_commit_after>
113
+ <observers>
114
+ <coscale_monitor_metric_product_remove>
115
+ <class>coscale_monitor/metric_product</class>
116
+ <method>removeProduct</method>
117
+ </coscale_monitor_metric_product_remove>
118
+ </observers>
119
+ </catalog_product_delete_commit_after>
120
+ <controller_action_layout_load_before>
121
+ <observers>
122
+ <coscale_monitor_event_page_load_start>
123
+ <class>coscale_monitor/metric_page</class>
124
+ <method>startPageLoad</method>
125
+ </coscale_monitor_event_page_load_start>
126
+ </observers>
127
+ </controller_action_layout_load_before>
128
+ <sales_order_place_after>
129
+ <observers>
130
+ <coscale_monitor_metric_order_add>
131
+ <class>coscale_monitor/metric_order</class>
132
+ <method>salesOrderPlaceAfter</method>
133
+ </coscale_monitor_metric_order_add>
134
+ </observers>
135
+ </sales_order_place_after>
136
+ <sales_order_save_after>
137
+ <observers>
138
+ <coscale_monitor_metric_order_save>
139
+ <class>coscale_monitor/metric_order</class>
140
+ <method>salesOrderSaveAfter</method>
141
+ </coscale_monitor_metric_order_save>
142
+ </observers>
143
+ </sales_order_save_after>
144
+
145
+ <controller_action_predispatch_adminhtml_process_massReindex>
146
+ <observers>
147
+ <coscale_monitor_event_reindex_start>
148
+ <class>coscale_monitor/event_reindex</class>
149
+ <method>startIndex</method>
150
+ </coscale_monitor_event_reindex_start>
151
+ </observers>
152
+ </controller_action_predispatch_adminhtml_process_massReindex>
153
+ <controller_action_postdispatch_adminhtml_process_massReindex>
154
+ <observers>
155
+ <coscale_monitor_event_reindex_start>
156
+ <class>coscale_monitor/event_reindex</class>
157
+ <method>endIndex</method>
158
+ </coscale_monitor_event_reindex_start>
159
+ </observers>
160
+ </controller_action_postdispatch_adminhtml_process_massReindex>
161
+
162
+ <controller_action_predispatch_adminhtml_cache_flushSystem>
163
+ <observers>
164
+ <coscale_monitor_event_reindex_start>
165
+ <class>coscale_monitor/event_cache</class>
166
+ <method>startFlushSystem</method>
167
+ </coscale_monitor_event_reindex_start>
168
+ </observers>
169
+ </controller_action_predispatch_adminhtml_cache_flushSystem>
170
+ <controller_action_postdispatch_adminhtml_cache_flushSystem>
171
+ <observers>
172
+ <coscale_monitor_event_reindex_start>
173
+ <class>coscale_monitor/event_cache</class>
174
+ <method>endFlushSystem</method>
175
+ </coscale_monitor_event_reindex_start>
176
+ </observers>
177
+ </controller_action_postdispatch_adminhtml_cache_flushSystem>
178
+
179
+ <controller_action_predispatch_adminhtml_cache_flushAll>
180
+ <observers>
181
+ <coscale_monitor_event_reindex_start>
182
+ <class>coscale_monitor/event_cache</class>
183
+ <method>startFlushAll</method>
184
+ </coscale_monitor_event_reindex_start>
185
+ </observers>
186
+ </controller_action_predispatch_adminhtml_cache_flushAll>
187
+ <controller_action_postdispatch_adminhtml_cache_flushAll>
188
+ <observers>
189
+ <coscale_monitor_event_reindex_start>
190
+ <class>coscale_monitor/event_cache</class>
191
+ <method>endFlushAll</method>
192
+ </coscale_monitor_event_reindex_start>
193
+ </observers>
194
+ </controller_action_postdispatch_adminhtml_cache_flushAll>
195
+
196
+ <controller_action_predispatch_adminhtml_cache_cleanImages>
197
+ <observers>
198
+ <coscale_monitor_event_reindex_start>
199
+ <class>coscale_monitor/event_cache</class>
200
+ <method>startCleanImages</method>
201
+ </coscale_monitor_event_reindex_start>
202
+ </observers>
203
+ </controller_action_predispatch_adminhtml_cache_cleanImages>
204
+ <controller_action_postdispatch_adminhtml_cache_cleanImages>
205
+ <observers>
206
+ <coscale_monitor_event_reindex_start>
207
+ <class>coscale_monitor/event_cache</class>
208
+ <method>endCleanImages</method>
209
+ </coscale_monitor_event_reindex_start>
210
+ </observers>
211
+ </controller_action_postdispatch_adminhtml_cache_cleanImages>
212
+
213
+ <controller_action_predispatch_adminhtml_cache_cleanMedia>
214
+ <observers>
215
+ <coscale_monitor_event_reindex_start>
216
+ <class>coscale_monitor/event_cache</class>
217
+ <method>startCleanAssets</method>
218
+ </coscale_monitor_event_reindex_start>
219
+ </observers>
220
+ </controller_action_predispatch_adminhtml_cache_cleanMedia>
221
+ <controller_action_postdispatch_adminhtml_cache_cleanMedia>
222
+ <observers>
223
+ <coscale_monitor_event_reindex_start>
224
+ <class>coscale_monitor/event_cache</class>
225
+ <method>endCleanAssets</method>
226
+ </coscale_monitor_event_reindex_start>
227
+ </observers>
228
+ </controller_action_postdispatch_adminhtml_cache_cleanMedia>
229
+
230
+ <controller_action_predispatch_adminhtml_cache_massRefresh>
231
+ <observers>
232
+ <coscale_monitor_event_reindex_start>
233
+ <class>coscale_monitor/event_cache</class>
234
+ <method>startMassRefresh</method>
235
+ </coscale_monitor_event_reindex_start>
236
+ </observers>
237
+ </controller_action_predispatch_adminhtml_cache_massRefresh>
238
+ <controller_action_postdispatch_adminhtml_cache_massRefresh>
239
+ <observers>
240
+ <coscale_monitor_event_reindex_start>
241
+ <class>coscale_monitor/event_cache</class>
242
+ <method>endMassRefresh</method>
243
+ </coscale_monitor_event_reindex_start>
244
+ </observers>
245
+ </controller_action_postdispatch_adminhtml_cache_massRefresh>
246
+ </events>
247
+ </global>
248
+ <frontend>
249
+ <layout>
250
+ <updates>
251
+ <coscale_monitor>
252
+ <file>coscale_monitor.xml</file>
253
+ </coscale_monitor>
254
+ </updates>
255
+ </layout>
256
+ </frontend>
257
+ <default>
258
+ <coscale>
259
+ <general>
260
+ <maxruntime>1000</maxruntime>
261
+ </general>
262
+ </coscale>
263
+ <system>
264
+ <coscale_monitor>
265
+ <enabled>1</enabled>
266
+ <status_pickpack_pending>processing</status_pickpack_pending>
267
+ <status_pickpack>processing_pickpack</status_pickpack>
268
+ <status_pickpack_completed>processing_pickpack_done</status_pickpack_completed>
269
+ <state_new_key>new</state_new_key>
270
+ <state_processing_key>processing</state_processing_key>
271
+ <state_completed_key>complete</state_completed_key>
272
+ <state_canceled_key>canceled</state_canceled_key>
273
+ <status_pickpack_pending_key>pending</status_pickpack_pending_key>
274
+ <status_pickpack_key>processing</status_pickpack_key>
275
+ <status_pickpack_completed_key>complete</status_pickpack_completed_key>
276
+ </coscale_monitor>
277
+ </system>
278
+ </default>
279
+
280
+ <crontab>
281
+ <jobs>
282
+ <coscale_daily_cron>
283
+ <schedule>
284
+ <cron_expr>0 0 * * *</cron_expr>
285
+ </schedule>
286
+ <run>
287
+ <model>coscale_monitor/cronjob::dailyCron</model>
288
+ </run>
289
+ </coscale_daily_cron>
290
+ </jobs>
291
+ </crontab>
292
+ </config>
app/code/community/CoScale/Monitor/etc/system.xml ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <system>
5
+ <groups>
6
+ <coscale_monitor>
7
+ <label>CoScale Monitoring</label>
8
+ <sort_order>200</sort_order>
9
+ <show_in_default>1</show_in_default>
10
+ <show_in_website>0</show_in_website>
11
+ <show_in_store>0</show_in_store>
12
+ <fields>
13
+ <enabled>
14
+ <label>Enabled</label>
15
+ <frontend_type>select</frontend_type>
16
+ <source_model>adminhtml/system_config_source_yesno</source_model>
17
+ <sort_order>1</sort_order>
18
+ <show_in_default>1</show_in_default>
19
+ <show_in_website>0</show_in_website>
20
+ <show_in_store>0</show_in_store>
21
+ </enabled>
22
+ <status_pickpack_pending>
23
+ <label>Status Pending Pickpack</label>
24
+ <frontend_type>select</frontend_type>
25
+ <source_model>adminhtml/system_config_source_order_status</source_model>
26
+ <depends><enabled>1</enabled></depends>
27
+ <sort_order>10</sort_order>
28
+ <show_in_default>1</show_in_default>
29
+ <show_in_website>0</show_in_website>
30
+ <show_in_store>0</show_in_store>
31
+ </status_pickpack_pending>
32
+ <status_pickpack>
33
+ <label>Status During Pickpack</label>
34
+ <frontend_type>select</frontend_type>
35
+ <source_model>adminhtml/system_config_source_order_status</source_model>
36
+ <depends><enabled>1</enabled></depends>
37
+ <sort_order>11</sort_order>
38
+ <show_in_default>1</show_in_default>
39
+ <show_in_website>0</show_in_website>
40
+ <show_in_store>0</show_in_store>
41
+ </status_pickpack>
42
+ <status_pickpack_completed>
43
+ <label>Status Completed Pickpack</label>
44
+ <frontend_type>select</frontend_type>
45
+ <source_model>adminhtml/system_config_source_order_status</source_model>
46
+ <depends><enabled>1</enabled></depends>
47
+ <sort_order>12</sort_order>
48
+ <show_in_default>1</show_in_default>
49
+ <show_in_website>0</show_in_website>
50
+ <show_in_store>0</show_in_store>
51
+ </status_pickpack_completed>
52
+ </fields>
53
+ </coscale_monitor>
54
+ </groups>
55
+ </system>
56
+ </sections>
57
+ </config>
app/code/community/CoScale/Monitor/sql/coscale_monitor_setup/install-0.1.0.php ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Set up an key value based database structure
4
+ *
5
+ * @package CoScale_Monitor
6
+ * @author Rian Orie <rian.orie@supportdesk.nu>
7
+ * @created 2015-07-03
8
+ * @version 1.0
9
+ */
10
+ /* @var $installer Mage_Core_Model_Resource_Setup */
11
+ $installer = $this;
12
+
13
+ $installer->startSetup();
14
+
15
+ $event = $installer->getConnection()
16
+ ->newTable($installer->getTable('coscale_monitor/event'))
17
+ ->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER,
18
+ 10,
19
+ array(
20
+ 'nullable' => false,
21
+ 'primary' => true,
22
+ 'identity' => true
23
+ ),
24
+ 'Identifier')
25
+ ->addColumn('name', Varien_Db_Ddl_Table::TYPE_VARCHAR,
26
+ 255,
27
+ array(
28
+ 'nullable' => false,
29
+ 'primary' => false,
30
+ ),
31
+ 'Event name')
32
+ ->addColumn('description', Varien_Db_Ddl_Table::TYPE_VARCHAR,
33
+ 255,
34
+ array(
35
+ 'nullable' => false,
36
+ 'primary' => false,
37
+ ),
38
+ 'Event description')
39
+ ->addColumn('event_data', Varien_Db_Ddl_Table::TYPE_VARCHAR,
40
+ 255,
41
+ array(
42
+ 'nullable' => true,
43
+ 'primary' => false,
44
+ ),
45
+ 'Event data (json)')
46
+ ->addColumn('type', Varien_Db_Ddl_Table::TYPE_VARCHAR,
47
+ 50,
48
+ array(
49
+ 'nullable' => false,
50
+ 'primary' => false,
51
+ ),
52
+ 'Event type')
53
+ ->addColumn('source', Varien_Db_Ddl_Table::TYPE_VARCHAR,
54
+ 50,
55
+ array(
56
+ 'nullable' => false,
57
+ 'primary' => false,
58
+ ),
59
+ 'Event source')
60
+ ->addColumn('state', Varien_Db_Ddl_Table::TYPE_INTEGER,
61
+ 1,
62
+ array(
63
+ 'nullable' => false,
64
+ 'primary' => false,
65
+ ),
66
+ 'Event state (-1 = disabled, 0 = inactive, 1 = on)')
67
+ ->addColumn('version', Varien_Db_Ddl_Table::TYPE_VARCHAR,
68
+ 10,
69
+ array(
70
+ 'nullable' => false,
71
+ 'primary' => false,
72
+ ),
73
+ 'Event version (incremented on every update)')
74
+ ->addColumn('timestamp', Varien_Db_Ddl_Table::TYPE_INTEGER,
75
+ 15,
76
+ array(),
77
+ 'Update timestamp')
78
+ ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP,
79
+ null,
80
+ array(),
81
+ 'Update Timestamp readable')
82
+ ->setComment('CoScale event data');
83
+
84
+ $event->setOption('type', 'MEMORY');
85
+
86
+ $metric = $installer->getConnection()
87
+ ->newTable($installer->getTable('coscale_monitor/metric'))
88
+ ->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER,
89
+ 5,
90
+ array(
91
+ 'nullable' => false,
92
+ 'primary' => true,
93
+ 'identity' => true
94
+ ),
95
+ 'Identifier')
96
+ ->addColumn('key', Varien_Db_Ddl_Table::TYPE_INTEGER,
97
+ 5,
98
+ array(
99
+ 'nullable' => false,
100
+ 'primary' => false,
101
+ ),
102
+ 'Fixed identifier for the metric')
103
+ ->addColumn('datatype', Varien_Db_Ddl_Table::TYPE_VARCHAR,
104
+ 32,
105
+ array(
106
+ 'nullable' => false,
107
+ 'primary' => false,
108
+ ),
109
+ 'Metric datatype')
110
+ ->addColumn('name', Varien_Db_Ddl_Table::TYPE_VARCHAR,
111
+ 255,
112
+ array(
113
+ 'nullable' => false,
114
+ 'primary' => false,
115
+ ),
116
+ 'Metric name')
117
+ ->addColumn('description', Varien_Db_Ddl_Table::TYPE_VARCHAR,
118
+ 255,
119
+ array(
120
+ 'nullable' => false,
121
+ 'primary' => false,
122
+ ),
123
+ 'Metric description')
124
+ ->addColumn('value', Varien_Db_Ddl_Table::TYPE_VARCHAR,
125
+ 255,
126
+ array(
127
+ 'nullable' => true,
128
+ 'primary' => false,
129
+ ),
130
+ 'Metric value (mixed content)')
131
+ ->addColumn('unit', Varien_Db_Ddl_Table::TYPE_VARCHAR,
132
+ 10,
133
+ array(
134
+ 'nullable' => false,
135
+ 'primary' => false,
136
+ ),
137
+ 'Metric unit')
138
+ ->addColumn('groups', Varien_Db_Ddl_Table::TYPE_VARCHAR,
139
+ 255,
140
+ array(
141
+ 'nullable' => true,
142
+ 'primary' => false,
143
+ ),
144
+ 'Metric groups')
145
+ ->addColumn('tags', Varien_Db_Ddl_Table::TYPE_VARCHAR,
146
+ 255,
147
+ array(
148
+ 'nullable' => true,
149
+ 'primary' => false,
150
+ ),
151
+ 'Metric tags')
152
+ ->addColumn('calctype', Varien_Db_Ddl_Table::TYPE_INTEGER,
153
+ 2,
154
+ array(
155
+ 'nullable' => false,
156
+ 'primary' => false,
157
+ ),
158
+ 'Metric calculation type')
159
+ ->addColumn('timestamp', Varien_Db_Ddl_Table::TYPE_INTEGER,
160
+ 15,
161
+ array(),
162
+ 'Update timestamp')
163
+ ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP,
164
+ null,
165
+ array(),
166
+ 'Update Timestamp')
167
+ ->addIndex('COSCALE_METRIC_UNIQUE_IDX', 'key', array('type' => 'UNIQUE'))
168
+ ->setComment('CoScale metric data');
169
+
170
+ $metric->setOption('type', 'MEMORY');
171
+
172
+
173
+ $installer->getConnection()->createTable($event);
174
+ $installer->getConnection()->createTable($metric);
175
+ $installer->endSetup();
app/code/community/CoScale/Monitor/sql/coscale_monitor_setup/upgrade-0.1.0-0.2.0.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Set up an key value based database structure
4
+ *
5
+ * @package CoScale_Monitor
6
+ * @author Rian Orie <rian.orie@supportdesk.nu>
7
+ * @created 2015-07-03
8
+ * @version 1.0
9
+ */
10
+ /* @var $installer Mage_Core_Model_Resource_Setup */
11
+ $installer = $this;
12
+
13
+ $installer->startSetup();
14
+
15
+ $event = $installer->getConnection();
16
+ $event->addColumn($installer->getTable('coscale_monitor/event'), 'duration', 'INT UNSIGNED NULL AFTER `timestamp`');
17
+
18
+ $installer->endSetup();
app/code/community/CoScale/Monitor/sql/coscale_monitor_setup/upgrade-0.12.0-0.13.0.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package CoScale_Monitor
4
+ * @author V. Kerkhoff <v.kerkhoff@genmato.com>
5
+ * @created 2016-03-25
6
+ * @version 0.13.0
7
+ *
8
+ * @author Mihai Oprea <mihai.oprea@issco.ro>
9
+ * @created 2016-03-03
10
+ * @version 0.12.0
11
+ */
12
+ /* @var $installer Mage_Core_Model_Resource_Setup */
13
+ $installer = $this;
14
+
15
+ $installer->startSetup();
16
+
17
+ $installer->getConnection()
18
+ ->addColumn(
19
+ $installer->getTable('coscale_monitor/metric'),
20
+ 'calculation_type',
21
+ array(
22
+ 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
23
+ 'nullable' => false,
24
+ 'default' => 0,
25
+ 'comment' => 'Calculation Type'
26
+ )
27
+ );
28
+ $metric = $installer->getConnection();
29
+
30
+ /**
31
+ * Initialize order data for further delta processing
32
+ */
33
+ Mage::getSingleton('coscale_monitor/metric_order')->initOrderData();
34
+ Mage::getSingleton('coscale_monitor/metric_customer')->updateTotalCount();
35
+ Mage::getSingleton('coscale_monitor/metric_product')->updateTotalCount();
36
+
37
+ $installer->endSetup();
app/code/community/CoScale/Monitor/sql/coscale_monitor_setup/upgrade-0.14.0-0.15.0.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package CoScale_Monitor
4
+ * @author Mihai Oprea <mihai.oprea@issco.ro>
5
+ * @created 2016-05-18
6
+ * @version 0.15.0
7
+ */
8
+ $installer = $this;
9
+
10
+ $installer->startSetup();
11
+
12
+ $metric = $installer->getConnection();
13
+
14
+ /**
15
+ * Initialize order data for further delta processing
16
+ */
17
+ Mage::getSingleton('coscale_monitor/metric_order')->initOrderData();
18
+ Mage::getSingleton('coscale_monitor/metric_customer')->updateTotalCount();
19
+ Mage::getSingleton('coscale_monitor/metric_product')->updateTotalCount();
20
+
21
+ $installer->endSetup();
app/code/community/CoScale/Monitor/sql/coscale_monitor_setup/upgrade-0.2.0-0.3.0.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Set up an key value based database structure
4
+ *
5
+ * @package CoScale_Monitor
6
+ * @author Rian Orie <rian.orie@supportdesk.nu>
7
+ * @created 2015-07-03
8
+ * @version 1.0
9
+ */
10
+ /* @var $installer Mage_Core_Model_Resource_Setup */
11
+ $installer = $this;
12
+
13
+ $installer->startSetup();
14
+
15
+ $event = $installer->getConnection();
16
+ $event->addColumn($installer->getTable('coscale_monitor/event'), 'timestamp_end', 'INT(11) UNSIGNED NULL AFTER `timestamp`');
17
+ $event->dropColumn($installer->getTable('coscale_monitor/event'), 'duration');
18
+ $event->changeColumn($installer->getTable('coscale_monitor/event'), 'timestamp', 'timestamp_start', 'INT(11) UNSIGNED NULL');
19
+
20
+ $installer->endSetup();
app/code/community/CoScale/Monitor/sql/coscale_monitor_setup/upgrade-0.3.0-0.4.0.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Set up an key value based database structure
4
+ *
5
+ * @package CoScale_Monitor
6
+ * @author Rian Orie <rian.orie@supportdesk.nu>
7
+ * @created 2015-07-03
8
+ * @version 1.0
9
+ */
10
+ /* @var $installer Mage_Core_Model_Resource_Setup */
11
+ $installer = $this;
12
+
13
+ $installer->startSetup();
14
+
15
+ $metric = $installer->getConnection();
16
+ $metric->changeColumn($installer->getTable('coscale_monitor/metric'), 'datatype', 'type', 'VARCHAR(1) NULL');
17
+ $metric->dropColumn($installer->getTable('coscale_monitor/metric'), 'groups');
18
+ $metric->dropColumn($installer->getTable('coscale_monitor/metric'), 'tags');
19
+ $metric->dropColumn($installer->getTable('coscale_monitor/metric'), 'calctype');
20
+ $metric->addColumn($installer->getTable('coscale_monitor/metric'), 'store_id', 'INT(5) UNSIGNED NOT NULL');
21
+
22
+ $metric->dropIndex($installer->getTable('coscale_monitor/metric'), 'COSCALE_METRIC_UNIQUE_IDX');
23
+ $metric->addIndex($installer->getTable('coscale_monitor/metric'), 'COSCALE_METRIC_UNIQUE_IDX', array('key', 'store_id'), $metric::INDEX_TYPE_UNIQUE);
24
+
25
+ $installer->endSetup();
app/code/community/CoScale/Monitor/sql/coscale_monitor_setup/upgrade-0.4.0-0.5.0.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Change storige engine for metric table
4
+ *
5
+ * @package CoScale_Monitor
6
+ * @author V. Kerkhoff <v.kerkhoff@genmato.com>
7
+ * @created 2015-08-18
8
+ * @version 0.5
9
+ */
10
+ /* @var $installer Mage_Core_Model_Resource_Setup */
11
+ $installer = $this;
12
+
13
+ $installer->startSetup();
14
+
15
+ $metric = $installer->getConnection();
16
+ $metric->changeTableEngine($installer->getTable('coscale_monitor/metric'), 'InnoDB');
17
+
18
+
19
+ /**
20
+ * Initialize order data for further delta processing
21
+ */
22
+ Mage::getSingleton('coscale_monitor/metric_order')->initOrderData();
23
+
24
+ $installer->endSetup();
app/design/frontend/base/default/layout/coscale_monitor.xml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <layout version="0.1.0">
2
+
3
+ <!--
4
+ Default layout, loads most of the pages
5
+ -->
6
+
7
+ <default>
8
+ <reference name="head" before="-">
9
+ <block type="core/template" name="coscale_monitor" as="coscale_monitor" template="coscale_monitor/rum.phtml" />
10
+ </reference>
11
+ </default>
12
+ </layout>
app/design/frontend/base/default/template/coscale_monitor/rum.phtml ADDED
@@ -0,0 +1 @@
 
1
+ <!-- CoScale RUM script will be added here automatically when RUM will be enabled for Magento plugin in CoScale interface -->
app/etc/modules/CoScale_Monitor.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <CoScale_Monitor>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </CoScale_Monitor>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>CoScale</name>
4
+ <version>0.17.1</version>
5
+ <stability>stable</stability>
6
+ <license>MITL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>This module enables you to send important business and IT metrics from Magento to CoScale.</summary>
10
+ <description>The CoScale module exposes Magento events and metrics to the CoScale Agent. The metrics contain business metrics, such as the number of products, orders, abondoned carts, etc and technical metrics such as Magento caching metrics. The events contain magento admin actions such as page cache flushes, reindexing, etc.</description>
11
+ <notes>The CoScale module is still under development. All feedback is welcome. </notes>
12
+ <authors><author><name>CoScale Developer</name><user>cs-dev</user><email>info@coscale.com</email></author></authors>
13
+ <date>2015-08-13</date>
14
+ <time>09:29:57</time>
15
+ <contents><target name="mage"><dir name="."><dir name="app"><dir name="code"><dir name="community"><dir name="CoScale"><dir name="Monitor"><dir name="etc"><file name="config.xml" hash="a4dba5ce3d656c88d5329e0d89a4cc67"/><file name="system.xml" hash="42be2964b9a0099bbb368c2d2cc9b0d3"/></dir><dir name="Helper"><file name="Data.php" hash="775ee001d20ad17751432f5a4cc92dc4"/></dir><dir name="Model"><file name="Cronjob.php" hash="440d107abacedd191021e589ed401602"/><dir name="Event"><file name="Cache.php" hash="2109ac7d1cb9d6fd9315f7fb0f3a67b1"/><file name="Observer.php" hash="a817985e8b961d75bbaeda0390e2e946"/><file name="Reindex.php" hash="09f014e4c39c53f6269807f1a653eb08"/><file name="Store.php" hash="30322b55ffbbd3b56241ef3df38ca7d2"/></dir><file name="Event.php" hash="1071a8393fb9a435ccf4b2a39a8c2720"/><dir name="Metric"><file name="Abstract.php" hash="5446f871617d948e13399c888021a796"/><file name="Customer.php" hash="791170ce6b6850966faa6003937b43fb"/><file name="File.php" hash="c1fef22000a768890023fa6d46fa4072"/><file name="Observer.php" hash="aa5898991e81b8e0401ec65a600d2473"/><file name="Order.php" hash="8cc3d9d9c53d1bbd73574ae86764e4ac"/><file name="Page.php" hash="40578366d1986afc96cbb40e23a844b9"/><file name="Product.php" hash="b6cf5bfecb5f2d33a43f6d37eef74625"/><file name="Rewrite.php" hash="9da7e8f4c454a80a296f515e71230824"/><file name="System.php" hash="bdbf7ae7d1430e1bc8ded38ba9ed2f60"/></dir><file name="Metric.php" hash="d48ed016231bae3b54435442d412c871"/><dir name="Output"><file name="Generator.php" hash="f2b7654a622f3adc2e3381348d61529c"/></dir><dir name="Resource"><dir name="Event"><file name="Collection.php" hash="b9f1136e9a418a92ca86096664cab4d1"/></dir><file name="Event.php" hash="412b640cd9b285406cc368057af3d620"/><dir name="Metric"><file name="Collection.php" hash="c2437a6f5e402d78e6e674ed0be4609c"/></dir><file name="Metric.php" hash="d2ae09e99911bd9756122b3679607150"/></dir></dir><dir name="sql"><dir name="coscale_monitor_setup"><file name="install-0.1.0.php" hash="05c50b690e49378003938abbe894f8ee"/><file name="upgrade-0.1.0-0.2.0.php" hash="6e6813a302af3f75d97a33158f1717b2"/><file name="upgrade-0.12.0-0.13.0.php" hash="908ae2e45ff7f39e14ec222ccbc62823"/><file name="upgrade-0.14.0-0.15.0.php" hash="f3282813a8149eb30f4952361a3c3b22"/><file name="upgrade-0.2.0-0.3.0.php" hash="191d51c3ece4fddc2aa3cf7e66c8be51"/><file name="upgrade-0.3.0-0.4.0.php" hash="4c7178d394eb42e9933beab9b1079492"/><file name="upgrade-0.4.0-0.5.0.php" hash="dd2bfe447e09f818512a724ca1847726"/></dir></dir></dir></dir></dir></dir><dir name="design"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="coscale_monitor.xml" hash="f90eb20b268a97486469d16e3f75f087"/></dir><dir name="template"><dir name="coscale_monitor"><file name="rum.phtml" hash="8784353a1539341957b301c944961615"/></dir></dir></dir></dir></dir></dir><dir name="etc"><dir name="modules"><file name="CoScale_Monitor.xml" hash="3aaf3341c82ee74aa76dbe6764b423f5"/></dir></dir></dir><dir name="shell"><file name="coscale.php" hash="337819df7fe81aeb039bbb68ba4c4039"/><file name="coscale_reset.php" hash="73dd6068fcaef6bda5ed7eb669e74ec0"/></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.3.0</min><max>7.0.5-2</max></php></required></dependencies>
18
+ </package>
shell/coscale.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once 'abstract.php';
4
+
5
+ /**
6
+ * CoScale shell script that will output the different elements of the module
7
+ *
8
+ * @package CoScale_Monitor
9
+ * @author Rian Orie <rian.orie@supportdesk.nu>
10
+ * @created 2015-07-03
11
+ * @version 1.0
12
+ */
13
+ class CoScale_Shell extends Mage_Shell_Abstract
14
+ {
15
+ protected $debug = false;
16
+
17
+ /**
18
+ * Execute the script
19
+ */
20
+ public function run()
21
+ {
22
+ $helper = Mage::helper('coscale_monitor');
23
+
24
+ if ($this->getArg('debug')) {
25
+ $helper->enableDebug();
26
+ }
27
+
28
+ if (!$helper->isEnabled()) {
29
+ echo json_encode(array('error'=>'CoScale Module not active!' . ' ' . $helper->getLogs()));
30
+ return;
31
+ }
32
+
33
+ // Generate output
34
+ try {
35
+ $helper->debugStart('Output Generation');
36
+ echo Mage::getSingleton('coscale_monitor/output_generator')->getJsonOutput();
37
+ $helper->debugEnd('Output Generation');
38
+ } catch (Exception $ex) {
39
+ $helper->debugEndError('Output Generation', $ex);
40
+ }
41
+ }
42
+ }
43
+
44
+ $shell = new CoScale_Shell();
45
+ $shell->run();
shell/coscale_reset.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once 'abstract.php';
4
+
5
+ /**
6
+ * CoScale shell script that will reset the different elements of the module
7
+ *
8
+ * @package CoScale_Monitor
9
+ * @author Mihai Oprea <mihai.oprea@issco.ro>
10
+ * @created 2016-08-11
11
+ * @version 1.0
12
+ */
13
+ class CoScale_Reset extends Mage_Shell_Abstract
14
+ {
15
+ /**
16
+ * Execute the script
17
+ */
18
+ public function run()
19
+ {
20
+ $helper = Mage::helper('coscale_monitor');
21
+
22
+ // Reset data
23
+ try {
24
+ $helper->debugStart('Metrics reset');
25
+ Mage::getResourceModel('coscale_monitor/metric')->truncate();
26
+
27
+ Mage::getSingleton('coscale_monitor/metric_order')->initOrderData();
28
+ Mage::getSingleton('coscale_monitor/metric_customer')->updateTotalCount();
29
+ Mage::getSingleton('coscale_monitor/metric_product')->updateTotalCount();
30
+ $helper->debugEnd('Metrics reset');
31
+ } catch (Exception $ex) {
32
+ $helper->debugEndError('Reset script', $ex);
33
+ }
34
+ }
35
+ }
36
+
37
+ $shell = new CoScale_Reset();
38
+ $shell->run();