-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
765 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
app/code/community/CoScale/Monitor/Model/Event/Observer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
class CoScale_Monitor_Model_Event_Observer | ||
{ | ||
public function generate(Varien_Event_Observer $observer) | ||
{ | ||
$event = $observer->getEvent(); | ||
|
||
/** @var CoScale_Monitor_Helper_Data $logger */ | ||
$logger = $event->getLogger(); | ||
/** @var CoScale_Monitor_Model_Output_Generator $output */ | ||
$output = $event->getOutput(); | ||
|
||
// Get Events Collection | ||
try { | ||
$logger->debugStart('Events Collection'); | ||
|
||
$collection = Mage::getModel('coscale_monitor/event')->getCollection(); | ||
/** @var CoScale_Monitor_Model_Event $event */ | ||
foreach ($collection as $event) { | ||
$output->addEvent( | ||
array( | ||
'type' => $event->getTypeGroup(), | ||
'message' => $event->getDescription(), | ||
'data' => array_merge( | ||
array('originator' => $event->getSource()), | ||
unserialize($event->getEventData()) | ||
), | ||
'start_time' => (int)(time() - $event->getTimestampStart()), | ||
'stop_time' => (int)($event->getTimestampEnd() != 0 ? (time() - $event->getTimestampEnd()) : 0), | ||
) | ||
); | ||
|
||
$event->delete(); | ||
if ($event->getState() != $event::STATE_ENABLED) { | ||
//$event->delete(); | ||
} | ||
} | ||
$logger->debugEnd('Events Collection'); | ||
} catch (Exception $ex) { | ||
$logger->debugEndError('Events Collection', $ex); | ||
} | ||
|
||
// Get Cronjob Collection | ||
try { | ||
$logger->debugStart('Cronjob Collection'); | ||
|
||
$endDateTime = date('U'); | ||
$collection = Mage::getModel('cron/schedule')->getCollection() | ||
->addFieldToFilter('finished_at', array('from' => date('Y-m-d H:i:s', $endDateTime-65))) | ||
->setOrder('finished_at', 'DESC'); | ||
/** @var Mage_Cron_Model_Schedule $event */ | ||
foreach ($collection as $cron) { | ||
$output['events'][] = array( | ||
'type' => CoScale_Monitor_Model_Event::GROUP_CRON, | ||
'message' => $cron->getJobCode(), | ||
'status' => $cron->getStatus(), | ||
'start_time' => (int)(time() - strtotime($cron->getExecutedAt())), | ||
'stop_time' => (int)(time() - strtotime($cron->getFinishedAt())), | ||
); | ||
} | ||
$logger->debugEnd('Cronjob Collection'); | ||
} catch (Exception $ex) { | ||
$logger->debugEndError('Events Collection', $ex); | ||
} | ||
|
||
try { | ||
$logger->debugStart('Maintenance Flag'); | ||
if (file_exists(Mage::getBaseDir('base') . DS . 'maintenance.flag')) { | ||
$output['events'][] = array( | ||
'type' => CoScale_Monitor_Model_Event::GROUP_ADMIN, | ||
'message' => 'Maintenance mode enabled', | ||
'start_time' => 0, | ||
'stop_time' => 0, | ||
); | ||
} | ||
$logger->debugEnd('Maintenance Flag'); | ||
} catch (Exception $ex) { | ||
$logger->debugEndError('Maintenance Flag', $ex); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
app/code/community/CoScale/Monitor/Model/Metric/Observer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
class CoScale_Monitor_Model_Metric_Observer | ||
{ | ||
public function generate(Varien_Event_Observer $observer) | ||
{ | ||
$event = $observer->getEvent(); | ||
|
||
/** @var CoScale_Monitor_Helper_Data $logger */ | ||
$logger = $event->getLogger(); | ||
/** @var CoScale_Monitor_Model_Output_Generator $output */ | ||
$output = $event->getOutput(); | ||
|
||
// Get Metrics Collection | ||
try { | ||
$logger->debugStart('Metrics Collection'); | ||
|
||
$metricOrderDelete = Mage::getSingleton('coscale_monitor/metric_order'); | ||
$collection = Mage::getModel('coscale_monitor/metric')->getCollection(); | ||
/** @var CoScale_Monitor_Model_Metric $metric */ | ||
foreach ($collection as $metric) { | ||
$output->addMetric( | ||
array( | ||
'name' => $metric->getName(), | ||
'unit' => $metric->getUnit(), | ||
'value' => (float)$metric->getValue(), | ||
'store_id' => (int)$metric->getStoreId(), | ||
'type' => $metric->getTypeText() | ||
) | ||
); | ||
|
||
// Check if metric need to be reset after collection | ||
if ($metricOrderDelete->resetOnCollect($metric->getKey())) { | ||
$metric->delete(); | ||
} | ||
} | ||
$logger->debugEnd('Metrics Collection'); | ||
} catch (Exception $ex) { | ||
$logger->debugEndError('Metrics Collection', $ex); | ||
} | ||
} | ||
} |
Oops, something went wrong.