Skip to content

Commit

Permalink
Fixed index size display (jsuto#145)
Browse files Browse the repository at this point in the history
Signed-off-by: Janos SUTO <sj@acts.hu>
  • Loading branch information
jsuto authored Aug 10, 2024
1 parent 8cf96dc commit 5888da4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 25 deletions.
16 changes: 0 additions & 16 deletions util/indexer.main.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ set -o pipefail

MAINTMPFILE="/var/run/piler/main.indexer.tmp"
CONFIG_FILE="SYSCONFDIR/piler/sphinx.conf"
INDEXDIR=sphinx
PRIORITY="mail.info"
TOUCHFILE="/var/piler/stat/indexer"
MAIN_INDEX="main1"

if [[ -f SYSCONFDIR/piler/MANTICORE ]]; then
CONFIG_FILE=SYSCONFDIR/piler/manticore.conf
INDEXDIR=manticore
fi

export PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
Expand All @@ -22,17 +20,6 @@ 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"
exit 1
Expand All @@ -57,6 +44,3 @@ echo "INDEXER INFO: resetting daily delta started" | logger -p "$PRIORITY"
indexer --config "$CONFIG_FILE" --quiet dailydelta1 --rotate

echo "INDEXER INFO: resetting daily delta finished" | logger -p "$PRIORITY"

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
17 changes: 10 additions & 7 deletions webui/model/health/health.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public function collect_data() {
$this->data['indexer_stat'] = $this->indexer_stat();
$this->data['purge_stat'] = $this->purge_stat();

$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->data['sphinx_total_size'] = $this->get_index_size() ;

$this->get_average_count_values();
$this->get_average_size_values($archivesizeraw);
Expand Down Expand Up @@ -282,8 +281,8 @@ public function toggle_option($option = '') {
public function get_database_size() {
$data = array();

$query = $this->db->query("SELECT table_schema AS `name`,
SUM( data_length + index_length ) AS `size`
$query = $this->db->query("SELECT table_schema AS `name`,
SUM( data_length + index_length ) AS `size`
FROM information_schema.TABLES
WHERE table_schema = '".DB_DATABASE."'
GROUP BY table_schema;");
Expand Down Expand Up @@ -353,11 +352,15 @@ public function purge_stat() {
}


public function get_index_size($statfile = '') {
public function get_index_size() {
$size = 0;

if(file_exists($statfile)) {
$size = (int) file_get_contents($statfile);
$indexes = explode(',', SPHINX_MAIN_INDEX);
foreach($indexes as $index) {
$query = $this->sphx->query('SHOW INDEX ' . $index . ' STATUS LIKE \'disk_bytes\'');
foreach($query->rows as $row) {
$size += $row[1];
}
}

return $size;
Expand Down
4 changes: 2 additions & 2 deletions webui/templates/health/worker.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,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>
</tr>
<tr>
<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']); ?> (<?php print nice_size($health['sphinx_total_size']); ?>) </td>
<td>Sphinx total index</td>
<td><?php print nice_size($health['sphinx_total_size']); ?></td>
</tr>
</table>

Expand Down

0 comments on commit 5888da4

Please sign in to comment.