php – Magento:监控所有cron作业的执行时间?

我继承了一个基于Magento Enterprise 1.9的网站,该网站有很多定期运行的cron作业.

这些cron作业由第三方模块配置,不属于Magento的核心.

一组作业处理从Magento到仓库管理系统的数据文件的导出和导入,有时cron作业会陷入某种循环,并且只需要几分钟就可以处理数小时.

我想以某种方式监视这些作业所花费的时间,但不修改每个脚本本身.也许是某种观察者,如果这样的话有可能吗?

有任何想法吗?

解决方法:

构建一个脚本,该脚本执行从cron_schedule表创建的格式化表.

我知道关于发布链接的常见事情,但MagentoCommerce.com可能不会很快消失,并且在这里获取代码发布是皇家PITA. So here’s the link to a PHP script that reads cron_schedule and creates a full report.参见底部代码.进入系统配置cron设置并告诉它保存信息24小时.

您现在可以看到正在计划的所有内容以及已执行的所有内容,如以下输出示例中所示.

对于链接上的MageBayvaporation感到抱歉,我试图将最重要的东西移到这里,但错过了这个.幸运的是,它仍然在其中一个网站上运行.

<?PHP

/******************************************************
 * Magento Log File Contents Monitor.
 * Released under the Digital damnation copyright
 * Free to do whatever the 7734 you want to do with it.
 * provided without warranty or support
 ******************************************************/

/***********************
 * Scan Magento local.xml file for connection information
 * Run out of password protected scripts/ directory
 ***********************/

if (file_exists('../app/etc/local.xml')) {

$xml = simplexml_load_file('../app/etc/local.xml', NULL, LIBXML_NOCDATA);

$db['host'] = $xml->global->resources->default_setup->connection->host;
$db['name'] = $xml->global->resources->default_setup->connection->dbname;
$db['user'] = $xml->global->resources->default_setup->connection->username;
$db['pass'] = $xml->global->resources->default_setup->connection->password;
$db['pref'] = $xml->global->resources->db->table_prefix;

$tables = array(
   'dataflow_batch_export',
   'dataflow_batch_import',
   'log_customer',
   'log_quote',
   'log_summary',
   'log_summary_type',
   'log_url',
   'log_url_info',
   'log_visitor',
   'log_visitor_info',
   'log_visitor_online',
   'catalog_compare_item',
   'report_event',
   'report_compared_product_index',
   'report_viewed_product_index',
   'sales_flat_quote',
   'sales_flat_quote_address',
   'sales_flat_quote_address_item',
   'sales_flat_quote_item',
   'sales_flat_quote_item_option',
   'sales_flat_quote_payment',
   'sales_flat_quote_shipping_rate'
);

} 

else {
    exit('Failed to open ../app/etc/local.xml');
}

/** Get current date, time, UTC and offset **/

$date   = date("Y-m-d");
$time   = date("H:i:s T");
$offset = date("P");
$utc    = gmdate("H:i:s");

/***********************
 * Start HTML output
 ***********************/

echo '<html><head><title>Magento Log File Contents on ' . $date . ' ' . $time . '</title>
<Meta http-equiv="refresh" content="30">
<style type="text/css">html {width: 100%; font-family:  Arial,Helvetica, sans-serif;}
body {line-height:1.0em; font-size: 100%;}
table {border-spacing: 1px;}
th.stattitle {text-align: left; font-size: 100%; font-weight: bold; color: white; background-color: #101010;}
th {text-align: center; font-size: 90%; font-weight: bold; padding: 5px; border-bottom: 1px solid black; border-left: 1px solid black; }
td {font-size: 90%; padding: 4px; border-bottom: 1px solid black; border-left: 1px solid black;}
</style>
</head><body>';

/** Output title, connection info and cron job monitor runtime **/

echo '<h2>Magento Log File Contents Report</h2><h3>Connection: '.$db['user'].'@'.$db['host'].'&nbsp;&nbsp;&ndash;&nbsp;&nbsp;Database: ' . $db['name'] . '</h3>';
echo '<h3>Runtime: ' . $date . '&nbsp;&nbsp;&nbsp;' .$time . '&nbsp;&nbsp;&nbsp;' . $utc . ' UTC</h3>';
echo '<h4>Note: Your timezone offset is ' . $offset . ' hours from UTC</h4>';

/** Connect to database **/

$conn = MysqL_connect($db['host'],$db['user'],$db['pass']);
@MysqL_select_db($db['name']) or die(MysqL_error());

/***********************
 * Get table record counts
 ***********************/

echo '<table><tbody><tr><th class="stattitle" colspan="2">Log Tables</th></tr>';
echo '<tr><th>Table</th><th>Row Count</th></tr>';

foreach($tables as $tblname) {
   $result  = MysqL_query('SELECT COUNT(*) FROM ' . $db['pref'] . $tblname) or die(MysqL_error());
   $numrows = MysqL_fetch_array($result);
   $num     = $numrows[0];

   /* Table output */
   echo '<tr>';
   echo '<td>'.$db['pref'].$tblname.'</td>';
   echo '<td align="right">'.$num.'</td>'; 
   echo '</tr>';                 
}

echo '</tbody></table></body></html>';

/***********************
 * End of report
 ***********************/

MysqL_close($conn);
?> 

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...