class StatsCloud::Client
Module which implements StatsCloud
framework support.
Attributes
Public Class Methods
Creates new StatsCloud::Client
instance with empty configuration.
@return instance of StatsCloud::Client
@api public
# File lib/statscloud/statscloud_client.rb, line 26 def initialize(environment = nil, client_tags = nil) initialize_values(environment, client_tags) update_config_file(".statscloud.yml") end
Public Instance Methods
Returns cluster status.
@return [Hash
]
@api public
# 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
Returns statscloud client environemnt.
@return [String
]
@api public
# File lib/statscloud/statscloud_client.rb, line 158 def environment @env end
Returns statscloud.io client aka Statsmeter client
@return instance of StatsCloud::StatsmeterClient
@api public
# File lib/statscloud/statscloud_client.rb, line 96 def meter @statsmeter_client end
Records a single event.
@param [String
] name
name of the event to record.
@param [Integer
] measurement
optional measurement, depending on metrics type.
Calls statsmeter client record_event
method.
@api public
# File lib/statscloud/statscloud_client.rb, line 110 def record_event(name, measurement = 0) @statsmeter_client&.record_event(name, measurement) end
Records several events at once.
@param [Array
] events
events to send (each should have name and optional measurement fields).
Calls statsmeter record_events
method.
@api public
# File lib/statscloud/statscloud_client.rb, line 122 def record_events(*events) @statsmeter_client&.record_events(*events) end
Records an array of events at once.
@param [Array
] events
array of events to send (each shoud have name and optional measurement fields).
Calls statsmeter client record_events_array
method.
@api public
# File lib/statscloud/statscloud_client.rb, line 134 def record_events_array(events) @statsmeter_client&.record_events_array(events) end
Configures statsmeter.io support for application and initializes a statscloud.io client.
@param [+String] env
statsmeter.io cluster environment
@param [Hash
] base_config
statsmeter.io configuration
@return [Thread]
@api public
# 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
Stops statscloud.io service.
@return nil
@api public
# 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
Allows to start several instances of StatsCloud::Client
with different confifurations.
@param [String
] file
Main configuration file for StatsCloud::Client
@return instance of StatsCloud::Client
@api public
# File lib/statscloud/statscloud_client.rb, line 86 def with_config_file(file) update_config_file(file) self end
Configures Statscloud environment.
@param [String
] env
Environment
@return instance of StatsCloud::Client
@api public
# File lib/statscloud/statscloud_client.rb, line 60 def with_environment(environment) config_environment(environment) self end
Private Instance Methods
# File lib/statscloud/statscloud_client.rb, line 209 def check_cluster_status(cluster) raise error(cluster_error_message) if cluster.nil? || cluster["status"]["status"] == "ERROR" end
# File lib/statscloud/statscloud_client.rb, line 200 def configure_cluster @cluster_client = create_cluster_client @cluster_client.deploy_cluster(@token, @app, @config) @cluster = @cluster_client.get_cluster(@token, @app).body @graphite_url = @cluster["graphiteUrl"] check_cluster_status(@cluster) log_successful_cluster_deploy end
# File lib/statscloud/statscloud_client.rb, line 196 def configure_statscloud_plugins @plugins = build_plugins(@config["plugins"]) end
# File lib/statscloud/statscloud_client.rb, line 213 def connect_to_cluster @statsmeter_client = create_statsmeter_client(@cluster, @token, @plugins, tags) @statsmeter_client.connect(register_connection_job) end
# File lib/statscloud/statscloud_client.rb, line 218 def create_cluster_client StatsCloud::ClusterClient.new(env, @config["endpoint"]) end
# File lib/statscloud/statscloud_client.rb, line 226 def create_statsmeter_client(cluster, token, plugins, tags) host = cluster["statsmeterUrl"] StatsCloud::StatsmeterClient.new(host, token, plugins, tags) end
# File lib/statscloud/statscloud_client.rb, line 189 def process_configuration(base_config) generate_configuration(base_config) collect_statscloud_assets(@config, @source_mappings) config_values clear_data end
# File lib/statscloud/statscloud_client.rb, line 222 def register_connection_job StatsCloud::RegisterConnectionJob.new(@cluster_client, @token, @app, tags) end