Class: StatsCloud::Client

Inherits:
Object
  • Object
show all
Includes:
AssetsHelper, LoggerHelper, PluginsHelper, StatsCloudHelper
Defined in:
lib/statscloud/statscloud_client.rb

Overview

Module which implements StatsCloud framework support.

Instance Method Summary collapse

Methods included from LoggerHelper

#log_error, #log_info, #logger

Constructor Details

#initializeObject

Creates new StatsCloud::Client instance with empty configuration.



26
27
28
# File 'lib/statscloud/statscloud_client.rb', line 26

def initialize
  initialize_values
end

Instance Method Details

#cluster_statusHash

Returns cluster status.



141
142
143
144
145
146
147
148
149
# File 'lib/statscloud/statscloud_client.rb', line 141

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

#meterObject

Returns statscloud.io client aka Statsmeter client



94
95
96
# File 'lib/statscloud/statscloud_client.rb', line 94

def meter
  @statsmeter_client
end

#record_event(name, measurement = 0) ⇒ Object

Records a single event.

Calls statsmeter client record_event method.



108
109
110
# File 'lib/statscloud/statscloud_client.rb', line 108

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.



120
121
122
# File 'lib/statscloud/statscloud_client.rb', line 120

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.



132
133
134
# File 'lib/statscloud/statscloud_client.rb', line 132

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.



41
42
43
44
45
46
47
48
# File 'lib/statscloud/statscloud_client.rb', line 41

def start(base_config = nil)
  process_configuration(base_config)
  configure_statscloud_plugins
  configure_cluster
  connect_to_cluster
rescue StandardError => error
  log_error error
end

#stopObject

Stops statscloud.io service.



156
157
158
159
160
161
162
163
# File 'lib/statscloud/statscloud_client.rb', line 156

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.



84
85
86
87
# File 'lib/statscloud/statscloud_client.rb', line 84

def with_config_file(file)
  update_config_file(file)
  self
end

#with_environment(env) ⇒ Object

Configures Statscloud environment.



58
59
60
61
# File 'lib/statscloud/statscloud_client.rb', line 58

def with_environment(env)
  config_environment(env)
  self
end

#with_tags(tags) ⇒ Object

Configures Statscloud tags.



71
72
73
74
# File 'lib/statscloud/statscloud_client.rb', line 71

def with_tags(tags)
  config_tags(tags)
  self
end