Class: Ably::Models::Stats
- Inherits:
-
Object
- Object
- Ably::Models::Stats
- Extended by:
- Ably::Modules::Enum
- Includes:
- Ably::Modules::ModelCommon
- Defined in:
- lib/ably/models/stats.rb,
lib/ably/models/stats_types.rb
Overview
A class representing an individual statistic for a specified #interval_id
Defined Under Namespace
Classes: ConnectionTypes, IntegerDefaultZero, MessageCount, MessageTraffic, MessageTypes, RequestCount, ResourceCount, StatsStruct
Constant Summary collapse
- GRANULARITY =
Describes the interval unit over which statistics are gathered.
MINUTE Interval unit over which statistics are gathered as minutes. HOUR Interval unit over which statistics are gathered as hours. DAY Interval unit over which statistics are gathered as days. MONTH Interval unit over which statistics are gathered as months.
ruby_enum('GRANULARITY', :minute, :hour, :day, :month )
- INTERVAL_FORMAT_STRING =
[ '%Y-%m-%d:%H:%M', '%Y-%m-%d:%H', '%Y-%m-%d', '%Y-%m' ]
Instance Attribute Summary
Attributes included from Ably::Modules::ModelCommon
Class Method Summary collapse
-
.from_interval_id(interval_id) ⇒ Time
Returns the UTC 0 start Time of an interval_id.
-
.granularity_from_interval_id(interval_id) ⇒ Symbol
Returns the Symbol determined from the interval_id.
-
.to_interval_id(time, granularity) ⇒ String
Convert a Time with the specified Granularity into an interval ID based on UTC 0 time.
Instance Method Summary collapse
-
#all ⇒ Stats::MessageTypes
A MessageTypes object containing the aggregate count of all message stats.
-
#api_requests ⇒ Ably::Models::Stats::RequestCount
A RequestCount object containing a breakdown of API Requests.
- #as_json(*args) ⇒ Object
- #attributes ⇒ Object
-
#channels ⇒ Ably::Models::Stats::ResourceCount
A ResourceCount object containing a breakdown of connection related stats, such as min, mean and peak connections.
-
#connections ⇒ Ably::Models::Stats::ConnectionTypes
A ConnectionTypes object containing a breakdown of connection related stats, such as min, mean and peak connections.
-
#inbound ⇒ Ably::Models::Stats::MessageTraffic
A MessageTraffic object containing the aggregate count of inbound message stats.
-
#initialize(hash_object) ⇒ Stats
constructor
Stats initializer.
-
#interval_granularity ⇒ GRANULARITY
The length of the interval the stats span.
-
#interval_id ⇒ String
The UTC time at which the time period covered begins.
-
#interval_time ⇒ Time
Represents the intervalId as a time object.
-
#outbound ⇒ Ably::Models::Stats::MessageTraffic
A MessageTraffic object containing the aggregate count of outbound message stats.
-
#persisted ⇒ Ably::Models::Stats::MessageTraffic
A MessageTraffic object containing the aggregate count of persisted message stats.
-
#token_requests ⇒ Ably::Models::Stats::RequestCount
A RequestCount object containing a breakdown of Ably Token requests.
Methods included from Ably::Modules::ModelCommon
#==, #[], included, #to_json, #to_s
Methods included from Ably::Modules::MessagePack
Constructor Details
#initialize(hash_object) ⇒ Stats
Ably::Models::Stats initializer
108 109 110 111 |
# File 'lib/ably/models/stats.rb', line 108 def initialize(hash_object) @raw_hash_object = hash_object set_attributes_object hash_object end |
Class Method Details
.from_interval_id(interval_id) ⇒ Time
Returns the UTC 0 start Time of an interval_id
72 73 74 75 76 77 78 79 |
# File 'lib/ably/models/stats.rb', line 72 def from_interval_id(interval_id) raise ArgumentError, 'Interval ID must be a string' unless interval_id.kind_of?(String) format = INTERVAL_FORMAT_STRING.find { |fmt| expected_length(fmt) == interval_id.length } raise ArgumentError, 'Interval ID is an invalid length' unless format Time.strptime("#{interval_id} +0000", "#{format} %z").utc end |
.granularity_from_interval_id(interval_id) ⇒ Symbol
Returns the Symbol determined from the interval_id
89 90 91 92 93 94 95 96 |
# File 'lib/ably/models/stats.rb', line 89 def granularity_from_interval_id(interval_id) raise ArgumentError, 'Interval ID must be a string' unless interval_id.kind_of?(String) format = INTERVAL_FORMAT_STRING.find { |fmt| expected_length(fmt) == interval_id.length } raise ArgumentError, 'Interval ID is an invalid length' unless format GRANULARITY[INTERVAL_FORMAT_STRING.index(format)] end |
.to_interval_id(time, granularity) ⇒ String
Convert a Time with the specified Granularity into an interval ID based on UTC 0 time
55 56 57 58 59 60 61 62 |
# File 'lib/ably/models/stats.rb', line 55 def to_interval_id(time, granularity) raise ArgumentError, 'Time object required as first argument' unless time.kind_of?(Time) granularity = GRANULARITY(granularity) format = INTERVAL_FORMAT_STRING[granularity.to_i] time.utc.strftime(format) end |
Instance Method Details
#all ⇒ Stats::MessageTypes
A MessageTypes object containing the aggregate count of all message stats.
119 120 121 |
# File 'lib/ably/models/stats.rb', line 119 def all @all ||= Stats::MessageTypes.new(attributes[:all]) end |
#api_requests ⇒ Ably::Models::Stats::RequestCount
A RequestCount object containing a breakdown of API Requests.
179 180 181 |
# File 'lib/ably/models/stats.rb', line 179 def api_requests @api_requests ||= Stats::RequestCount.new(attributes[:api_requests]) end |
#as_json(*args) ⇒ Object
229 230 231 |
# File 'lib/ably/models/stats.rb', line 229 def as_json(*args) attributes.as_json(*args).reject { |key, val| val.nil? } end |
#attributes ⇒ Object
225 226 227 |
# File 'lib/ably/models/stats.rb', line 225 def attributes @attributes end |
#channels ⇒ Ably::Models::Stats::ResourceCount
A ResourceCount object containing a breakdown of connection related stats, such as min, mean and peak connections.
169 170 171 |
# File 'lib/ably/models/stats.rb', line 169 def channels @channels ||= Stats::ResourceCount.new(attributes[:channels]) end |
#connections ⇒ Ably::Models::Stats::ConnectionTypes
A ConnectionTypes object containing a breakdown of connection related stats, such as min, mean and peak connections.
159 160 161 |
# File 'lib/ably/models/stats.rb', line 159 def connections @connections ||= Stats::ConnectionTypes.new(attributes[:connections]) end |
#inbound ⇒ Ably::Models::Stats::MessageTraffic
A MessageTraffic object containing the aggregate count of inbound message stats.
129 130 131 |
# File 'lib/ably/models/stats.rb', line 129 def inbound @inbound ||= Stats::MessageTraffic.new(attributes[:inbound]) end |
#interval_granularity ⇒ GRANULARITY
The length of the interval the stats span. Values will be a [StatsIntervalGranularity]StatsIntervalGranularity.
221 222 223 |
# File 'lib/ably/models/stats.rb', line 221 def interval_granularity self.class.granularity_from_interval_id(interval_id) end |
#interval_id ⇒ String
The UTC time at which the time period covered begins. If unit is set to minute this will be in the format YYYY-mm-dd:HH:MM, if hour it will be YYYY-mm-dd:HH, if day it will be YYYY-mm-dd:00 and if month it will be YYYY-mm-01:00.
201 202 203 |
# File 'lib/ably/models/stats.rb', line 201 def interval_id attributes.fetch(:interval_id) end |
#interval_time ⇒ Time
Represents the intervalId as a time object.
211 212 213 |
# File 'lib/ably/models/stats.rb', line 211 def interval_time self.class.from_interval_id(interval_id) end |
#outbound ⇒ Ably::Models::Stats::MessageTraffic
A MessageTraffic object containing the aggregate count of outbound message stats.
139 140 141 |
# File 'lib/ably/models/stats.rb', line 139 def outbound @outbound ||= Stats::MessageTraffic.new(attributes[:outbound]) end |
#persisted ⇒ Ably::Models::Stats::MessageTraffic
A MessageTraffic object containing the aggregate count of persisted message stats.
149 150 151 |
# File 'lib/ably/models/stats.rb', line 149 def persisted @persisted ||= Stats::MessageTypes.new(attributes[:persisted]) end |
#token_requests ⇒ Ably::Models::Stats::RequestCount
A RequestCount object containing a breakdown of Ably Token requests.
189 190 191 |
# File 'lib/ably/models/stats.rb', line 189 def token_requests @token_requests ||= Stats::RequestCount.new(attributes[:token_requests]) end |