Class: GraphQL::AnyCable::Stats
- Inherits:
-
Object
- Object
- GraphQL::AnyCable::Stats
- Defined in:
- lib/graphql/anycable/stats.rb
Overview
Calculates amount of Graphql Redis keys (graphql-subscription, graphql-fingerprints, graphql-subscriptions, graphql-channel) Also, calculate the number of subscribers grouped by subscriptions
Constant Summary collapse
- SCAN_COUNT_RECORDS_AMOUNT =
1_000
Instance Attribute Summary collapse
-
#include_subscriptions ⇒ Object
readonly
Returns the value of attribute include_subscriptions.
-
#scan_count ⇒ Object
readonly
Returns the value of attribute scan_count.
Instance Method Summary collapse
- #collect ⇒ Object
-
#initialize(scan_count: SCAN_COUNT_RECORDS_AMOUNT, include_subscriptions: false) ⇒ Stats
constructor
A new instance of Stats.
Constructor Details
#initialize(scan_count: SCAN_COUNT_RECORDS_AMOUNT, include_subscriptions: false) ⇒ Stats
Returns a new instance of Stats.
13 14 15 16 |
# File 'lib/graphql/anycable/stats.rb', line 13 def initialize(scan_count: SCAN_COUNT_RECORDS_AMOUNT, include_subscriptions: false) @scan_count = scan_count @include_subscriptions = include_subscriptions end |
Instance Attribute Details
#include_subscriptions ⇒ Object (readonly)
Returns the value of attribute include_subscriptions.
11 12 13 |
# File 'lib/graphql/anycable/stats.rb', line 11 def include_subscriptions @include_subscriptions end |
#scan_count ⇒ Object (readonly)
Returns the value of attribute scan_count.
11 12 13 |
# File 'lib/graphql/anycable/stats.rb', line 11 def scan_count @scan_count end |
Instance Method Details
#collect ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/graphql/anycable/stats.rb', line 18 def collect total_subscriptions_result = {total: {}} AnyCable.with_redis do |redis| list_prefixes_keys.each do |name, prefix| total_subscriptions_result[:total][name] = count_by_scan(redis, match: "#{prefix}*") end if include_subscriptions total_subscriptions_result[:subscriptions] = group_subscription_stats(redis) end end total_subscriptions_result end |