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
- Run generator for creatinig initializer file, statscloud.io configuration file
.statscloud.ymland directory for saving your metrics configurations.ruby rails g stats_cloud:install - 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.
You can change
statscloud.rbintializer 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, soStatsCloud.with_environment('production').startwould start StatsCloud service at
productionenvironment. 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 thedefault.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.(['region', 'server_name']).startYou can combine these methods calling them as a chain.
Use StatsCLoud.meter with
record_eventmethod for recording one event orrecord_eventsto 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
Install
statscloudgem:gem install statscloudRequire
statscloudin the project and set up your application structure, with.statscloud.ymlconfiguration file (at the root of the project) and metrics configs (read more about StatsCloud configuration here).Customize statscloud run with
with_environmentandwith_tagsmethods and start it where you need it.StatsCloud.with_environment('test').(['usa', 'server_1']).startSend metrics via StatsCloud.meter
meter = StatsCloud.meter meter.record_event('event', 1) meter.record_events({name: 'gauge', measurement: 123}, {name: 'counter'});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.