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 +4 -4
- data/README.md +6 -1
- data/lib/statsman/accountable.rb +5 -5
- data/lib/statsman/reporter_job.rb +29 -14
- data/lib/statsman/version.rb +1 -1
- data/lib/statsman.rb +12 -10
- data/statsman.gemspec +1 -1
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed869a2552ea2928a1113cacfcfcab177d4e8f02
|
4
|
+
data.tar.gz: 9acf818a6b5365abffd49098fa1becb16e60e88a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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?
|
data/lib/statsman/accountable.rb
CHANGED
@@ -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,
|
10
|
-
Statsman.send_counter key,
|
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,
|
14
|
-
Statsman.send_value key,
|
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,
|
9
|
-
Statsman::Agent.log("ReporterJob sending
|
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
|
-
|
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
|
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
|
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
|
data/lib/statsman/version.rb
CHANGED
data/lib/statsman.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
|
1
|
+
require_relative "statsman/version"
|
2
2
|
require "singleton"
|
3
3
|
require "logger"
|
4
|
-
|
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(
|
14
|
+
def send_counter(key, value, meta={})
|
14
15
|
agent = Agent.with_config(Config.instance)
|
15
|
-
agent.send_data(:counter,
|
16
|
+
agent.send_data(:counter, key, value, meta)
|
16
17
|
end
|
17
18
|
|
18
|
-
def send_value(
|
19
|
+
def send_value(key, value, meta={})
|
19
20
|
agent = Agent.with_config(Config.instance)
|
20
|
-
agent.send_data(:value,
|
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 :
|
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(
|
61
|
-
log("enqueueing
|
62
|
-
ReporterJob.new.async.perform(config,
|
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
|
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-
|
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.
|
131
|
+
rubygems_version: 2.4.8
|
126
132
|
signing_key:
|
127
133
|
specification_version: 4
|
128
134
|
summary: Report stats to the statsman backend
|