From 3171afc36a9472a0a027e3e2c7397c4dd880b703 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Fri, 6 Oct 2023 10:02:55 -0500 Subject: [PATCH] Add Elasticsearch index size to Admin dashboard (#27301) Co-authored-by: Claire --- .../dimension/space_usage_dimension.rb | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/lib/admin/metrics/dimension/space_usage_dimension.rb b/app/lib/admin/metrics/dimension/space_usage_dimension.rb index cc8560890..f1b6dba04 100644 --- a/app/lib/admin/metrics/dimension/space_usage_dimension.rb +++ b/app/lib/admin/metrics/dimension/space_usage_dimension.rb @@ -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