Class: StatsCloud::Client
- Inherits:
-
Object
- Object
- StatsCloud::Client
- Includes:
- AssetsHelper, LoggerHelper, PluginsHelper, StatsCloudHelper
- Defined in:
- lib/statscloud/statscloud_client.rb
Overview
Module which implements StatsCloud framework support.
Instance Method Summary collapse
-
#client_tags ⇒ Array[+String+]
Returns statscloud client tags.
-
#cluster_status ⇒ +Hash+
Returns cluster status.
-
#environment ⇒ +String+
Returns statscloud client environemnt.
-
#initialize(environment = nil, client_tags = nil) ⇒ Object
constructor
Creates new StatsCloud::Client instance with empty configuration.
-
#meter ⇒ Object
Returns statscloud.io client aka Statsmeter client.
-
#record_event(name, measurement = 0) ⇒ Object
Records a single event.
-
#record_events(*events) ⇒ Object
Records several events at once.
-
#record_events_array(events) ⇒ Object
Records an array of events at once.
-
#start(base_config = nil) ⇒ Thread
Configures statsmeter.io support for application and initializes a statscloud.io client.
-
#stop ⇒ Object
Stops statscloud.io service.
-
#with_config_file(file) ⇒ Object
Allows to start several instances of StatsCloud::Client with different confifurations.
-
#with_environment(environment) ⇒ Object
Configures Statscloud environment.
-
#with_tags(tags) ⇒ Object
Configures Statscloud tags.
Methods included from LoggerHelper
#log_error, #log_info, #logger
Constructor Details
#initialize(environment = nil, client_tags = nil) ⇒ Object
Creates new StatsCloud::Client instance with empty configuration.
26 27 28 29 |
# File 'lib/statscloud/statscloud_client.rb', line 26 def initialize(environment = nil, = nil) initialize_values(environment, ) update_config_file(".statscloud.yml") end |
Instance Method Details
#client_tags ⇒ Array[+String+]
Returns statscloud client tags.
167 168 169 |
# File 'lib/statscloud/statscloud_client.rb', line 167 def @tags end |
#cluster_status ⇒ +Hash+
Returns cluster status.
143 144 145 146 147 148 149 150 151 |
# File 'lib/statscloud/statscloud_client.rb', line 143 def cluster_status return unless @cluster_client cluster = @cluster_client.get_cluster(@token, @app)&.body check_cluster_status(cluster) cluster["status"]["status"] if cluster rescue StandardError => error log_error error end |
#environment ⇒ +String+
Returns statscloud client environemnt.
158 159 160 |
# File 'lib/statscloud/statscloud_client.rb', line 158 def environment @env end |
#meter ⇒ Object
Returns statscloud.io client aka Statsmeter client
96 97 98 |
# File 'lib/statscloud/statscloud_client.rb', line 96 def meter @statsmeter_client end |
#record_event(name, measurement = 0) ⇒ Object
Records a single event.
Calls statsmeter client record_event method.
110 111 112 |
# File 'lib/statscloud/statscloud_client.rb', line 110 def record_event(name, measurement = 0) @statsmeter_client&.record_event(name, measurement) end |
#record_events(*events) ⇒ Object
Records several events at once.
Calls statsmeter record_events method.
122 123 124 |
# File 'lib/statscloud/statscloud_client.rb', line 122 def record_events(*events) @statsmeter_client&.record_events(*events) end |
#record_events_array(events) ⇒ Object
Records an array of events at once.
Calls statsmeter client record_events_array method.
134 135 136 |
# File 'lib/statscloud/statscloud_client.rb', line 134 def record_events_array(events) @statsmeter_client&.record_events_array(events) end |
#start(base_config = nil) ⇒ Thread
Configures statsmeter.io support for application and initializes a statscloud.io client.
42 43 44 45 46 47 48 49 50 |
# File 'lib/statscloud/statscloud_client.rb', line 42 def start(base_config = nil) initialize_values process_configuration(base_config) configure_statscloud_plugins configure_cluster connect_to_cluster rescue StandardError => error log_error error end |
#stop ⇒ Object
Stops statscloud.io service.
176 177 178 179 180 181 182 183 |
# File 'lib/statscloud/statscloud_client.rb', line 176 def stop @statsmeter_client&.close @statsmeter_client = nil @cluster_client&.undeploy_cluster(@token, @app) @cluster_client = nil rescue StandardError => error log_error error end |
#with_config_file(file) ⇒ Object
Allows to start several instances of StatsCloud::Client with different confifurations.
86 87 88 89 |
# File 'lib/statscloud/statscloud_client.rb', line 86 def with_config_file(file) update_config_file(file) self end |
#with_environment(environment) ⇒ Object
Configures Statscloud environment.
60 61 62 63 |
# File 'lib/statscloud/statscloud_client.rb', line 60 def with_environment(environment) config_environment(environment) self end |
#with_tags(tags) ⇒ Object
Configures Statscloud tags.
73 74 75 76 |
# File 'lib/statscloud/statscloud_client.rb', line 73 def () () self end |