| 1 | #!/usr/local/bin/perl | ||
| 2 | # PODNAME: es-index-scan.pl | ||
| 3 | # ABSTRACT: Scan indexes for potential issues | ||
| 4 | use v5.16; | ||
| 5 | use warnings; | ||
| 6 | |||
| 7 | use App::ElasticSearch::Utilities qw(:all); | ||
| 8 | use CLI::Helpers qw(:output); | ||
| 9 | |||
| 10 | my $indexes = es_indices(check_dates => 0); | ||
| 11 | |||
| 12 | foreach my $idx ( sort @{ $indexes } ) { | ||
| 13 | next if $idx =~ /^[._]/; | ||
| 14 | my $age = es_index_days_old( $idx ); | ||
| 15 | my $result = es_request("/$idx/_stats"); | ||
| 16 | my $stats = $result->{indices}{$idx}{primaries}; | ||
| 17 | |||
| 18 | my $doc_size = es_human_count($stats->{docs}{count} || 0); | ||
| 19 | my $size = es_human_size($stats->{store}{size_in_bytes}); | ||
| 20 | output("checking $idx.. (age=${age}d, docs=$doc_size, size=$size)"); | ||
| 21 | |||
| 22 | my $segments = $stats->{segments}{count}; | ||
| 23 | my $shards = $stats->{shard_stats}{total_count} || $result->{_shards}{total}; | ||
| 24 | |||
| 25 | if( my $docs = $stats->{docs}{count} ) { | ||
| 26 | my $deleted = $stats->{docs}{deleted}; | ||
| 27 | output({indent=>1,color=>'blue'}, sprintf "%d of %d (%0.1f%%) documents deleted", | ||
| 28 | $deleted, $docs, ($deleted / $docs) * 100, | ||
| 29 | ) if $deleted; | ||
| 30 | } | ||
| 31 | else { | ||
| 32 | output({indent=>1,color=>'red'}, "no documents") | ||
| 33 | } | ||
| 34 | |||
| 35 | output({indent=>1,color=>'red'}, "More than one segment per shard: segments=$segments, shards=$shards") | ||
| 36 | if $age > 1 && $segments > $shards; | ||
| 37 | |||
| 38 | |||
| 39 | output({indent=>1,color=>'magenta'}, "index never queried") | ||
| 40 | unless $stats->{search}{query_total}; | ||
| 41 | |||
| 42 | output({indent=>1,color=>'yellow'}, "$stats->{indexing}{index_failed} index failures") | ||
| 43 | if $stats->{indexing}{index_failed}; | ||
| 44 | |||
| 45 | output({indent=>1,color=>'red'}, "indexing throttled") | ||
| 46 | if $stats->{indexing}{is_throttled}; | ||
| 47 | |||
| 48 | output({indent=>1,color=>'yellow'}, sprintf "%0.3fs of throttled indexing", $stats->{indexing}{throttle_time_in_millis} / 1000) | ||
| 49 | if $stats->{indexing}{throttle_time_in_millis}; | ||
| 50 | } | ||
| 51 | |||
| 52 | __END__ |