emque-stats 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 TeamSnap
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.
@@ -0,0 +1,79 @@
1
+ [![Build Status](https://travis-ci.org/emque/emque-stats.png)](https://travis-ci.org/emque/emque-stats)
2
+
3
+ # Emque Stats
4
+
5
+ A library that provides any [Emque::Producing](https://github.com/emque/emque-producing)
6
+ application instrumentation capabilities for collecting application statistics
7
+ and events. Stats and events are sent as just another Emque message through the
8
+ Message Broker (RabbitMQ).
9
+
10
+ A separate [Emque::Consuming](https://github.com/emque/emque-consuming)
11
+ service must be created and deployed to process the data. In doing so, you can
12
+ use your preferred graphing or analytics solution, be it Graphite, StatsD,
13
+ New Relic, Keen.io, etc.
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ gem 'emque-stats'
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install emque-stats
28
+
29
+ ## Usage
30
+
31
+ For any app already using Emque::Producing, there is nothing further to do.
32
+ Emque::Stats will re-use the same configuration.
33
+
34
+ For an app that is not already using Emque::Producing.
35
+
36
+ ``` ruby
37
+ Emque::Stats.configure do |config|
38
+ emque_configuration = Emque::Producing::Configuration.new
39
+ emque_configuration.app_name = "your_app"
40
+ emque_configuration.rabbitmq_options = { :url => "your rabbitmq url" }
41
+ config.emque_producing_configuration = emque_configuration
42
+ end
43
+ ```
44
+
45
+ Send some stats
46
+
47
+ ``` ruby
48
+ # track activity
49
+ Emque::Stats.track("login", {:user_id => 1, :another_property => "something"} )
50
+
51
+ # counter
52
+ Emque::Stats.increment("garets")
53
+ Emque::Stats.count("garets", 20)
54
+
55
+ # timing
56
+ Emque::Stats.timer("glork", 320)
57
+
58
+ # gauge
59
+ Emque::Stats.gauge("bork", 100)
60
+ ```
61
+
62
+ ## Tests
63
+
64
+ To run tests...
65
+
66
+ ```
67
+ bundle exec rspec
68
+ ```
69
+
70
+ ## Contributing
71
+
72
+ FIRST: Read our style guides at
73
+ https://github.com/teamsnap/guides/tree/master/ruby
74
+
75
+ 1. Fork it ( http://github.com/emque/emque-stats/fork )
76
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
77
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
78
+ 4. Push to the branch (`git push origin my-new-feature`)
79
+ 5. Create new Pull Request
@@ -0,0 +1,14 @@
1
+ require "rubygems"
2
+ require "bundler/gem_tasks"
3
+ require "rake/clean"
4
+ require "rspec/core/rake_task"
5
+ require "coveralls/rake/task"
6
+
7
+ CLOBBER.include("coverage")
8
+
9
+ RSpec::Core::RakeTask.new(:spec) do |t|
10
+ t.fail_on_error = false
11
+ end
12
+ task :default => :spec
13
+
14
+ Coveralls::RakeTask.new
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "emque/stats/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "emque-stats"
8
+ spec.version = Emque::Stats::VERSION
9
+ spec.authors = ["Ryan Williams"]
10
+ spec.email = ["oss@teamsnap.com"]
11
+ spec.description = %q{Collect and send application stats and events via Emque}
12
+ spec.summary = %q{Collect and send application stats and events via Emque}
13
+ spec.homepage = "https://github.com/teamsnap/emque-stats"
14
+ spec.license = "MIT"
15
+
16
+ spec.require_paths = %w(lib)
17
+ spec.files = %w(LICENSE.txt README.md Rakefile emque-stats.gemspec)
18
+ spec.files += Dir.glob('lib/**/*.rb')
19
+ spec.files += Dir.glob('spec/**/*')
20
+ spec.test_files = Dir.glob('spec/**/*')
21
+
22
+ spec.add_dependency "emque-producing", "1.1.2"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.7"
25
+ spec.add_development_dependency "rake", "~> 10.4.2"
26
+ spec.add_development_dependency "rspec", "~> 3.2.0"
27
+ spec.add_development_dependency "bunny", "~> 1.7.0"
28
+ spec.add_development_dependency "pry"
29
+ spec.add_development_dependency "coveralls"
30
+ end
@@ -0,0 +1,3 @@
1
+ module Emque; end
2
+
3
+ require "emque/stats"
@@ -0,0 +1,45 @@
1
+ require "emque/stats/version"
2
+ require "emque/stats/configuration"
3
+ require "emque/stats/client"
4
+
5
+ module Emque
6
+ module Stats
7
+ class << self
8
+ attr_accessor :client
9
+ attr_writer :configuration
10
+
11
+ def logger
12
+ self.configuration.logger
13
+ end
14
+
15
+ def configure
16
+ yield(configuration)
17
+ self.client = Client.new(configuration)
18
+ end
19
+
20
+ def configuration
21
+ @configuration ||= Configuration.new
22
+ end
23
+
24
+ def track(event_name, props = {})
25
+ Emque::Stats.client.produce_track_event(event_name, props)
26
+ end
27
+
28
+ def increment(event_name)
29
+ count(event_name, 1)
30
+ end
31
+
32
+ def count(event_name, count=1)
33
+ Emque::Stats.client.produce_count(event_name, count)
34
+ end
35
+
36
+ def timer(event_name, duration)
37
+ Emque::Stats.client.produce_timer(event_name, duration)
38
+ end
39
+
40
+ def gauge(event_name, value)
41
+ Emque::Stats.client.produce_gauge(event_name, value)
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,36 @@
1
+ require "emque-producing"
2
+ require "emque/stats/messages/count_message"
3
+ require "emque/stats/messages/gauge_message"
4
+ require "emque/stats/messages/timer_message"
5
+ require "emque/stats/messages/track_event_message"
6
+
7
+ module Emque
8
+ module Stats
9
+ class Client
10
+
11
+ def initialize(config)
12
+ Emque::Producing.configuration = config.emque_producing_configuration
13
+ end
14
+
15
+ def produce_track_event(event_name, properties = {})
16
+ message = TrackEventMessage.new(:event_name => event_name, :properties => properties)
17
+ message.publish
18
+ end
19
+
20
+ def produce_count(event_name, count=1)
21
+ message = CountMessage.new(:event_name => event_name, :count => count)
22
+ message.publish
23
+ end
24
+
25
+ def produce_timer(event_name, duration)
26
+ message = TimerMessage.new(:event_name => event_name, :duration => duration)
27
+ message.publish
28
+ end
29
+
30
+ def produce_gauge(event_name, value)
31
+ message = GaugeMessage.new(:event_name => event_name, :value => value)
32
+ message.publish
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,11 @@
1
+ module Emque
2
+ module Stats
3
+ class Configuration
4
+ attr_accessor :emque_producing_configuration
5
+
6
+ def initialize
7
+ @emque_producing_configuration = nil
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ class CountMessage
2
+ include Emque::Producing::Message
3
+
4
+ topic "metrics"
5
+ message_type "metrics.count"
6
+ raise_on_failure false
7
+
8
+ values do
9
+ attribute :event_name, String, :required => true
10
+ attribute :count, Integer, :required => true
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ class GaugeMessage
2
+ include Emque::Producing::Message
3
+
4
+ topic "metrics"
5
+ message_type "metrics.gauge"
6
+ raise_on_failure false
7
+
8
+ values do
9
+ attribute :event_name, String, :required => true
10
+ attribute :value, Integer, :required => true
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ class MeterMessage
2
+ include Emque::Producing::Message
3
+
4
+ topic "metrics"
5
+ message_type "metrics.meter"
6
+ raise_on_failure false
7
+
8
+ values do
9
+ attribute :event_name, String, :required => true
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ class TimerMessage
2
+ include Emque::Producing::Message
3
+
4
+ topic "metrics"
5
+ message_type "metrics.timer"
6
+ raise_on_failure false
7
+
8
+ values do
9
+ attribute :event_name, String, :required => true
10
+ attribute :duration, Integer, :required => true
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ class TrackEventMessage
2
+ include Emque::Producing::Message
3
+
4
+ topic "track"
5
+ message_type "track.event"
6
+ raise_on_failure false
7
+
8
+ values do
9
+ attribute :event_name, String, :required => true
10
+ attribute :properties, Hash
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ module Emque
2
+ module Stats
3
+ VERSION = "1.0.1"
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ require "pry"
2
+ require "emque-stats"
3
+
4
+ RSpec.configure do |config|
5
+ config.order = :random
6
+ end
@@ -0,0 +1,26 @@
1
+ describe Emque::Stats::Client do
2
+ subject {
3
+ producing_configuration = Emque::Producing::Configuration.new
4
+ producing_configuration.publish_messages = false
5
+ stats_configuration = Emque::Stats::Configuration.new
6
+ stats_configuration.emque_producing_configuration = producing_configuration
7
+ client = Emque::Stats::Client.new(stats_configuration)
8
+ client
9
+ }
10
+
11
+ it "produces event" do
12
+ subject.produce_track_event("signin")
13
+ end
14
+
15
+ it "produces count" do
16
+ subject.produce_count("signin")
17
+ end
18
+
19
+ it "produces timers" do
20
+ subject.produce_timer("timer", 10)
21
+ end
22
+
23
+ it "produces gauge" do
24
+ subject.produce_gauge("gauge", 10)
25
+ end
26
+ end
@@ -0,0 +1,12 @@
1
+ describe Emque::Stats::Configuration do
2
+ subject { Emque::Stats::Configuration.new }
3
+
4
+ it "emque_producing_configuration is nil by default" do
5
+ expect(subject.emque_producing_configuration).to eq nil
6
+ end
7
+
8
+ it "allows emque_producing_configuration to be overwritten" do
9
+ subject.emque_producing_configuration = Emque::Producing::Configuration.new
10
+ expect(subject.emque_producing_configuration).to_not be_nil
11
+ end
12
+ end
@@ -0,0 +1,35 @@
1
+ describe Emque::Stats do
2
+ describe "#configure" do
3
+ before do
4
+ Emque::Stats.configure do |config|
5
+ emque_configuration = Emque::Producing::Configuration.new
6
+ emque_configuration.app_name = "emque_stats"
7
+ config.emque_producing_configuration = emque_configuration
8
+ end
9
+ end
10
+
11
+ it "has a configuration" do
12
+ expect(
13
+ Emque::Stats.configuration.emque_producing_configuration.app_name
14
+ ).to eq "emque_stats"
15
+ end
16
+ end
17
+
18
+ describe "#count" do
19
+ subject {
20
+ Emque::Stats.configure do |config|
21
+ end
22
+ Emque::Stats.client
23
+ }
24
+
25
+ it "by default, produces a count of 1" do
26
+ expect(subject).to receive(:produce_count).with("an.event", 1)
27
+ Emque::Stats.count("an.event")
28
+ end
29
+
30
+ it "produces an arbitrary count" do
31
+ expect(subject).to receive(:produce_count).with("an.event", 5)
32
+ Emque::Stats.count("an.event", 5)
33
+ end
34
+ end
35
+ end
metadata ADDED
@@ -0,0 +1,180 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: emque-stats
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ryan Williams
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-06-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: emque-producing
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - '='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.1.2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - '='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.1.2
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.7'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.7'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 10.4.2
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 10.4.2
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 3.2.0
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 3.2.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: bunny
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 1.7.0
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 1.7.0
94
+ - !ruby/object:Gem::Dependency
95
+ name: pry
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: coveralls
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: Collect and send application stats and events via Emque
127
+ email:
128
+ - oss@teamsnap.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - LICENSE.txt
134
+ - README.md
135
+ - Rakefile
136
+ - emque-stats.gemspec
137
+ - lib/emque-stats.rb
138
+ - lib/emque/stats.rb
139
+ - lib/emque/stats/configuration.rb
140
+ - lib/emque/stats/client.rb
141
+ - lib/emque/stats/messages/gauge_message.rb
142
+ - lib/emque/stats/messages/meter_message.rb
143
+ - lib/emque/stats/messages/count_message.rb
144
+ - lib/emque/stats/messages/track_event_message.rb
145
+ - lib/emque/stats/messages/timer_message.rb
146
+ - lib/emque/stats/version.rb
147
+ - spec/spec_helper.rb
148
+ - spec/stats_spec.rb
149
+ - spec/stats/configuration_spec.rb
150
+ - spec/stats/client_spec.rb
151
+ homepage: https://github.com/teamsnap/emque-stats
152
+ licenses:
153
+ - MIT
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ none: false
160
+ requirements:
161
+ - - ! '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ none: false
166
+ requirements:
167
+ - - ! '>='
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ requirements: []
171
+ rubyforge_project:
172
+ rubygems_version: 1.8.23
173
+ signing_key:
174
+ specification_version: 3
175
+ summary: Collect and send application stats and events via Emque
176
+ test_files:
177
+ - spec/spec_helper.rb
178
+ - spec/stats_spec.rb
179
+ - spec/stats/configuration_spec.rb
180
+ - spec/stats/client_spec.rb