statscloud.io Ruby client
Install
Add this line to your application's Gemfile:
gem 'statscloud'
And then execute:
bundle
Use
Make sure you confgured statscloud via .statscloud.yml configuration file. Read https://medium.com/@roman.kisilenko/software-application-monitoring-how-to-or-how-not-to-let-your-production-fail-9481dd0ef6de for configuration options.
# require gem
require 'statscloud'
# use default client via StatsCloud module
statscloud = StatsCloud
# optionally, specify environment and/or tags
statscloud.with_environment('staging').(['us-west-2', 'my-server'])
# start the StatsCloud client
statscloud.start()
# track events
statscloud.record_event('statistics', 123)
statscloud.record_events({name: 'gauge', measurement: 123}, {name: 'counter'})
# stop the module (useful for tests)
statscloud.stop()
Creating multiple clients
You can also create multiple clients with custom config files:
# require gem
require 'statscloud'
# use default client via StatsCloud module
statscloud = StatsCloud
# optionally, specify environment and/or tags
statscloud.with_environment('staging').(['us-west-2', 'my-server'])
# start the StatsCloud client
statscloud.start
# create custom client, tags and environment will be copied from default client
business_client = statscloud.clone_with_config_file('.business.statscloud.yml')
# you can change tags and environment for custom client
business_client.with_environment('production').('other-server')
# and start as usual
business_client.start
# track events
statscloud.record_event('statistics', 123)
statscloud.record_events({name: 'gauge', measurement: 123}, {name: 'counter'})
business_client.record_event('business-metric', 123)
# stop the module (useful for tests)
statscloud.stop
Specify token in environment variable
If token is not specified in .statscloud.yml configuration file, then it will be retrieved from STATSCLOUD_AUTH_TOKEN environment variable.
Usage in Rails framework
You can use a generator for creatinig initializer file, statscloud.io configuration file and directory for saving your metrics configurations.
rails g stats_cloud:install
You can then change statscloud.rb
intializer file as needed.
StatsCloud initializer exposes StatsCloud client as StatsCloud constant, so that you can use it from your Rails code as
StatsCloud.record_event('statistic', 123)