Fixed sphinx size display on health page #1255

Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
Janos SUTO 2023-01-29 14:06:15 +01:00
parent 4021d4687d
commit 0f7422e199
4 changed files with 27 additions and 43 deletions

View File

@ -462,7 +462,8 @@ define('QSHAPE_DEFERRED_SENDER', DIR_STAT . '/deferred-sender');
define('CPUSTAT', DIR_STAT . '/cpu.stat'); define('CPUSTAT', DIR_STAT . '/cpu.stat');
define('AD_SYNC_STAT', DIR_STAT . '/adsync.stat'); define('AD_SYNC_STAT', DIR_STAT . '/adsync.stat');
define('ARCHIVE_SIZE', DIR_STAT . '/archive.size'); define('ARCHIVE_SIZE', DIR_STAT . '/archive.size');
define('SPHINX_MAIN_INDEX_SIZE', DIR_STAT . '/main_index_size'); define('SPHINX_CURRENT_MAIN_INDEX_SIZE', DIR_STAT . '/current_main_index_size');
define('SPHINX_TOTAL_INDEX_SIZE', DIR_STAT . '/total_index_size');
define('LOCK_FILE', DIR_LOG . 'lock'); define('LOCK_FILE', DIR_LOG . 'lock');
define('SEARCH_HELPER_URL', SITE_URL . 'search-helper.php'); define('SEARCH_HELPER_URL', SITE_URL . 'search-helper.php');

View File

@ -22,6 +22,16 @@ finish() {
rm -f "$MAINTMPFILE" rm -f "$MAINTMPFILE"
} }
get_index_size() {
local mainfiles="$1"
local sum=0
# shellcheck disable=SC2034
while read -r a b; do
sum=$(( sum + b ))
done < <( find /var/piler/${INDEXDIR}/ -type f -name "$mainfiles" -printf "%TY%Tm%Td %s\\n" )
printf "%d" $sum
}
if [[ -f "$MAINTMPFILE" ]]; then if [[ -f "$MAINTMPFILE" ]]; then
echo "INDEXER ERROR: indexer merging to main index is already running. It started at $(cat "$MAINTMPFILE")" | logger -p "$PRIORITY" echo "INDEXER ERROR: indexer merging to main index is already running. It started at $(cat "$MAINTMPFILE")" | logger -p "$PRIORITY"
@ -48,8 +58,5 @@ indexer --config "$CONFIG_FILE" --quiet dailydelta1 --rotate
echo "INDEXER INFO: resetting daily delta finished" | logger -p "$PRIORITY" echo "INDEXER INFO: resetting daily delta finished" | logger -p "$PRIORITY"
sum=0 get_index_size "main*.sp[dp]" > /var/piler/stat/total_index_size
while read -r a b; do get_index_size "${MAIN_INDEX}*.sp[dp]" > /var/piler/stat/current_main_index_size
sum=$(( sum + b ))
done < <( find /var/piler/${INDEXDIR}/ -type f -name main\*.sp[dp] -printf "%TY%Tm%Td %s\\n" )
printf "%d" $sum > /var/piler/stat/main_index_size

View File

@ -31,7 +31,8 @@ class ModelHealthHealth extends Model {
$this->data['indexer_stat'] = $this->indexer_stat(); $this->data['indexer_stat'] = $this->indexer_stat();
$this->data['purge_stat'] = $this->purge_stat(); $this->data['purge_stat'] = $this->purge_stat();
$this->data['sphinx_current_main_size'] = $this->get_current_sphinx_main_index_size(); $this->data['sphinx_current_main_size'] = $this->get_index_size(SPHINX_CURRENT_MAIN_INDEX_SIZE);
$this->data['sphinx_total_size'] = $this->get_index_size(SPHINX_TOTAL_INDEX_SIZE);
$this->get_average_count_values(); $this->get_average_count_values();
$this->get_average_size_values($archivesizeraw); $this->get_average_size_values($archivesizeraw);
@ -83,7 +84,7 @@ class ModelHealthHealth extends Model {
$averagesqlsizeraw = $this->get_database_size() / $this->data['counters']['rcvd']; $averagesqlsizeraw = $this->get_database_size() / $this->data['counters']['rcvd'];
//average message sphinx index size, computed for total messages in database //average message sphinx index size, computed for total messages in database
$averagesphinxsizeraw = $this->get_sphinx_size() / $this->data['counters']['rcvd']; $averagesphinxsizeraw = $this->data['sphinx_total_size'] / $this->data['counters']['rcvd'];
} }
// average total message size per day, computed over the time period since the first email was archived // average total message size per day, computed over the time period since the first email was archived
@ -320,31 +321,6 @@ class ModelHealthHealth extends Model {
} }
public function get_sphinx_size($directory = DIR_SPHINX) {
$dirSize=0;
if(!$dh=opendir($directory)) {
return false;
}
while($file = readdir($dh)) {
if($file == "." || $file == "..") {
continue;
}
if(is_file($directory."/".$file)) {
$dirSize += filesize($directory."/".$file);
}
if(is_dir($directory."/".$file)) {
$dirSize += $this->get_sphinx_size($directory."/".$file);
}
}
closedir($dh);
return $dirSize;
}
public function indexer_stat() { public function indexer_stat() {
$data = array('', ''); $data = array('', '');
@ -377,11 +353,11 @@ class ModelHealthHealth extends Model {
} }
public function get_current_sphinx_main_index_size() { public function get_index_size($statfile = '') {
$size = 0; $size = 0;
if(file_exists(SPHINX_MAIN_INDEX_SIZE)) { if(file_exists($statfile)) {
$size = (int) file_get_contents(SPHINX_MAIN_INDEX_SIZE); $size = (int) file_get_contents($statfile);
} }
return $size; return $size;

View File

@ -156,8 +156,8 @@
<td><?php if ($health['usagetrend'] > 0) { print $text_usage_increasing; } elseif($health['usagetrend'] < 0) { print $text_usage_decreasing; } else { print $text_usage_neutral; } ?></td> <td><?php if ($health['usagetrend'] > 0) { print $text_usage_increasing; } elseif($health['usagetrend'] < 0) { print $text_usage_decreasing; } else { print $text_usage_neutral; } ?></td>
</tr> </tr>
<tr> <tr>
<td>Sphinx main index</td> <td>Sphinx main (total) index</td>
<td<?php if($health['sphinx_current_main_size'] > SPHINX_MAIN_INDEX_THRESHOLD) { ?> class="text-error"<?php } ?>><?php print nice_size($health['sphinx_current_main_size']); ?></td> <td<?php if($health['sphinx_current_main_size'] > SPHINX_MAIN_INDEX_THRESHOLD) { ?> class="text-error"<?php } ?>><?php print nice_size($health['sphinx_current_main_size']); ?> (<?php print nice_size($health['sphinx_total_size']); ?>) </td>
</tr> </tr>
</table> </table>