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,9 +546,11 @@ class Event {
}
$filters = array();
$result = dbQuery($sql, $values);
$results = $result->fetchALL();
foreach ( $results as $row ) {
$filters[] = new Event($row);
if ( $result ) {
$results = $result->fetchALL();
foreach ( $results as $row ) {
$filters[] = new Event($row);
}
}
return $filters;
}

View File

@ -1909,23 +1909,24 @@ function logState() {
# 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';
$counts = dbFetchAll( $sql );
foreach ( $counts as $count ) {
if ( $count['Level'] <= Logger::PANIC )
$count['Level'] = Logger::FATAL;
if ( !($levelCount = $levelCounts[$count['Level']]) ) {
Error( "Unexpected Log level ".$count['Level'] );
next;
}
if ( $levelCount[1] && $count['LevelCount'] >= $levelCount[1] ) {
$state = 'alarm';
break;
} elseif ( $levelCount[0] && $count['LevelCount'] >= $levelCount[0] ) {
$state = 'alert';
$counts = dbFetchAll($sql);
if ( $counts ) {
foreach ( $counts as $count ) {
if ( $count['Level'] <= Logger::PANIC )
$count['Level'] = Logger::FATAL;
if ( !($levelCount = $levelCounts[$count['Level']]) ) {
Error('Unexpected Log level '.$count['Level']);
next;
}
if ( $levelCount[1] && $count['LevelCount'] >= $levelCount[1] ) {
$state = 'alarm';
break;
} elseif ( $levelCount[0] && $count['LevelCount'] >= $levelCount[0] ) {
$state = 'alert';
}
}
}
return( $state );
return $state;
}
function isVector ( &$array ) {

View File

@ -345,7 +345,7 @@ if ($reload == 'reload') ob_start();
<?php
$connections = dbFetchOne( "SHOW status WHERE variable_name='threads_connected'", '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>';
?>
<li><?php echo translate('Storage') ?>: