statsman 0.0.2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a4ba0d1cac6e83dd6585c2f59e24d58355ad3ab1
4
- data.tar.gz: 07092b0f510b7d0005a59c9e38667501d1e75a7a
3
+ metadata.gz: ed869a2552ea2928a1113cacfcfcab177d4e8f02
4
+ data.tar.gz: 9acf818a6b5365abffd49098fa1becb16e60e88a
5
5
  SHA512:
6
- metadata.gz: 722b2d529e248dbee3bde23b0ba78d16dee76f7df4da2782c3f440389cb342c05860c787c859df9b67e943870109325e54a23a1dfa1eada2818a07f22d759432
7
- data.tar.gz: 47c25c2b90706e39b1493db1ac5cfb0ea97d456b4c9a43e1be82f1bd5ad81a4dc03021f9a33d934fb392c8bf72c5f5d793641f19131489807417f0fa8b4b1a54
6
+ metadata.gz: 51b5578fa95bf7c3a9632b222238449008ca5efe50fe3c73bcd6655c80fdafa1687f18345e329cfd23455f3a04b91c7e2ffa26b111af6f8e3c653d84c5fc43ab
7
+ data.tar.gz: 2f85e2a9f8f54acdd2cf91f1a36b603f0a8f4b29f63fb2fb4907ecda3d96667781a040caea2ddd0ac3e81ad2d534796619c3960cf2c0ccea2de18697e30e0534
data/README.md CHANGED
@@ -28,7 +28,9 @@ In an initializer:
28
28
  # config/initializers/statsman.rb
29
29
 
30
30
  Statsman.config do |config|
31
- config.auth_header = "your-auth-header-key"
31
+ #config.logging_on = false # stealth by default
32
+ config.api_key = "your-api-key"
33
+ config.api_secret = "your-api-secret"
32
34
  config.url = "http://url-of-cupboard-backend"
33
35
  end
34
36
 
@@ -44,6 +46,9 @@ Statsman.send_counter "my-counter-stat-name", some_count, { optional: "metadata"
44
46
  Statsman.send_value "my-value-stat-name", some_value, { optional: "metadata" }
45
47
  ```
46
48
 
49
+ ## Troubleshooting
50
+ If Statsman doesn't appear to be working, be sure to turn on logging.
51
+
47
52
  ## TODO
48
53
 
49
54
  * Thread pool?
@@ -1,4 +1,4 @@
1
- require "activesupport"
1
+ #require "activesupport"
2
2
 
3
3
  module Statsman
4
4
 
@@ -6,12 +6,12 @@ module Statsman
6
6
  # some convenience methods for sending stats
7
7
  module Accountable
8
8
 
9
- def statsman_counter(key, count, meta = {})
10
- Statsman.send_counter key, count, set_class_id(meta)
9
+ def statsman_counter(key, value, meta = {})
10
+ Statsman.send_counter key, value, set_class_id(meta)
11
11
  end
12
12
 
13
- def statsman_value(key, count, meta = {})
14
- Statsman.send_value key, count, set_class_id(meta)
13
+ def statsman_value(key, value, meta = {})
14
+ Statsman.send_value key, value, set_class_id(meta)
15
15
  end
16
16
 
17
17
  # change_type can be anything you want, as it's just used
@@ -1,30 +1,45 @@
1
-
2
1
  require "httparty"
3
2
  require "sucker_punch"
3
+ require "openssl"
4
+ require "json"
4
5
 
5
6
  class ReporterJob
6
7
  include SuckerPunch::Job
7
8
 
8
- def perform(config, type, name, data, meta)
9
- Statsman::Agent.log("ReporterJob sending type: #{type}, name: #{name}, data: #{data}, meta: #{meta}")
9
+ def perform(config, data_type, key, value, meta)
10
+ Statsman::Agent.log("ReporterJob sending data_type: #{data_type}, key: #{key}, value: #{value}, meta: #{meta}")
11
+
12
+ body = {
13
+ data_type: data_type,
14
+ key: key,
15
+ value: value,
16
+ meta: meta,
17
+ time: Time.now.to_i # Add timestamp to body to avoid replay attacks
18
+ }
19
+
20
+ url = "#{config.url}/stats"
10
21
 
11
22
  resp = HTTParty.post(
12
23
  "#{config.url}/stats",
13
- headers: {
14
- "x-auth-header" => config.auth_header
15
- },
16
- body: {
17
- type: type,
18
- name: name,
19
- data: data,
20
- meta: meta,
21
- }
24
+ headers: { "authorization" => request_auth_header(config, "/stats", body)},
25
+ body: body
22
26
  )
23
- Statsman::Agent.log("sent type: #{type}, name: #{name}, data: #{data}, meta: #{meta}, response: [#{resp.code}] #{resp.headers.inspect}")
27
+ Statsman::Agent.log("sent data_type: #{data_type}, key: #{key}, value: #{value}, meta: #{meta}, response: [#{resp.code}] #{resp.headers.inspect}")
24
28
 
25
29
  rescue => e
26
- Statsman::Agent.log("Exception sending type: #{type}, name: #{name}, data: #{data}, meta: #{meta}: #{e.message}\n#{e.backtrace.join("\n")}")
30
+ Statsman::Agent.log("Exception sending data_type: #{data_type}, key: #{key}, value: #{value}, meta: #{meta}: #{e.message}\n#{e.backtrace.join("\n")}")
27
31
 
28
32
  end
29
33
 
34
+ def request_auth_header(config, path, body)
35
+ signature = request_signature(config, path, body)
36
+ "#{config.api_key}:#{signature}"
37
+ end
38
+
39
+ def request_signature(config, path, body)
40
+ str = HTTParty::HashConversions.to_params(body)
41
+ to_sign = path + str
42
+ OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), config.api_secret, to_sign)
43
+ end
44
+
30
45
  end
@@ -1,3 +1,3 @@
1
1
  module Statsman
2
- VERSION = "0.0.2"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/statsman.rb CHANGED
@@ -1,8 +1,9 @@
1
- require "statsman/version"
1
+ require_relative "statsman/version"
2
2
  require "singleton"
3
3
  require "logger"
4
- require "statsman/reporter_job"
4
+ require_relative "statsman/reporter_job"
5
5
  require "json"
6
+ require_relative "statsman/accountable"
6
7
 
7
8
  module Statsman
8
9
 
@@ -10,23 +11,24 @@ module Statsman
10
11
  yield Config.instance
11
12
  end
12
13
 
13
- def send_counter(name, data)
14
+ def send_counter(key, value, meta={})
14
15
  agent = Agent.with_config(Config.instance)
15
- agent.send_data(:counter, name, data)
16
+ agent.send_data(:counter, key, value, meta)
16
17
  end
17
18
 
18
- def send_value(name, data)
19
+ def send_value(key, value, meta={})
19
20
  agent = Agent.with_config(Config.instance)
20
- agent.send_data(:value, name, data)
21
+ agent.send_data(:value, key, value, meta)
21
22
  end
22
23
 
24
+
23
25
  module_function :config
24
26
  module_function :send_counter
25
27
  module_function :send_value
26
28
 
27
29
  class Config
28
30
  include Singleton
29
- attr_accessor :auth_header, :url, :logging_on
31
+ attr_accessor :api_key, :api_secret, :url, :logging_on
30
32
  end # Config
31
33
 
32
34
  class Agent
@@ -57,9 +59,9 @@ module Statsman
57
59
  self.class.log(str)
58
60
  end
59
61
 
60
- def send_data(type, name, data, meta = {})
61
- log("enqueueing type: #{type}, name: #{name}, data: #{data}, meta: #{meta.inspect}")
62
- ReporterJob.new.async.perform(config, type, name, data, meta.to_json)
62
+ def send_data(data_type, key, value, meta = {})
63
+ log("enqueueing data_type: #{data_type}, key: #{key}, value: #{value}, meta: #{meta.inspect}")
64
+ ReporterJob.new.async.perform(config, data_type, key, value, meta.to_json)
63
65
  end
64
66
 
65
67
  end # Agent
data/statsman.gemspec CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_runtime_dependency "sucker_punch", "~> 1.2"
22
22
  spec.add_runtime_dependency "httparty", "~> 0.13"
23
- spec.add_runtime_dependency "activesupport", ">= 3.0"
23
+ spec.add_runtime_dependency "activesupport", ">= 3.0", "< 9"
24
24
 
25
25
  spec.add_development_dependency "bundler", "~> 1.7"
26
26
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: statsman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Emminger
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-07-01 00:00:00.000000000 Z
12
+ date: 2015-07-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sucker_punch
@@ -46,6 +46,9 @@ dependencies:
46
46
  - - '>='
47
47
  - !ruby/object:Gem::Version
48
48
  version: '3.0'
49
+ - - <
50
+ - !ruby/object:Gem::Version
51
+ version: '9'
49
52
  type: :runtime
50
53
  prerelease: false
51
54
  version_requirements: !ruby/object:Gem::Requirement
@@ -53,6 +56,9 @@ dependencies:
53
56
  - - '>='
54
57
  - !ruby/object:Gem::Version
55
58
  version: '3.0'
59
+ - - <
60
+ - !ruby/object:Gem::Version
61
+ version: '9'
56
62
  - !ruby/object:Gem::Dependency
57
63
  name: bundler
58
64
  requirement: !ruby/object:Gem::Requirement
@@ -122,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
128
  version: '0'
123
129
  requirements: []
124
130
  rubyforge_project:
125
- rubygems_version: 2.4.7
131
+ rubygems_version: 2.4.8
126
132
  signing_key:
127
133
  specification_version: 4
128
134
  summary: Report stats to the statsman backend