statsman 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +15 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +57 -0
- data/Rakefile +2 -0
- data/lib/statsman.rb +68 -0
- data/lib/statsman/reporter_job.rb +30 -0
- data/lib/statsman/version.rb +3 -0
- data/statsman.gemspec +26 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2f893b43308e1cba15f3ae3bba98808d84c92a6a
|
4
|
+
data.tar.gz: 578b9f2f3efe488d1736c1bfc71897a4c37126f8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b04806849d924d72411337d2d76b7aa21da0e4719f035124bb67d97dce750fd6493c68f7fad109fe8187939fcf7159170d876ab69512ac0e37d66401f877a636
|
7
|
+
data.tar.gz: 60eb7e4cbe1899b6527a7bc405136f696400c7fbf9131f8cd2230ac07a6c8649f8cf783e85f7ad47110b59fc330a7cb4bc46762c7c578c8e9c1fe42746fbce84
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
statsman
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Jeff Emminger
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# Statsman
|
2
|
+
|
3
|
+
Send stats to a cupboard backend
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'statsman'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install statsman
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Rails
|
24
|
+
|
25
|
+
In an initializer:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
# config/initializers/statsman.rb
|
29
|
+
|
30
|
+
Statsman.config do |config|
|
31
|
+
config.auth_header = "your-auth-header-key"
|
32
|
+
config.url = "http://url-of-cupboard-backend"
|
33
|
+
end
|
34
|
+
|
35
|
+
```
|
36
|
+
|
37
|
+
Then, whereever you want to collect stats:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
# Send a counter stat
|
41
|
+
Statsman.send_counter "my-counter-stat-name", some_count, { optional: "metadata" }
|
42
|
+
|
43
|
+
# Send a value stat
|
44
|
+
Statsman.send_value "my-value-stat-name", some_value, { optional: "metadata" }
|
45
|
+
```
|
46
|
+
|
47
|
+
## TODO
|
48
|
+
|
49
|
+
* Thread pool?
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
1. Fork it ( https://bitbucket.org/7compass/statsman/fork )
|
54
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
55
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
56
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
57
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/statsman.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require "statsman/version"
|
2
|
+
require "singleton"
|
3
|
+
require "logger"
|
4
|
+
require "statsman/reporter_job"
|
5
|
+
require "json"
|
6
|
+
|
7
|
+
module Statsman
|
8
|
+
|
9
|
+
def config
|
10
|
+
yield Config.instance
|
11
|
+
end
|
12
|
+
|
13
|
+
def send_counter(name, data)
|
14
|
+
agent = Agent.with_config(Config.instance)
|
15
|
+
agent.send_data(:counter, name, data)
|
16
|
+
end
|
17
|
+
|
18
|
+
def send_value(name, data)
|
19
|
+
agent = Agent.with_config(Config.instance)
|
20
|
+
agent.send_data(:value, name, data)
|
21
|
+
end
|
22
|
+
|
23
|
+
module_function :config
|
24
|
+
module_function :send_counter
|
25
|
+
module_function :send_value
|
26
|
+
|
27
|
+
class Config
|
28
|
+
include Singleton
|
29
|
+
attr_accessor :auth_header, :url, :logging_on
|
30
|
+
end # Config
|
31
|
+
|
32
|
+
class Agent
|
33
|
+
include Singleton
|
34
|
+
attr_accessor :config
|
35
|
+
|
36
|
+
def self.logger
|
37
|
+
if defined? Rails
|
38
|
+
log_path = "log/statsman.#{Rails.env}.log"
|
39
|
+
else
|
40
|
+
log_path = "./statsman.log"
|
41
|
+
end
|
42
|
+
|
43
|
+
@logger ||= Logger.new(log_path)
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.with_config(config)
|
47
|
+
i = instance
|
48
|
+
i.config = config
|
49
|
+
i
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.log(str)
|
53
|
+
logger.info(str) if Config.instance.logging_on
|
54
|
+
end
|
55
|
+
|
56
|
+
def log(str)
|
57
|
+
self.class.log(str)
|
58
|
+
end
|
59
|
+
|
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)
|
63
|
+
end
|
64
|
+
|
65
|
+
end # Agent
|
66
|
+
|
67
|
+
end
|
68
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
require "httparty"
|
3
|
+
require "sucker_punch"
|
4
|
+
|
5
|
+
class ReporterJob
|
6
|
+
include SuckerPunch::Job
|
7
|
+
|
8
|
+
def perform(config, type, name, data, meta)
|
9
|
+
Statsman::Agent.log("ReporterJob sending type: #{type}, name: #{name}, data: #{data}, meta: #{meta}")
|
10
|
+
|
11
|
+
resp = HTTParty.post(
|
12
|
+
"#{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
|
+
}
|
22
|
+
)
|
23
|
+
Statsman::Agent.log("sent type: #{type}, name: #{name}, data: #{data}, meta: #{meta}, response: [#{resp.code}] #{resp.headers.inspect}")
|
24
|
+
|
25
|
+
rescue => e
|
26
|
+
Statsman::Agent.log("Exception sending type: #{type}, name: #{name}, data: #{data}, meta: #{meta}: #{e.message}\n#{e.backtrace.join("\n")}")
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/statsman.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'statsman/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "statsman"
|
8
|
+
spec.version = Statsman::VERSION
|
9
|
+
spec.authors = ["Jeff Emminger", "Marly Wilson"]
|
10
|
+
spec.email = ["jeff@7compass.com", "marly@7compass.com"]
|
11
|
+
spec.summary = %q{Report stats to the statsman backend}
|
12
|
+
spec.description = %q{Report stats to the statsman backend.}
|
13
|
+
spec.homepage = "https://bitbucket.org/7compass/statsman"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "sucker_punch", "~> 1.2"
|
22
|
+
spec.add_runtime_dependency "httparty", "~> 0.13"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: statsman
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeff Emminger
|
8
|
+
- Marly Wilson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-07-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: sucker_punch
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.2'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.2'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: httparty
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0.13'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0.13'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: bundler
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ~>
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '1.7'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '1.7'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rake
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '10.0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '10.0'
|
70
|
+
description: Report stats to the statsman backend.
|
71
|
+
email:
|
72
|
+
- jeff@7compass.com
|
73
|
+
- marly@7compass.com
|
74
|
+
executables: []
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- .DS_Store
|
79
|
+
- .gitignore
|
80
|
+
- .ruby-gemset
|
81
|
+
- .ruby-version
|
82
|
+
- Gemfile
|
83
|
+
- LICENSE.txt
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- lib/statsman.rb
|
87
|
+
- lib/statsman/reporter_job.rb
|
88
|
+
- lib/statsman/version.rb
|
89
|
+
- statsman.gemspec
|
90
|
+
homepage: https://bitbucket.org/7compass/statsman
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.4.7
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: Report stats to the statsman backend
|
114
|
+
test_files: []
|