StatsCloud

StatsCloud module

Installation

Add this line to your application's Gemfile:

gem 'statscloud'

And then execute:

$ bundle

Or install it yourself as:

$ gem install statscloud

Usage

Rails

  1. Run generator for creatinig initializer file, statscloud.io configuration file .statscloud.yml and directory for saving your metrics configurations. ruby rails g stats_cloud:install
  2. Set up your configuration files (you can read more about StatsCloud configuration here).

StatsCloud auth token is a required parameter for getting access to StatsCloud service. The best way to configure this auth token in your application is using environment variable STATSCLOUD_AUTH_TOKEN. StatsCloud add-on at Heroku configures this environment variable automatically during adding this add-on to your application. If you want to use statscloud service in your development process (or somewhere else) you can copy Heroku config vars to your local .env file.

  1. You can change statscloud.rb intializer file if you want to start StatsCloud service with a different environment or add some tags to your StatsmeterClient.

    with_environment('env')

    This method allows you to record metrics from different environments (like test, development, production) separately, so

    StatsCloud.with_environment('production').start 
    

    would start StatsCloud service at production environment. Without this method, the environment would be chosen from the configuration file. If you don't configure it service would try to find env in the RAILS_ENV and if it is also missing it would set the value as the default.

    with_tags(array[string])

    Also, you can start service with sending some tags to the cluster. Tags are used to group metrics. By default, the host name is used as a tag, which allows you to track metrics for both the application as a whole and for each host individually. In the cloud, an array of tags ['region', 'server_name'] can be used, which allows you to track metrics for the application as a whole, separate regions or separate servers.

    StatsCloud.with_tags(['region', 'server_name']).start
    

    You can combine these methods calling them as a chain.

  2. Use StatsCLoud.meter with record_event method for recording one event or record_events to send multiple events to cluster from any place of you application.

    StatsCloud.meter.record_event('event', 1)
    StatsCloud.meter.record_events({name: 'gauge', measurement: 123}, {name: 'counter'})
    

    Ruby

  3. Install statscloud gem:

    gem install statscloud
    
  4. Require statscloud in the project and set up your application structure, with .statscloud.yml configuration file (at the root of the project) and metrics configs (read more about StatsCloud configuration here).

  5. Customize statscloud run with with_environment and with_tags methods and start it where you need it.

    StatsCloud.with_environment('test').with_tags(['usa', 'server_1']).start
    
  6. Send metrics via StatsCloud.meter

    meter = StatsCloud.meter
    meter.record_event('event', 1)
    meter.record_events({name: 'gauge', measurement: 123}, {name: 'counter'});
    
  7. Stop work of StatsCloud service when 'time is over'.

    StatsCloud.stop
    

The full version of pure ruby example takes the form:

require 'statscloud' # import gem

# start the module, returns a thread
StatsCloud.start

# track events (remember that you have to wait for the socket connection to the cluster before record any metrics)
StatsCloud.meter.record_event('numeric', 123)
StatsCloud.meter.record_events({name: 'gauge', measurement: 123}, {name: 'counter'})

# stop the module
StatsCloud.stop

License

(c) Copyright 2018 Agilium Labs LLC, all rights reserved.