active_admin-elastic_stats 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 763998393f5dc904dc77a6a473f53ea7f09e16e2123c97b494dd157bb88038b9
4
- data.tar.gz: 6020acaf7fe77b1a339a36be487bf7a66ea197880f2ebad29edd5f5f95d6688a
3
+ metadata.gz: fe16bb7401c036b8fa5b6168ec17d7bc2958ea6c7fe51996a78dfd88a0b9d769
4
+ data.tar.gz: b85594c3137616edceffc4c355783cd766c54dbf9dd16ed643f5475ec361fd5a
5
5
  SHA512:
6
- metadata.gz: d4940dbf86064b815ed2c1fe88839a45b54f43e6d8e49a0d4f6056126293849871017d993aa81bb6c13bbe53cd48d9223879304a3125e250e32879ce4538324c
7
- data.tar.gz: ac9bd76a9b2e96b057efb7ff15ee23fa7a31eb0fbe2fa263a1742358112b2b19cf76c7d77a5cf6a6e1f288158db796aa096030b57ad2d553e178065d32be1f88
6
+ metadata.gz: 5fda4a760d9744ef35d4ab3d2271d8f47e8e374158bcfe3ba3b250e83265aa427d621727eb11e9d658e81c88319155e4b064c6c111122278e1aa22c6fa37e6f9
7
+ data.tar.gz: dff303f81bcfdba6e9c2749719654651959474d73b744146527e1fbc69c653905eceaaa97ce0d9b58eb359ef23ab2af3fd5c93492c562b7b285dc2f1e1692cc4
@@ -0,0 +1,68 @@
1
+ module ActiveAdmin
2
+ class ElasticStats < Arbre::Component
3
+ builder_method :active_admin_elastic_stats
4
+
5
+ CONTAINER_STYLE = 'display: flex; justify-content: center; align-items: center;'
6
+ VALUE_STYLE = 'display: flex; flex:1; justify-content: center; align-items: center; flex-direction: column; align-self: baseline; text-align: center;'
7
+
8
+ def build(model, attributes = {})
9
+ super(attributes)
10
+
11
+ index_name = model.index_name
12
+ panel("Elastic #{index_name.titleize} Stats") do
13
+ div(style: CONTAINER_STYLE) do
14
+ begin
15
+ if Elasticsearch::Model.client.indices.exists(index: index_name)
16
+ build_fields(index_name)
17
+ else
18
+ show_error(index_name)
19
+ end
20
+ rescue Faraday::ConnectionFailed => e
21
+ h2 e.message
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def build_fields(index_name)
30
+ stats = JSON.parse(Elasticsearch::Model.client.indices.stats(index: index_name).to_json)
31
+
32
+ primaries = stats.dig('_all', 'primaries')
33
+
34
+ {
35
+ document_count: primaries.dig('docs', 'count'),
36
+ size: number_to_human_size(primaries.dig('store', 'size_in_bytes')),
37
+ index_time: primaries.dig('indexing', 'index_time_in_millis').to_s + ' ms',
38
+ search_time: average_search_time(primaries),
39
+ fetch_time: average_fetch_time(primaries)
40
+ }.each do |name, value|
41
+ div style: VALUE_STYLE do
42
+ h1 value
43
+ span name.to_s.titleize
44
+ end
45
+ end
46
+ rescue => e
47
+ div { h3 e.message }
48
+ end
49
+
50
+ def average_search_time(primaries)
51
+ total = primaries.dig('search', 'query_total')
52
+ return 'N/A' if total.zero?
53
+ average = primaries.dig('search', 'query_time_in_millis').to_f / total
54
+ "#{average.round(2)} ms"
55
+ end
56
+
57
+ def average_fetch_time(primaries)
58
+ total = primaries.dig('search', 'fetch_total')
59
+ return 'N/A' if total.zero?
60
+ average = primaries.dig('search', 'fetch_time_in_millis').to_f / total
61
+ "#{average.round(2)} ms"
62
+ end
63
+
64
+ def show_error(index_name)
65
+ h2 "Index #{index_name} does not exist"
66
+ end
67
+ end
68
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_admin-elastic_stats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Datarade
@@ -45,6 +45,7 @@ extensions: []
45
45
  extra_rdoc_files: []
46
46
  files:
47
47
  - lib/active_admin-elastic_stats.rb
48
+ - lib/active_admin/elastic_stats.rb
48
49
  homepage:
49
50
  licenses: []
50
51
  metadata: {}