Class: OpenC3::MetricModel
- Inherits:
-
EphemeralModel
- Object
- Model
- EphemeralModel
- OpenC3::MetricModel
- Defined in:
- lib/openc3/models/metric_model.rb
Constant Summary collapse
- PRIMARY_KEY =
'__openc3__metric'.freeze
Instance Attribute Summary collapse
-
#values ⇒ Object
Returns the value of attribute values.
Attributes inherited from Model
#name, #plugin, #scope, #updated_at
Class Method Summary collapse
- .all(scope:) ⇒ Object
- .destroy(scope:, name:) ⇒ Object
-
.get(name:, scope:) ⇒ Object
NOTE: The following three class methods are used by the ModelController and are reimplemented to enable various Model class methods to work.
- .names(scope:) ⇒ Object
- .redis_extract_p50_and_p99_seconds(value) ⇒ Object
- .redis_metrics ⇒ Object
-
.set(json, scope:, queued: true) ⇒ Object
Sets (updates) the redis hash of this model Queued defaults to true for MetricModel.
Instance Method Summary collapse
- #as_json(*a) ⇒ Object
-
#initialize(name:, values: {}, scope:) ⇒ MetricModel
constructor
A new instance of MetricModel.
Methods inherited from EphemeralModel
Methods inherited from Model
#check_disable_erb, #create, #deploy, #destroy, #destroyed?, filter, find_all_by_plugin, from_json, get_all_models, get_model, handle_config, store, store_queued, #undeploy, #update
Constructor Details
#initialize(name:, values: {}, scope:) ⇒ MetricModel
Returns a new instance of MetricModel.
57 58 59 60 |
# File 'lib/openc3/models/metric_model.rb', line 57 def initialize(name:, values: {}, scope:) super("#{scope}#{PRIMARY_KEY}", name: name, scope: scope) @values = values end |
Instance Attribute Details
#values ⇒ Object
Returns the value of attribute values.
29 30 31 |
# File 'lib/openc3/models/metric_model.rb', line 29 def values @values end |
Class Method Details
.all(scope:) ⇒ Object
41 42 43 |
# File 'lib/openc3/models/metric_model.rb', line 41 def self.all(scope:) super("#{scope}#{PRIMARY_KEY}") end |
.destroy(scope:, name:) ⇒ Object
53 54 55 |
# File 'lib/openc3/models/metric_model.rb', line 53 def self.destroy(scope:, name:) EphemeralStore.hdel("#{scope}#{PRIMARY_KEY}", name) end |
.get(name:, scope:) ⇒ Object
NOTE: The following three class methods are used by the ModelController and are reimplemented to enable various Model class methods to work
33 34 35 |
# File 'lib/openc3/models/metric_model.rb', line 33 def self.get(name:, scope:) super("#{scope}#{PRIMARY_KEY}", name: name) end |
.names(scope:) ⇒ Object
37 38 39 |
# File 'lib/openc3/models/metric_model.rb', line 37 def self.names(scope:) super("#{scope}#{PRIMARY_KEY}") end |
.redis_extract_p50_and_p99_seconds(value) ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/openc3/models/metric_model.rb', line 70 def self.redis_extract_p50_and_p99_seconds(value) if value split_value = value.to_s.split(',') p50 = split_value[0].split('=')[-1].to_f / 1_000_000 p99 = split_value[-1].split('=')[-1].to_f / 1_000_000 return p50, p99 else return 0.0, 0.0 end end |
.redis_metrics ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/openc3/models/metric_model.rb', line 81 def self.redis_metrics result = {} metrics = OpenC3::Store.info("all") result['redis_connected_clients_total'] = metrics['connected_clients'] result['redis_used_memory_rss_total'] = metrics['used_memory_rss'] result['redis_commands_processed_total'] = metrics['total_commands_processed'] result['redis_iops'] = metrics['instantaneous_ops_per_sec'] result['redis_instantaneous_input_kbps'] = metrics['instantaneous_input_kbps'] result['redis_instantaneous_output_kbps'] = metrics['instantaneous_output_kbps'] result['redis_hget_p50_seconds'], result['redis_hget_p99_seconds'] = redis_extract_p50_and_p99_seconds(metrics['latency_percentiles_usec_hget']) result['redis_hgetall_p50_seconds'], result['redis_hgetall_p99_seconds'] = redis_extract_p50_and_p99_seconds(metrics['latency_percentiles_usec_hgetall']) result['redis_hset_p50_seconds'], result['redis_hset_p99_seconds'] = redis_extract_p50_and_p99_seconds(metrics['latency_percentiles_usec_hset']) result['redis_xadd_p50_seconds'], result['redis_xadd_p99_seconds'] = redis_extract_p50_and_p99_seconds(metrics['latency_percentiles_usec_xadd']) result['redis_xread_p50_seconds'], result['redis_xread_p99_seconds'] = redis_extract_p50_and_p99_seconds(metrics['latency_percentiles_usec_xread']) result['redis_xrevrange_p50_seconds'], result['redis_xrevrange_p99_seconds'] = redis_extract_p50_and_p99_seconds(metrics['latency_percentiles_usec_xrevrange']) result['redis_xtrim_p50_seconds'], result['redis_xtrim_p99_seconds'] = redis_extract_p50_and_p99_seconds(metrics['latency_percentiles_usec_xtrim']) metrics = OpenC3::EphemeralStore.info("all") result['redis_ephemeral_connected_clients_total'] = metrics['connected_clients'] result['redis_ephemeral_used_memory_rss_total'] = metrics['used_memory_rss'] result['redis_ephemeral_commands_processed_total'] = metrics['total_commands_processed'] result['redis_ephemeral_iops'] = metrics['instantaneous_ops_per_sec'] result['redis_ephemeral_instantaneous_input_kbps'] = metrics['instantaneous_input_kbps'] result['redis_ephemeral_instantaneous_output_kbps'] = metrics['instantaneous_output_kbps'] result['redis_ephemeral_hget_p50_seconds'], result['redis_ephemeral_hget_p99_seconds'] = redis_extract_p50_and_p99_seconds(metrics['latency_percentiles_usec_hget']) result['redis_ephemeral_hgetall_p50_seconds'], result['redis_ephemeral_hgetall_p99_seconds'] = redis_extract_p50_and_p99_seconds(metrics['latency_percentiles_usec_hgetall']) result['redis_ephemeral_hset_p50_seconds'], result['redis_ephemeral_hset_p99_seconds'] = redis_extract_p50_and_p99_seconds(metrics['latency_percentiles_usec_hset']) result['redis_ephemeral_xadd_p50_seconds'], result['redis_ephemeral_xadd_p99_seconds'] = redis_extract_p50_and_p99_seconds(metrics['latency_percentiles_usec_xadd']) result['redis_ephemeral_xread_p50_seconds'], result['redis_ephemeral_xread_p99_seconds'] = redis_extract_p50_and_p99_seconds(metrics['latency_percentiles_usec_xread']) result['redis_ephemeral_xrevrange_p50_seconds'], result['redis_ephemeral_xrevrange_p99_seconds'] = redis_extract_p50_and_p99_seconds(metrics['latency_percentiles_usec_xrevrange']) result['redis_ephemeral_xtrim_p50_seconds'], result['redis_ephemeral_xtrim_p99_seconds'] = redis_extract_p50_and_p99_seconds(metrics['latency_percentiles_usec_xtrim']) return result end |
.set(json, scope:, queued: true) ⇒ Object
Sets (updates) the redis hash of this model Queued defaults to true for MetricModel
47 48 49 50 51 |
# File 'lib/openc3/models/metric_model.rb', line 47 def self.set(json, scope:, queued: true) json[:scope] = scope json.transform_keys!(&:to_sym) self.new(**json).create(force: true, queued: queued) end |
Instance Method Details
#as_json(*a) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/openc3/models/metric_model.rb', line 62 def as_json(*a) { 'name' => @name, 'updated_at' => @updated_at, 'values' => @values.as_json(*a) } end |