statscloud 1.1.2 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 09e53f93e0256bdb1d7cca10342ca813c3f24ca2
4
- data.tar.gz: 8908fbe41125fdd6360e67a1f14abc2118ae7a55
3
+ metadata.gz: c746267bab13cd8c99e02f033e224ebae2417796
4
+ data.tar.gz: 45a4b15bdd510a44f43ca8ab46af9d38b6fedef3
5
5
  SHA512:
6
- metadata.gz: c5bd4090110b99032c7994729bae102d56a53b1479ff8ca0dad5e94ab3e2512a5ca8fa29b48cf20678048d78f3891f5c777c4f5f87b7bcd42c27f31b60f63e8d
7
- data.tar.gz: 8c56520587fb19179306cd19dd52d49b3ad9ab5f964ef53b42ce7f013f40565b15c6cccbab964796f76f3ed1c39b384cfceff52afaf4179b3e965fcd72e3eb96
6
+ metadata.gz: af4f74b24c2a6d149de0d8bb48f19a5016dbdaa8cede112fbc3ce1b9e48507381b7d0cf9b0f9d703a93586f11407757e5faa77d367ff8e109d3aef910e7b253a
7
+ data.tar.gz: 5b8269f4d83d72e30fccbdefa03e4537947556dc7eb20da2751f3fcfefa455d206a32dfbaadbc5f9d61bf3d160f993368bb604b4f3b48544ce1c460d6d7ae9ec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- statscloud (1.1.2)
4
+ statscloud (1.2.0)
5
5
  crc32 (~> 1.0.1)
6
6
  eventmachine (~> 1.2)
7
7
  fileutils
data/LICENSE ADDED
@@ -0,0 +1,37 @@
1
+ (c) Copyright 2018 Agilium Labs LLC, all rights reserved
2
+
3
+ Certain inventions disclosed in this file may be claimed within
4
+ patents owned or patent applications filed by Agilium Labs LLC or third
5
+ parties.
6
+
7
+ Subject to the terms of this notice, Agilium Labs LLC grants you a
8
+ nonexclusive, nontransferable license, without the right to
9
+ sublicense, to (a) install and execute one copy of these files on any
10
+ number of workstations owned or controlled by you and (b) distribute
11
+ verbatim copies of these files to third parties. As a condition to the
12
+ foregoing grant, you must provide this notice along with each copy you
13
+ distribute and you must not remove, alter, or obscure this notice. All
14
+ other use, reproduction, modification, distribution, or other
15
+ exploitation of these files is strictly prohibited, except as may be set
16
+ forth in a separate written license agreement between you and Agilium Labs LLC.
17
+ The terms of any such license agreement will control over this
18
+ notice. The license stated above will be automatically terminated and
19
+ revoked if you exceed its scope or violate any of the terms of this
20
+ notice.
21
+
22
+ This License does not grant permission to use the trade names,
23
+ trademarks, service marks, or product names of Agilium Labs LLC, except as
24
+ required for reasonable and customary use in describing the origin of
25
+ this file and reproducing the content of this notice. You may not
26
+ mark or brand this file with any trade name, trademarks, service
27
+ marks, or product names other than the original brand (if any)
28
+ provided by Agilium Labs LLC.
29
+
30
+ Unless otherwise expressly agreed by Agilium Labs LLC in a separate written
31
+ license agreement, these files are provided AS IS, WITHOUT WARRANTY OF
32
+ ANY KIND, including without any implied warranties of MERCHANTABILITY,
33
+ FITNESS FOR A PARTICULAR PURPOSE, TITLE, or NON-INFRINGEMENT. As a
34
+ condition to your use of these files, you are solely responsible for
35
+ such use. Agilium Labs LLC will have no liability to you for direct,
36
+ indirect, consequential, incidental, special, or punitive damages or
37
+ for lost profits or data.
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
- # StatsCloud
2
- StatsCloud module
3
- ## Installation
1
+ ## statscloud.io Ruby client
4
2
 
3
+ ### Install
5
4
  Add this line to your application's Gemfile:
6
5
 
7
6
  ```ruby
@@ -10,111 +9,81 @@ gem 'statscloud'
10
9
 
11
10
  And then execute:
12
11
 
13
- $ bundle
12
+ ```bash
13
+ bundle
14
+ ```
14
15
 
15
- Or install it yourself as:
16
+ ### Use
17
+ 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.
16
18
 
17
- $ gem install statscloud
19
+ ```ruby
20
+ # require gem
21
+ require 'statscloud'
18
22
 
19
- ## Usage
23
+ # use default client via StatsCloud module
24
+ statscloud = StatsCloud
20
25
 
21
- ### Rails
26
+ # optionally, specify environment and/or tags
27
+ statscloud.with_environment('staging').with_tags(['us-west-2', 'my-server'])
22
28
 
23
- 1. Run generator for creatinig initializer file, statscloud.io configuration file `.statscloud.yml` and directory for saving your metrics configurations.
24
- ```ruby
25
- rails g stats_cloud:install
26
- ```
27
- 2. Set up your configuration files (you can read more about StatsCloud configuration [here](https://medium.com/@roman.kisilenko/software-application-monitoring-how-to-or-how-not-to-let-your-production-fail-9481dd0ef6de)).
28
-
29
- 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](https://devcenter.heroku.com/articles/heroku-local).
29
+ # start the StatsCloud client
30
+ statscloud.start()
31
+
32
+ # track events
33
+ statscloud.record_event('statistics', 123)
34
+ statscloud.record_events({name: 'gauge', measurement: 123}, {name: 'counter'})
35
+
36
+ # stop the module (useful for tests)
37
+ statscloud.stop()
38
+ ```
39
+
40
+ ### Creating multiple clients
41
+ You can also create multiple clients with custom config files:
30
42
 
31
- 3. You can change `statscloud.rb` intializer file if you want to start StatsCloud service with a different environment, create several instances of StatsCloud::Client with different configurations or add some tags to your StatsmeterClient.
32
-
33
- #### `with_environment('env')`
34
- This method allows you to record metrics from different environments (like `test`, `development`, `production`) separately, so
35
- ```ruby
36
- StatsCloud::Client.new.with_environment('production')
37
- ```
38
- 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`.
39
-
40
- #### `with_tags(array[string])`
41
- 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.
42
- ```ruby
43
- StatsCloud::Client.new.with_tags(['region', 'server_name'])
44
- ```
45
- #### `with_config_file(file)`
46
- Also, it's available to set up several StatsCloud clients with different configuration files via `with_config_file` method.
47
- ```ruby
48
- StatsCloud::Client.new.with_config_file('.production_statscloud.yml')
49
- ```
50
-
51
- You can combine these methods calling them as a chain.
52
-
53
- 4. StatsCloud initializer defines `StatsCloudClient` constant which you can use to record metrics with `record_event` method for recording one event or `record_events` to send multiple events to cluster from any place of your application:
54
-
55
- ```ruby
56
- StatsCloudClient.meter.record_event('event', 1)
57
- StatsCloudClient.meter.record_events({name: 'gauge', measurement: 123}, {name: 'counter'})
58
- ```
59
- Also, you can use these methods directly from StatsCloudClient:
60
- ```ruby
61
- StatsCloudClient.record_event('event', 1)
62
- StatsCloudClient.record_events({name: 'gauge', measurement: 123}, {name: 'counter'})
63
- ```
64
- ### Ruby
65
- 1. Install `statscloud` gem:
66
-
67
- ```ruby
68
- gem install statscloud
69
- ```
70
-
71
- 2. 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](https://medium.com/@roman.kisilenko/software-application-monitoring-how-to-or-how-not-to-let-your-production-fail-9481dd0ef6de)).
72
-
73
- 3. Customize statscloud run with `with_environment`, `with_tags` and `with_config_file` methods and start it where you need it.
74
-
75
- ```ruby
76
- statscloud_client = StatsCloud::Client.new
77
- statscloud_client.with_environment('test').with_tags(['usa', 'server_1']).start
78
- ```
79
- 4. Send metrics via statscloud_client.meter or directly via StatsCloud::Client instance:
80
-
81
- ```ruby
82
- meter = statscloud_client.meter
83
- meter.record_event('event', 1)
84
- meter.record_events({name: 'gauge', measurement: 123}, {name: 'counter'})
85
-
86
- # also available and preferable
87
-
88
- statscloud_client.record_event('some_event', 4)
89
- statscloud_client.record_events({name: 'some_gauge', measurement: 321})
90
-
91
- ```
92
-
93
- 5. Stop work of StatsCloud service when 'time is over':
94
- ```ruby
95
- statscloud_client.stop
96
- ```
97
-
98
- The full version of pure ruby example takes the form:
99
43
  ```ruby
100
- require 'statscloud' # import gem
44
+ # require gem
45
+ require 'statscloud'
46
+
47
+ # use default client via StatsCloud module
48
+ statscloud = StatsCloud
101
49
 
102
- # start the module, returns a thread
103
- statscloud_client = StatsCloud::Client.new
104
- statscloud_client.start
50
+ # optionally, specify environment and/or tags
51
+ statscloud.with_environment('staging').with_tags(['us-west-2', 'my-server'])
105
52
 
106
- meter = statscloud_client.meter
107
- # track events (remember that you have to wait for the socket connection to the cluster before record any metrics)
108
- meter.record_event('numeric', 123)
109
- meter.record_events({name: 'gauge', measurement: 123}, {name: 'counter'})
53
+ # start the StatsCloud client
54
+ statscloud.start
110
55
 
111
- statscloud_client.record_event('some_event', 123)
56
+ # create custom client, tags and environment will be copied from default client
57
+ business_client = statscloud.clone_with_config_file('.business.statscloud.yml')
112
58
 
113
- # stop cluster work
114
- statscloud_client.stop
59
+ # you can change tags and environment for custom client
60
+ business_client.with_environment('production').with_tags('other-server')
115
61
 
62
+ # and start as usual
63
+ business_client.start
64
+
65
+ # track events
66
+ statscloud.record_event('statistics', 123)
67
+ statscloud.record_events({name: 'gauge', measurement: 123}, {name: 'counter'})
68
+ business_client.record_event('business-metric', 123)
69
+
70
+ # stop the module (useful for tests)
71
+ statscloud.stop
116
72
  ```
117
73
 
118
- ## License
74
+ ### Specify token in environment variable
75
+ If token is not specified in .statscloud.yml configuration file, then it will be retrieved from STATSCLOUD_AUTH_TOKEN environment variable.
76
+
77
+ ### Usage in Rails framework
119
78
 
120
- (c) Copyright 2018 Agilium Labs LLC, all rights reserved.
79
+ You can use a generator for creatinig initializer file, statscloud.io configuration file and directory for saving your metrics configurations.
80
+ ```bash
81
+ rails g stats_cloud:install
82
+ ```
83
+
84
+ You can then change `statscloud.rb` intializer file as needed.
85
+
86
+ StatsCloud initializer exposes StatsCloud client as StatsCloud constant, so that you can use it from your Rails code as
87
+ ```ruby
88
+ StatsCloud.record_event('statistic', 123)
89
+ ```
@@ -9,10 +9,11 @@ module StatsCloud
9
9
  module StatsCloudHelper
10
10
  private
11
11
 
12
- def initialize_values
12
+ def initialize_values(environment = nil, client_tags = nil)
13
13
  @config = {}
14
+ @env ||= environment
15
+ @tags ||= client_tags
14
16
  @source_mappings = { metrics: [], admins: [], dashboards: [], alerts: [] }
15
- update_config_file("statscloud.yml")
16
17
  end
17
18
 
18
19
  def generate_configuration(base_config)
@@ -90,7 +91,8 @@ module StatsCloud
90
91
  end
91
92
 
92
93
  def config_dir_file(file)
93
- File.join("config", file)
94
+ file_name = file[0] == "." ? file.sub(/^./, "") : file
95
+ File.join("config", file_name)
94
96
  end
95
97
 
96
98
  def rails_environment
@@ -23,8 +23,9 @@ module StatsCloud
23
23
  # @return instance of StatsCloud::Client
24
24
  #
25
25
  # @api public
26
- def initialize
27
- initialize_values
26
+ def initialize(environment = nil, client_tags = nil)
27
+ initialize_values(environment, client_tags)
28
+ update_config_file(".statscloud.yml")
28
29
  end
29
30
 
30
31
  # Configures statsmeter.io support for application and initializes a statscloud.io client.
@@ -39,6 +40,7 @@ module StatsCloud
39
40
  #
40
41
  # @api public
41
42
  def start(base_config = nil)
43
+ initialize_values
42
44
  process_configuration(base_config)
43
45
  configure_statscloud_plugins
44
46
  configure_cluster
@@ -55,8 +57,8 @@ module StatsCloud
55
57
  # @return instance of StatsCloud::Client
56
58
  #
57
59
  # @api public
58
- def with_environment(env)
59
- config_environment(env)
60
+ def with_environment(environment)
61
+ config_environment(environment)
60
62
  self
61
63
  end
62
64
 
@@ -135,7 +137,7 @@ module StatsCloud
135
137
 
136
138
  # Returns cluster status.
137
139
  #
138
- # @return [Hash]
140
+ # @return [+Hash+]
139
141
  #
140
142
  # @api public
141
143
  def cluster_status
@@ -148,6 +150,24 @@ module StatsCloud
148
150
  log_error error
149
151
  end
150
152
 
153
+ # Returns statscloud client environemnt.
154
+ #
155
+ # @return [+String+]
156
+ #
157
+ # @api public
158
+ def environment
159
+ @env
160
+ end
161
+
162
+ # Returns statscloud client tags.
163
+ #
164
+ # @return [Array[+String+]]
165
+ #
166
+ # @api public
167
+ def client_tags
168
+ @tags
169
+ end
170
+
151
171
  # Stops statscloud.io service.
152
172
  #
153
173
  # @return nil
@@ -4,5 +4,5 @@ module StatsCloud
4
4
  # version of statscloud-ruby-client.
5
5
  #
6
6
  # Type: *String*
7
- VERSION = "1.1.2"
7
+ VERSION = "1.2.0"
8
8
  end
data/lib/statscloud.rb CHANGED
@@ -1,4 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "forwardable"
4
+
3
5
  require "statscloud/statscloud_client"
4
6
  require "statscloud/version"
7
+
8
+ # StatsCloud.io ruby client
9
+ module StatsCloud
10
+ class << self
11
+ include LoggerHelper
12
+ extend Forwardable
13
+
14
+ def_delegators :stats_cloud_instance, :start, :with_environment, :with_tags, :meter, :record_event, :record_events,
15
+ :record_events_array, :cluster_status, :stop, :environment, :client_tags
16
+
17
+ def clone_with_config_file(file)
18
+ new_statscloud_instance(environment, client_tags).with_config_file(file)
19
+ end
20
+
21
+ private
22
+
23
+ def stats_cloud_instance
24
+ @stats_cloud_instance ||= new_statscloud_instance
25
+ end
26
+
27
+ def new_statscloud_instance(environment = nil, client_tags = nil)
28
+ StatsCloud::Client.new(environment, client_tags)
29
+ end
30
+ end
31
+ end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  unless defined?(::Rails::Console)
4
- ::StatsCloudClient = StatsCloud::Client.new
5
- StatsCloudClient.start
6
- at_exit { StatsCloudClient.stop }
4
+ StatsCloud.start
5
+ at_exit { StatsCloud.stop }
7
6
  end
data/statscloud.gemspec CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
13
13
  spec.summary = "StatsCloud service."
14
14
  spec.description = "PaaS application monitoring system."
15
15
  spec.homepage = "https://statscloud.io"
16
- spec.license = "MIT"
16
+ spec.license = "Agilium Labs LLC"
17
17
 
18
18
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
19
  # to allow pushing to a single host or delete this section to allow pushing to any host.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: statscloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Ovcharov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-17 00:00:00.000000000 Z
11
+ date: 2019-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: crc32
@@ -191,7 +191,7 @@ files:
191
191
  - ".rubocop.yml"
192
192
  - Gemfile
193
193
  - Gemfile.lock
194
- - LICENSE.txt
194
+ - LICENSE
195
195
  - README.md
196
196
  - Rakefile
197
197
  - bin/console
@@ -218,7 +218,7 @@ files:
218
218
  - statscloud.gemspec
219
219
  homepage: https://statscloud.io
220
220
  licenses:
221
- - MIT
221
+ - Agilium Labs LLC
222
222
  metadata:
223
223
  allowed_push_host: https://rubygems.org
224
224
  post_install_message:
data/LICENSE.txt DELETED
@@ -1 +0,0 @@
1
- (c) Copyright 2018 Agilium Labs LLC, all rights reserved