Improve behaviour and reduce extra logging when db goes away

This commit is contained in:
Isaac Connor 2018-10-29 09:59:26 -04:00
parent aaeb30a72f
commit 95a6d0666a
3 changed files with 22 additions and 19 deletions

View File

@ -546,10 +546,12 @@ class Event {
} }
$filters = array(); $filters = array();
$result = dbQuery($sql, $values); $result = dbQuery($sql, $values);
if ( $result ) {
$results = $result->fetchALL(); $results = $result->fetchALL();
foreach ( $results as $row ) { foreach ( $results as $row ) {
$filters[] = new Event($row); $filters[] = new Event($row);
} }
}
return $filters; return $filters;
} }

View File

@ -1910,12 +1910,12 @@ function logState() {
# This is an expensive request, as it has to hit every row of the Logs Table # This is an expensive request, as it has to hit every row of the Logs Table
$sql = 'SELECT Level, COUNT(Level) AS LevelCount FROM Logs WHERE Level < '.Logger::INFO.' AND TimeKey > unix_timestamp(now() - interval '.ZM_LOG_CHECK_PERIOD.' second) GROUP BY Level ORDER BY Level ASC'; $sql = 'SELECT Level, COUNT(Level) AS LevelCount FROM Logs WHERE Level < '.Logger::INFO.' AND TimeKey > unix_timestamp(now() - interval '.ZM_LOG_CHECK_PERIOD.' second) GROUP BY Level ORDER BY Level ASC';
$counts = dbFetchAll($sql); $counts = dbFetchAll($sql);
if ( $counts ) {
foreach ( $counts as $count ) { foreach ( $counts as $count ) {
if ( $count['Level'] <= Logger::PANIC ) if ( $count['Level'] <= Logger::PANIC )
$count['Level'] = Logger::FATAL; $count['Level'] = Logger::FATAL;
if ( !($levelCount = $levelCounts[$count['Level']]) ) { if ( !($levelCount = $levelCounts[$count['Level']]) ) {
Error( "Unexpected Log level ".$count['Level'] ); Error('Unexpected Log level '.$count['Level']);
next; next;
} }
if ( $levelCount[1] && $count['LevelCount'] >= $levelCount[1] ) { if ( $levelCount[1] && $count['LevelCount'] >= $levelCount[1] ) {
@ -1925,7 +1925,8 @@ function logState() {
$state = 'alert'; $state = 'alert';
} }
} }
return( $state ); }
return $state;
} }
function isVector ( &$array ) { function isVector ( &$array ) {

View File

@ -345,7 +345,7 @@ if ($reload == 'reload') ob_start();
<?php <?php
$connections = dbFetchOne( "SHOW status WHERE variable_name='threads_connected'", 'Value' ); $connections = dbFetchOne( "SHOW status WHERE variable_name='threads_connected'", 'Value' );
$max_connections = dbFetchOne( "SHOW variables WHERE variable_name='max_connections'", 'Value' ); $max_connections = dbFetchOne( "SHOW variables WHERE variable_name='max_connections'", 'Value' );
$percent_used = 100 * $connections / $max_connections; $percent_used = $max_connections ? 100 * $connections / $max_connections : 100;
echo '<li'. ( $percent_used > 90 ? ' class="warning"' : '' ).'>'.translate('DB').':'.$connections.'/'.$max_connections.'</li>'; echo '<li'. ( $percent_used > 90 ? ' class="warning"' : '' ).'>'.translate('DB').':'.$connections.'/'.$max_connections.'</li>';
?> ?>
<li><?php echo translate('Storage') ?>: <li><?php echo translate('Storage') ?>: