instrumental_agent 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -10,14 +10,17 @@ Add the gem to your Gemfile.
10
10
  gem 'instrumental_agent'
11
11
  ```
12
12
 
13
- Visit instrumentalapp.com[instrumentalapp.com] and create an account, then
14
- initialize the agent with your API key, found in the Docs section.
13
+ Visit instrumentalapp.com[instrumentalapp.com] and create an account,
14
+ then initialize the agent with your API key, found in the Docs section.
15
+ You'll probably want something like this, only enabling the agent in
16
+ production mode so you don't pollute your data.
15
17
 
16
18
  ```sh
17
19
  I = Instrumental::Agent.new('YOUR_API_KEY', :test_mode => !Rails.env.production?)
18
20
  ```
19
21
 
20
- We recommend setting test_mode to true in dev/test modes so that you don't pollute your production data.
22
+ You may want to setup two projects, so that you can verify stats in one,
23
+ and release them to production in another.
21
24
 
22
25
  Now you can begin to use Instrumental to track your application.
23
26
 
@@ -26,16 +29,18 @@ I.gauge('load', 1.23)
26
29
  I.increment('signups')
27
30
  ```
28
31
 
29
- Data without historical context sucks. Instrumental lets you
30
- backfill data, allowing you to see deep into your project's past.
32
+ Streaming data is better with a little historical context. Instrumental
33
+ lets you backfill data, allowing you to see deep into your project's
34
+ past.
31
35
 
32
36
  ```sh
37
+ I.synchronous = true # disables command buffering
33
38
  User.find_each do |user|
34
39
  I.increment('signups', 1, user.created_at)
35
40
  end
36
41
  ```
37
42
 
38
- Want some general server stats (load, memory, etc.)? Install instrumental_tools and run this command (sorry not daemonized yet :)
43
+ Want some general server stats (load, memory, etc.)? Check out the instrumental_tools gem.
39
44
 
40
45
  ```sh
41
46
  gem install instrumental_tools
data/Rakefile CHANGED
@@ -1,9 +1,9 @@
1
1
  require 'bundler/gem_tasks'
2
- require "rspec/core/rake_task"
2
+ require 'rspec/core/rake_task'
3
3
 
4
- task :default => 'spec'
4
+ task :default => :spec
5
5
 
6
6
  RSpec::Core::RakeTask.new(:spec) do |spec|
7
7
  spec.pattern = 'spec/*_spec.rb'
8
- spec.rspec_opts = ['--backtrace']
9
- end
8
+ spec.rspec_opts = ['--color --backtrace']
9
+ end
@@ -11,9 +11,9 @@ module Instrumental
11
11
  class Agent
12
12
  BACKOFF = 2.0
13
13
  MAX_RECONNECT_DELAY = 15
14
- MAX_BUFFER = 100
14
+ MAX_BUFFER = 5000
15
15
 
16
- attr_accessor :host, :port
16
+ attr_accessor :host, :port, :synchronous
17
17
  attr_reader :connection, :enabled
18
18
 
19
19
  def self.logger=(l)
@@ -150,7 +150,9 @@ module Instrumental
150
150
  cmd = "%s %s\n" % [cmd, args.collect(&:to_s).join(" ")]
151
151
  if @queue.size < MAX_BUFFER
152
152
  logger.debug "Queueing: #{cmd.chomp}"
153
+ @main_thread = Thread.current if @synchronous
153
154
  @queue << cmd
155
+ Thread.stop if @synchronous
154
156
  cmd
155
157
  else
156
158
  logger.warn "Dropping command, queue full(#{@queue.size}): #{cmd.chomp}"
@@ -201,6 +203,7 @@ module Instrumental
201
203
  @socket.puts command_and_args
202
204
  command_and_args = nil
203
205
  end
206
+ @main_thread.run if @synchronous
204
207
  end
205
208
  rescue Exception => err
206
209
  logger.error err.to_s
@@ -1,3 +1,3 @@
1
1
  module Instrumental
2
- VERSION = "0.5.1"
2
+ VERSION = "0.6.0"
3
3
  end
data/spec/agent_spec.rb CHANGED
@@ -140,6 +140,35 @@ describe Instrumental::Agent, "enabled" do
140
140
  @server.commands.last.should == "increment increment_test 1 555"
141
141
  end
142
142
 
143
+ it "should discard data that overflows the buffer" do
144
+ with_constants('Instrumental::Agent::MAX_BUFFER' => 3) do
145
+ 5.times do |i|
146
+ @agent.increment('overflow_test', i + 1, 300)
147
+ end
148
+ wait
149
+ @server.commands.should include("increment overflow_test 1 300")
150
+ @server.commands.should include("increment overflow_test 2 300")
151
+ @server.commands.should include("increment overflow_test 3 300")
152
+ @server.commands.should_not include("increment overflow_test 4 300")
153
+ @server.commands.should_not include("increment overflow_test 5 300")
154
+ end
155
+ end
156
+
157
+ it "should send all data in synchronous mode" do
158
+ with_constants('Instrumental::Agent::MAX_BUFFER' => 3) do
159
+ @agent.synchronous = true
160
+ 5.times do |i|
161
+ @agent.increment('overflow_test', i + 1, 300)
162
+ end
163
+ wait # let the server receive the commands
164
+ @server.commands.should include("increment overflow_test 1 300")
165
+ @server.commands.should include("increment overflow_test 2 300")
166
+ @server.commands.should include("increment overflow_test 3 300")
167
+ @server.commands.should include("increment overflow_test 4 300")
168
+ @server.commands.should include("increment overflow_test 5 300")
169
+ end
170
+ end
171
+
143
172
  it "should automatically reconnect" do
144
173
  wait
145
174
  @server.disconnect_all
data/spec/spec_helper.rb CHANGED
@@ -12,3 +12,59 @@ RSpec.configure do |config|
12
12
  end
13
13
 
14
14
  end
15
+
16
+
17
+ def parse_constant(constant)
18
+ source, _, constant_name = constant.to_s.rpartition('::')
19
+
20
+ [source.constantize, constant_name]
21
+ end
22
+
23
+ def with_constants(constants, &block)
24
+ saved_constants = {}
25
+ constants.each do |constant, val|
26
+ source_object, const_name = parse_constant(constant)
27
+
28
+ saved_constants[constant] = source_object.const_get(const_name)
29
+ Kernel::silence_warnings { source_object.const_set(const_name, val) }
30
+ end
31
+
32
+ begin
33
+ block.call
34
+ ensure
35
+ constants.each do |constant, val|
36
+ source_object, const_name = parse_constant(constant)
37
+
38
+ Kernel::silence_warnings { source_object.const_set(const_name, saved_constants[constant]) }
39
+ end
40
+ end
41
+ end
42
+ alias :with_constant :with_constants
43
+
44
+ class String
45
+ # From Rails
46
+ def constantize
47
+ names = split('::')
48
+ names.shift if names.empty? || names.first.empty?
49
+
50
+ constant = Object
51
+ names.each do |name|
52
+ constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
53
+ end
54
+ constant
55
+ end
56
+ end
57
+
58
+ module Kernel
59
+ # File activesupport/lib/active_support/core_ext/kernel/reporting.rb, line 10
60
+ def silence_warnings
61
+ with_warnings(nil) { yield }
62
+ end
63
+
64
+ def with_warnings(flag)
65
+ old_verbose, $VERBOSE = $VERBOSE, flag
66
+ yield
67
+ ensure
68
+ $VERBOSE = old_verbose
69
+ end
70
+ end
metadata CHANGED
@@ -1,102 +1,133 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: instrumental_agent
3
- version: !ruby/object:Gem::Version
4
- version: 0.5.1
3
+ version: !ruby/object:Gem::Version
4
+ hash: 7
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 6
9
+ - 0
10
+ version: 0.6.0
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Elijah Miller
9
14
  - Christopher Zelenak
10
15
  - Kristopher Chambers
11
16
  autorequire:
12
17
  bindir: bin
13
18
  cert_chain: []
14
- date: 2011-12-12 00:00:00.000000000 Z
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
19
+
20
+ date: 2011-12-13 00:00:00 Z
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :development
33
+ prerelease: false
17
34
  name: rake
18
- requirement: &70326630447340 !ruby/object:Gem::Requirement
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ requirement: &id002 !ruby/object:Gem::Requirement
19
38
  none: false
20
- requirements:
21
- - - ! '>='
22
- - !ruby/object:Gem::Version
23
- version: '0'
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 2
45
+ - 0
46
+ version: "2.0"
24
47
  type: :development
25
48
  prerelease: false
26
- version_requirements: *70326630447340
27
- - !ruby/object:Gem::Dependency
28
49
  name: rspec
29
- requirement: &70326630446640 !ruby/object:Gem::Requirement
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ requirement: &id003 !ruby/object:Gem::Requirement
30
53
  none: false
31
- requirements:
32
- - - ~>
33
- - !ruby/object:Gem::Version
34
- version: '2.0'
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
35
61
  type: :development
36
62
  prerelease: false
37
- version_requirements: *70326630446640
38
- - !ruby/object:Gem::Dependency
39
63
  name: guard
40
- requirement: &70326630445220 !ruby/object:Gem::Requirement
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ requirement: &id004 !ruby/object:Gem::Requirement
41
67
  none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
46
75
  type: :development
47
76
  prerelease: false
48
- version_requirements: *70326630445220
49
- - !ruby/object:Gem::Dependency
50
77
  name: guard-rspec
51
- requirement: &70326630444280 !ruby/object:Gem::Requirement
78
+ version_requirements: *id004
79
+ - !ruby/object:Gem::Dependency
80
+ requirement: &id005 !ruby/object:Gem::Requirement
52
81
  none: false
53
- requirements:
54
- - - ! '>='
55
- - !ruby/object:Gem::Version
56
- version: '0'
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
88
+ version: "0"
57
89
  type: :development
58
90
  prerelease: false
59
- version_requirements: *70326630444280
60
- - !ruby/object:Gem::Dependency
61
91
  name: growl_notify
62
- requirement: &70326630443280 !ruby/object:Gem::Requirement
92
+ version_requirements: *id005
93
+ - !ruby/object:Gem::Dependency
94
+ requirement: &id006 !ruby/object:Gem::Requirement
63
95
  none: false
64
- requirements:
65
- - - ! '>='
66
- - !ruby/object:Gem::Version
67
- version: '0'
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ hash: 3
100
+ segments:
101
+ - 0
102
+ version: "0"
68
103
  type: :development
69
104
  prerelease: false
70
- version_requirements: *70326630443280
71
- - !ruby/object:Gem::Dependency
72
105
  name: rb-fsevent
73
- requirement: &70326630442600 !ruby/object:Gem::Requirement
106
+ version_requirements: *id006
107
+ - !ruby/object:Gem::Dependency
108
+ requirement: &id007 !ruby/object:Gem::Requirement
74
109
  none: false
75
- requirements:
76
- - - ! '>='
77
- - !ruby/object:Gem::Version
78
- version: '0'
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ hash: 3
114
+ segments:
115
+ - 0
116
+ version: "0"
79
117
  type: :development
80
118
  prerelease: false
81
- version_requirements: *70326630442600
82
- - !ruby/object:Gem::Dependency
83
119
  name: fuubar
84
- requirement: &70326630441940 !ruby/object:Gem::Requirement
85
- none: false
86
- requirements:
87
- - - ! '>='
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: *70326630441940
120
+ version_requirements: *id007
93
121
  description: Keep track of anything.
94
- email:
122
+ email:
95
123
  - support@instrumentalapp.com
96
124
  executables: []
125
+
97
126
  extensions: []
127
+
98
128
  extra_rdoc_files: []
99
- files:
129
+
130
+ files:
100
131
  - .gitignore
101
132
  - .rspec
102
133
  - Gemfile
@@ -116,29 +147,38 @@ files:
116
147
  - spec/test_server.rb
117
148
  homepage: http://github.com/fastestforward/instrumental_agent
118
149
  licenses: []
150
+
119
151
  post_install_message:
120
152
  rdoc_options: []
121
- require_paths:
153
+
154
+ require_paths:
122
155
  - lib
123
- required_ruby_version: !ruby/object:Gem::Requirement
156
+ required_ruby_version: !ruby/object:Gem::Requirement
124
157
  none: false
125
- requirements:
126
- - - ! '>='
127
- - !ruby/object:Gem::Version
128
- version: '0'
129
- required_rubygems_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ hash: 3
162
+ segments:
163
+ - 0
164
+ version: "0"
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
166
  none: false
131
- requirements:
132
- - - ! '>='
133
- - !ruby/object:Gem::Version
134
- version: '0'
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ hash: 3
171
+ segments:
172
+ - 0
173
+ version: "0"
135
174
  requirements: []
175
+
136
176
  rubyforge_project:
137
- rubygems_version: 1.8.11
177
+ rubygems_version: 1.8.10
138
178
  signing_key:
139
179
  specification_version: 3
140
180
  summary: Agent for reporting data to instrumentalapp.com
141
- test_files:
181
+ test_files:
142
182
  - spec/agent_spec.rb
143
183
  - spec/spec_helper.rb
144
184
  - spec/test_server.rb