Add Elasticsearch index size to Admin dashboard (#27301)

Co-authored-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
Michael Stanclift 2023-10-06 10:02:55 -05:00 committed by GitHub
parent 340c390849
commit 3171afc36a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -11,7 +11,7 @@ class Admin::Metrics::Dimension::SpaceUsageDimension < Admin::Metrics::Dimension
protected
def perform_query
[postgresql_size, redis_size, media_size]
[postgresql_size, redis_size, media_size, search_size].compact
end
def postgresql_size
@ -65,4 +65,22 @@ class Admin::Metrics::Dimension::SpaceUsageDimension < Admin::Metrics::Dimension
redis.info
end
end
def search_size
return unless Chewy.enabled?
client_info = Chewy.client.info
value = Chewy.client.indices.stats['indices'].values.sum { |index_data| index_data['primaries']['store']['size_in_bytes'] }
{
key: 'search',
human_key: client_info.dig('version', 'distribution') == 'opensearch' ? 'OpenSearch' : 'Elasticsearch',
value: value.to_s,
unit: 'bytes',
human_value: number_to_human_size(value),
}
rescue Faraday::ConnectionFailed, Elasticsearch::Transport::Transport::Error
nil
end
end