diff --git a/config.php.in b/config.php.in index 761e365d..71bbe68e 100644 --- a/config.php.in +++ b/config.php.in @@ -462,7 +462,8 @@ define('QSHAPE_DEFERRED_SENDER', DIR_STAT . '/deferred-sender'); define('CPUSTAT', DIR_STAT . '/cpu.stat'); define('AD_SYNC_STAT', DIR_STAT . '/adsync.stat'); 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('SEARCH_HELPER_URL', SITE_URL . 'search-helper.php'); diff --git a/util/indexer.main.sh.in b/util/indexer.main.sh.in index 3561fb5a..06ee3b21 100755 --- a/util/indexer.main.sh.in +++ b/util/indexer.main.sh.in @@ -22,6 +22,16 @@ finish() { 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 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" -sum=0 -while read -r a b; do - 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 +get_index_size "main*.sp[dp]" > /var/piler/stat/total_index_size +get_index_size "${MAIN_INDEX}*.sp[dp]" > /var/piler/stat/current_main_index_size diff --git a/webui/model/health/health.php b/webui/model/health/health.php index 17e1b27d..71a67ec2 100644 --- a/webui/model/health/health.php +++ b/webui/model/health/health.php @@ -31,7 +31,8 @@ class ModelHealthHealth extends Model { $this->data['indexer_stat'] = $this->indexer_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_size_values($archivesizeraw); @@ -83,7 +84,7 @@ class ModelHealthHealth extends Model { $averagesqlsizeraw = $this->get_database_size() / $this->data['counters']['rcvd']; //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 @@ -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() { $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; - if(file_exists(SPHINX_MAIN_INDEX_SIZE)) { - $size = (int) file_get_contents(SPHINX_MAIN_INDEX_SIZE); + if(file_exists($statfile)) { + $size = (int) file_get_contents($statfile); } return $size; diff --git a/webui/view/theme/default/templates/health/worker.tpl b/webui/view/theme/default/templates/health/worker.tpl index 88c52a61..cb94c759 100644 --- a/webui/view/theme/default/templates/health/worker.tpl +++ b/webui/view/theme/default/templates/health/worker.tpl @@ -156,14 +156,14 @@ 0) { print $text_usage_increasing; } elseif($health['usagetrend'] < 0) { print $text_usage_decreasing; } else { print $text_usage_neutral; } ?> - Sphinx main index - SPHINX_MAIN_INDEX_THRESHOLD) { ?> class="text-error"> + Sphinx main (total) index + SPHINX_MAIN_INDEX_THRESHOLD) { ?> class="text-error"> () - - - - - + + + + +