Refactored daily report script

Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
Janos SUTO 2020-03-14 13:36:12 +01:00
parent b8891360cc
commit 54a8be6b22
2 changed files with 39 additions and 99 deletions

View File

@ -3,9 +3,6 @@
$webuidir = ""; $webuidir = "";
$verbose = 0; $verbose = 0;
$archivesizeraw = $sqlsizeraw = $sphinxsizeraw = 0;
$averagemessagesweekraw = $averagemessagesmonthraw = $averagemessagesizeraw = $averagesizedayraw = $averagesqlsizeraw = $averagesphinxsizeraw = 0;
ini_set("session.save_path", "/tmp"); ini_set("session.save_path", "/tmp");
$_SERVER['HTTP_USER_AGENT'] = "daily/cron"; $_SERVER['HTTP_USER_AGENT'] = "daily/cron";
@ -99,66 +96,9 @@ $counter = new ModelStatCounter();
$mail = new ModelMailMail(); $mail = new ModelMailMail();
foreach (Registry::get('health_smtp_servers') as $smtp) { $health->collect_data();
$_health[] = $health->checksmtp($smtp, $text_error); $health = $health->data;
}
$processed_emails = $health->count_processed_emails();
list ($uptime, $cpuload) = $health->uptime();
$x = exec(CPU_USAGE_COMMAND);
$cpuinfo = 100 - (int)$x;
list($totalmem, $meminfo, $totalswap, $swapinfo) = $health->meminfo();
$shortdiskinfo = $health->diskinfo();
list($archivesizeraw, $archivesizestored, $counters) = $counter->get_counters();
$archive_size = nice_size($archivesizeraw, ' ');
$sysinfo = $health->sysinfo();
$options = $health->get_options();
$averagemessagesizeraw = $averagesqlsizeraw = $averagesphinxsizeraw = $daysleftatcurrentrate = 0;
/* these next counters are for projecting space */
$averagemessagesweekraw = 0;
$averagemessagesmonthraw = 0;
if($counters['rcvd'] > 0) {
$averagemessagesizeraw = $archivesizeraw / $counters['rcvd'];
$averagesqlsizeraw = $sqlsizeraw / $counters['rcvd'];
$averagesphinxsizeraw = $sphinxsizeraw / $counters['rcvd'];
}
$averagesizedayraw = ($averagemessagesizeraw+$averagesqlsizeraw+$averagesphinxsizeraw) * $averagemessagesweekraw;
$datapart = 0;
foreach($shortdiskinfo as $part) {
if( $part['partition'] == DATA_PARTITION ) { $datapart = $part['freespace']*1024; }
}
$averagemessages = round($averagemessagesweekraw); // average of messages over the past week
$averagemessagesize = nice_size($averagemessagesizeraw,' '); // average message size on disk
$averagesqlsize = nice_size($averagesqlsizeraw,' '); // average metadata size in sql
$averagesphinxsize = nice_size($averagesphinxsizeraw,' '); // average sphinx index
$averagesizeday = nice_size($averagesizedayraw,' '); // average size per day
if($averagesizedayraw > 0) {
$daysleftatcurrentrate = convert_days_ymd($datapart / $averagesizedayraw); // number of days of free space left
}
if ( $averagemessagesweekraw > $averagemessagesmonthraw ) {
$usagetrend = 1;
} elseif( $averagemessagesweekraw < $averagemessagesmonthraw ) {
$usagetrend = -1;
} else {
$usagetrend = 0;
}
/* start email message */
$msg = "From: " . SMTP_FROMADDR . EOL; $msg = "From: " . SMTP_FROMADDR . EOL;
$msg .= "To: " . ADMIN_EMAIL . EOL; $msg .= "To: " . ADMIN_EMAIL . EOL;

View File

@ -32,28 +32,28 @@
<div class="row"> <div class="row">
<div class="cellhealthleft"><?php print $text_server_name; ?>:</div> <div class="cellhealthleft"><?php print $text_server_name; ?>:</div>
<div class="cellhealthright"><?php print $sysinfo[0]; ?></div> <div class="cellhealthright"><?php print $health['sysinfo'][0]; ?></div>
</div> </div>
<div class="row"> <div class="row">
<div class="cellhealthleft"><?php print $text_server_operating_system; ?>:</div> <div class="cellhealthleft"><?php print $text_server_operating_system; ?>:</div>
<div class="cellhealthright"><?php print $sysinfo[1]; ?></div> <div class="cellhealthright"><?php print $health['sysinfo'][1]; ?></div>
</div> </div>
<div class="row"> <div class="row">
<div class="cellhealthleft"><?php print $text_uptime; ?>:</div> <div class="cellhealthleft"><?php print $text_uptime; ?>:</div>
<div class="cellhealthright"><?php print $uptime; ?></div> <div class="cellhealthright"><?php print $health['uptime']; ?></div>
</div> </div>
<div class="row"> <div class="row">
<div class="cellhealthleft"><?php print $text_archive_size_before_compression; ?>:</div> <div class="cellhealthleft"><?php print $text_archive_size_before_compression; ?>:</div>
<div class="cellhealthright"><?php print $archive_size; ?>B</div> <div class="cellhealthright"><?php print $health['archive_size']; ?>B</div>
</div> </div>
<div class="row"> <div class="row">
<div class="cellhealthleft"><?php print $text_smtp_status; ?>:</div> <div class="cellhealthleft"><?php print $text_smtp_status; ?>:</div>
<div class="cellhealthright"> <div class="cellhealthright">
<?php foreach($_health as $h) { <?php foreach($health['health'] as $h) {
if(preg_match("/^220/", $h[1])) { if(preg_match("/^220/", $h[1])) {
$status = 'OK'; $class = 'ok'; $status = 'OK'; $class = 'ok';
} else { } else {
@ -68,37 +68,37 @@
<div class="row"> <div class="row">
<div class="cellhealthleft"><?php print $text_processed_emails; ?>:</div> <div class="cellhealthleft"><?php print $text_processed_emails; ?>:</div>
<div class="cellhealthright"><?php print $processed_emails['last_60_mins_count']; ?> (<?php print $text_60_minutes; ?>)<br /><?php print $processed_emails['today_count']; ?> (<?php print $text_24_hours; ?>)<br /><?php print $processed_emails['last_7_days_count']; ?> (<?php print $text_1_week; ?>)<br /><?php print $processed_emails['last_30_days_count']; ?> (<?php print $text_30_days; ?>)</div> <div class="cellhealthright"><?php print $health['processed_emails']['last_60_mins_count']; ?> (<?php print $text_60_minutes; ?>)<br /><?php print $health['processed_emails']['today_count']; ?> (<?php print $text_24_hours; ?>)<br /><?php print $health['processed_emails']['last_7_days_count']; ?> (<?php print $text_1_week; ?>)<br /><?php print $health['processed_emails']['last_30_days_count']; ?> (<?php print $text_30_days; ?>)</div>
</div> </div>
<div class="row"> <div class="row">
<div class="cellhealthleft"><?php print $text_cpu_usage; ?>:</div> <div class="cellhealthleft"><?php print $text_cpu_usage; ?>:</div>
<div class="cellhealthright"><span class="<?php if($cpuinfo < HEALTH_RATIO) { ?>ok<?php } else { ?>error<?php } ?>"><?php print $cpuinfo; ?>% <?php print $cpuload; ?></span></div> <div class="cellhealthright"><span class="<?php if($health['cpuinfo'] < HEALTH_RATIO) { ?>ok<?php } else { ?>error<?php } ?>"><?php print $health['cpuinfo']; ?>% <?php print $health['cpuload']; ?></span></div>
</div> </div>
<div class="row"> <div class="row">
<div class="cellhealthleft"><?php print $text_memory_usage; ?>:</div> <div class="cellhealthleft"><?php print $text_memory_usage; ?>:</div>
<div class="cellhealthright"><span class="<?php if($meminfo < HEALTH_RATIO) { ?>ok<?php } else { ?>error<?php } ?>"><?php print $meminfo; ?>% / <?php print $totalmem; ?> MB</span></div> <div class="cellhealthright"><span class="<?php if($health['meminfo'] < HEALTH_RATIO) { ?>ok<?php } else { ?>error<?php } ?>"><?php print $health['meminfo']; ?>% / <?php print $health['totalmem']; ?> MB</span></div>
</div> </div>
<div class="row"> <div class="row">
<div class="cellhealthleft"><?php print $text_swap_usage; ?></div> <div class="cellhealthleft"><?php print $text_swap_usage; ?></div>
<div class="cellhealthright"><span class="<?php if($swapinfo < HEALTH_RATIO) { ?>ok<?php } else { ?>error<?php } ?>"><?php print $swapinfo; ?>% / <?php print $totalswap; ?> MB</span></div> <div class="cellhealthright"><span class="<?php if($health['swapinfo'] < HEALTH_RATIO) { ?>ok<?php } else { ?>error<?php } ?>"><?php print $health['swapinfo']; ?>% / <?php print $health['totalswap']; ?> MB</span></div>
</div> </div>
<div class="row"> <div class="row">
<div class="cellhealthleft"><?php print $text_disk_usage; ?></div> <div class="cellhealthleft"><?php print $text_disk_usage; ?></div>
<div class="cellhealthright"><?php foreach($shortdiskinfo as $partition) { ?><span class="<?php if($partition['utilization'] < HEALTH_RATIO) { ?>ok<?php } else { ?>error<?php } ?>"><?php print $partition['partition']; ?> <?php print $partition['utilization']; ?>%</span> <?php } ?></div> <div class="cellhealthright"><?php foreach($health['shortdiskinfo'] as $partition) { ?><span class="<?php if($partition['utilization'] < HEALTH_RATIO) { ?>ok<?php } else { ?>error<?php } ?>"><?php print $partition['partition']; ?> <?php print $partition['utilization']; ?>%</span> <?php } ?></div>
</div> </div>
<div class="row"> <div class="row">
<div class="cellhealthleft"><?php print $text_space_projection; ?></div> <div class="cellhealthleft"><?php print $text_space_projection; ?></div>
<div class="cellhealthright"> <div class="cellhealthright">
<?php print $averagemessages; ?> (<?php print $text_average_messages_day; ?>)<br/> <?php print $health['averagemessages']; ?> (<?php print $text_average_messages_day; ?>)<br/>
<?php print $averagemessagesize; ?> + <?php print $averagesqlsize; ?> + <?php print $averagesphinxsize; ?> (<?php print $text_average_message_size; ?>)<br/> <?php print $health['averagemessagesize']; ?> + <?php print $health['averagesqlsize']; ?> + <?php print $health['averagesphinxsize']; ?> (<?php print $text_average_message_size; ?>)<br/>
<?php print $averagesizeday; ?> (<?php print $text_average_size_day; ?>)<br/> <?php print $health['averagesizeday']; ?> (<?php print $text_average_size_day; ?>)<br/>
<?php print $daysleftatcurrentrate[0]; ?> years, <?php print $daysleftatcurrentrate[1]; ?> months, <?php print $daysleftatcurrentrate[2]; ?> days ("<?php print DATA_PARTITION; ?>" <?php print $text_partition_full; ?>)<br/> <?php print $health['daysleftatcurrentrate'][0]; ?> years, <?php print $health['daysleftatcurrentrate'][1]; ?> months, <?php print $health['daysleftatcurrentrate'][2]; ?> days ("<?php print DATA_PARTITION; ?>" <?php print $text_partition_full; ?>)<br/>
<?php if ( $usagetrend > 0 ) { print $text_usage_increasing; } elseif( $usagetrend < 0 ) { print $text_usage_decreasing; } else { print $text_usage_neutral; } ?> (<?php print $text_usage_trend; ?>)<br/> <?php if ($health['usagetrend'] > 0) { print $text_usage_increasing; } elseif($health['usagetrend'] < 0) { print $text_usage_decreasing; } else { print $text_usage_neutral; } ?> (<?php print $text_usage_trend; ?>)<br/>
</div> </div>
</div> </div>