Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #24 from tclavier/master

Gem update and add a generic collectd parser
  • Loading branch information...
commit 3d3f088fa998846a26cf33a63c4018f03d0e25e9 2 parents c49c3b8 + 87ba881
@obfuscurity authored
Showing with 99 additions and 39 deletions.
  1. +2 −1  .gitignore
  2. +0 −2  Gemfile
  3. +37 −32 Gemfile.lock
  4. +3 −4 lib/backstop/collectd/parser.rb
  5. +10 −0 lib/backstop/collectd/plugins/generic.rb
  6. +14 −0 spec/backstop/generic_collectd_data.json
  7. +13 −0 spec/backstop/generic_collectd_data_without_type_instance.json
  8. +20 −0 spec/backstop/web_spec.rb
  9. BIN  vendor/cache/daemons-1.1.8.gem
  10. BIN  vendor/cache/daemons-1.1.9.gem
  11. BIN  vendor/cache/diff-lcs-1.1.3.gem
  12. BIN  vendor/cache/diff-lcs-1.2.5.gem
  13. BIN  vendor/cache/dotenv-0.9.0.gem
  14. BIN  vendor/cache/dotenv-1.0.2.gem
  15. BIN  vendor/cache/eventmachine-0.12.10.gem
  16. BIN  vendor/cache/eventmachine-1.0.7.gem
  17. BIN  vendor/cache/foreman-0.63.0.gem
  18. BIN  vendor/cache/foreman-0.77.0.gem
  19. BIN  vendor/cache/json-1.8.0.gem
  20. BIN  vendor/cache/json-1.8.2.gem
  21. BIN  vendor/cache/newrelic_rpm-3.6.5.130.gem
  22. BIN  vendor/cache/newrelic_rpm-3.9.9.275.gem
  23. BIN  vendor/cache/rack-1.5.2.gem
  24. BIN  vendor/cache/rack-1.6.0.gem
  25. BIN  vendor/cache/rack-protection-1.2.0.gem
  26. BIN  vendor/cache/rack-protection-1.5.3.gem
  27. BIN  vendor/cache/rack-test-0.6.1.gem
  28. BIN  vendor/cache/rack-test-0.6.3.gem
  29. BIN  vendor/cache/rake-0.9.2.2.gem
  30. BIN  vendor/cache/rake-10.4.2.gem
  31. BIN  vendor/cache/rspec-2.11.0.gem
  32. BIN  vendor/cache/rspec-3.2.0.gem
  33. BIN  vendor/cache/rspec-core-2.11.1.gem
  34. BIN  vendor/cache/rspec-core-3.2.0.gem
  35. BIN  vendor/cache/rspec-expectations-2.11.2.gem
  36. BIN  vendor/cache/rspec-expectations-3.2.0.gem
  37. BIN  vendor/cache/rspec-mocks-2.11.2.gem
  38. BIN  vendor/cache/rspec-mocks-3.2.0.gem
  39. BIN  vendor/cache/rspec-support-3.2.1.gem
  40. BIN  vendor/cache/sinatra-1.3.2.gem
  41. BIN  vendor/cache/sinatra-1.4.5.gem
  42. BIN  vendor/cache/thin-1.3.1.gem
  43. BIN  vendor/cache/thin-1.6.3.gem
  44. BIN  vendor/cache/thor-0.18.1.gem
  45. BIN  vendor/cache/thor-0.19.1.gem
  46. BIN  vendor/cache/tilt-1.3.3.gem
  47. BIN  vendor/cache/tilt-1.4.1.gem
  48. BIN  vendor/cache/yajl-ruby-1.1.0.gem
  49. BIN  vendor/cache/yajl-ruby-1.2.1.gem
View
3  .gitignore
@@ -1,4 +1,5 @@
.bundle
.env
.foreman
-
+*~
+*.swp
View
2  Gemfile
@@ -1,7 +1,5 @@
source 'https://rubygems.org'
-ruby '1.9.3'
-
gem 'bundler'
gem 'foreman'
gem 'dotenv'
View
69 Gemfile.lock
@@ -1,40 +1,45 @@
GEM
remote: https://rubygems.org/
specs:
- daemons (1.1.8)
- diff-lcs (1.1.3)
- dotenv (0.9.0)
- eventmachine (0.12.10)
- foreman (0.63.0)
- dotenv (>= 0.7)
- thor (>= 0.13.6)
- json (1.8.0)
- newrelic_rpm (3.6.5.130)
- rack (1.5.2)
- rack-protection (1.2.0)
+ daemons (1.1.9)
+ diff-lcs (1.2.5)
+ dotenv (1.0.2)
+ eventmachine (1.0.7)
+ foreman (0.77.0)
+ dotenv (~> 1.0.2)
+ thor (~> 0.19.1)
+ json (1.8.2)
+ newrelic_rpm (3.9.9.275)
+ rack (1.6.0)
+ rack-protection (1.5.3)
rack
- rack-test (0.6.1)
+ rack-test (0.6.3)
rack (>= 1.0)
- rake (0.9.2.2)
- rspec (2.11.0)
- rspec-core (~> 2.11.0)
- rspec-expectations (~> 2.11.0)
- rspec-mocks (~> 2.11.0)
- rspec-core (2.11.1)
- rspec-expectations (2.11.2)
- diff-lcs (~> 1.1.3)
- rspec-mocks (2.11.2)
- sinatra (1.3.2)
- rack (~> 1.3, >= 1.3.6)
- rack-protection (~> 1.2)
- tilt (~> 1.3, >= 1.3.3)
- thin (1.3.1)
- daemons (>= 1.0.9)
- eventmachine (>= 0.12.6)
- rack (>= 1.0.0)
- thor (0.18.1)
- tilt (1.3.3)
- yajl-ruby (1.1.0)
+ rake (10.4.2)
+ rspec (3.2.0)
+ rspec-core (~> 3.2.0)
+ rspec-expectations (~> 3.2.0)
+ rspec-mocks (~> 3.2.0)
+ rspec-core (3.2.0)
+ rspec-support (~> 3.2.0)
+ rspec-expectations (3.2.0)
+ diff-lcs (>= 1.2.0, < 2.0)
+ rspec-support (~> 3.2.0)
+ rspec-mocks (3.2.0)
+ diff-lcs (>= 1.2.0, < 2.0)
+ rspec-support (~> 3.2.0)
+ rspec-support (3.2.1)
+ sinatra (1.4.5)
+ rack (~> 1.4)
+ rack-protection (~> 1.4)
+ tilt (~> 1.3, >= 1.3.4)
+ thin (1.6.3)
+ daemons (~> 1.0, >= 1.0.9)
+ eventmachine (~> 1.0)
+ rack (~> 1.0)
+ thor (0.19.1)
+ tilt (1.4.1)
+ yajl-ruby (1.2.1)
PLATFORMS
ruby
View
7 lib/backstop/collectd/parser.rb
@@ -37,11 +37,10 @@ def parse_base
def parse_plugin
plugin = data['plugin']
method = "parse_plugin_#{plugin}".to_sym
- if self.respond_to? method
- send(method)
- else
- []
+ unless self.respond_to? method
+ method = :parse_plugin_generic
end
+ send(method)
end
end
View
10 lib/backstop/collectd/plugins/generic.rb
@@ -0,0 +1,10 @@
+class CollectdData
+ # disk partition stats
+ def parse_plugin_generic
+ metric = data['type']
+ metric += ".#{data['type_instance']}" unless data['type_instance'].empty?
+ [
+ { metric: "#{metric}", value: data['values'][0] },
+ ]
+ end
+end
View
14 spec/backstop/generic_collectd_data.json
@@ -0,0 +1,14 @@
+[
+ {
+ "values":[42],
+ "dstypes":["derive"],
+ "dsnames":["value"],
+ "time":1423949215.334,
+ "interval":10.0,
+ "host":"leeloo.octo.it",
+ "plugin":"irq",
+ "plugin_instance":"",
+ "type":"irq",
+ "type_instance":"IWI"
+ }
+]
View
13 spec/backstop/generic_collectd_data_without_type_instance.json
@@ -0,0 +1,13 @@
+[
+ {
+ "values":[42],
+ "dstypes":["gauge"],
+ "dsnames":["value"],
+ "time":1423950659.88,
+ "interval":10.0,
+ "host":"leeloo.octo.it",
+ "plugin":"users",
+ "plugin_instance":"",
+ "type":"users",
+ "type_instance":""}
+]
View
20 spec/backstop/web_spec.rb
@@ -49,6 +49,8 @@ def app
context 'POST /collectd' do
let(:good_collectd_data) { File.open(File.dirname(__FILE__) + '/good_collectd_data.json').read }
let(:bad_collectd_data) { File.open(File.dirname(__FILE__) + '/bad_collectd_data.json').read }
+ let(:generic_collectd_data) { File.open(File.dirname(__FILE__) + '/generic_collectd_data.json').read }
+ let(:generic_collectd_data_without_type_instance) { File.open(File.dirname(__FILE__) + '/generic_collectd_data_without_type_instance.json').read }
it 'should require JSON' do
post '/collectd', 'foo'
@@ -70,6 +72,24 @@ def app
last_response.status.should eq(400)
last_response.body.should eq('missing fields')
end
+
+ it 'should handle a generic collectd metric' do
+ p = double('publisher')
+ Backstop::Publisher.should_receive(:new) { p }
+ p.should_receive(:publish).with('mitt.leeloo.octo.it.irq.IWI', 42, 1423949215.334)
+ post '/collectd', generic_collectd_data
+ last_response.body.should eq('ok')
+ last_response.status.should eq(200)
+ end
+
+ it 'should handle a generic collectd metric without type_instance' do
+ p = double('publisher')
+ Backstop::Publisher.should_receive(:new) { p }
+ p.should_receive(:publish).with('mitt.leeloo.octo.it.users', 42, 1423950659.88)
+ post '/collectd', generic_collectd_data_without_type_instance
+ last_response.body.should eq('ok')
+ last_response.status.should eq(200)
+ end
end
context 'POST /github' do
View
BIN  vendor/cache/daemons-1.1.8.gem
Binary file not shown
View
BIN  vendor/cache/daemons-1.1.9.gem
Binary file not shown
View
BIN  vendor/cache/diff-lcs-1.1.3.gem
Binary file not shown
View
BIN  vendor/cache/diff-lcs-1.2.5.gem
Binary file not shown
View
BIN  vendor/cache/dotenv-0.9.0.gem
Binary file not shown
View
BIN  vendor/cache/dotenv-1.0.2.gem
Binary file not shown
View
BIN  vendor/cache/eventmachine-0.12.10.gem
Binary file not shown
View
BIN  vendor/cache/eventmachine-1.0.7.gem
Binary file not shown
View
BIN  vendor/cache/foreman-0.63.0.gem
Binary file not shown
View
BIN  vendor/cache/foreman-0.77.0.gem
Binary file not shown
View
BIN  vendor/cache/json-1.8.0.gem
Binary file not shown
View
BIN  vendor/cache/json-1.8.2.gem
Binary file not shown
View
BIN  vendor/cache/newrelic_rpm-3.6.5.130.gem
Binary file not shown
View
BIN  vendor/cache/newrelic_rpm-3.9.9.275.gem
Binary file not shown
View
BIN  vendor/cache/rack-1.5.2.gem
Binary file not shown
View
BIN  vendor/cache/rack-1.6.0.gem
Binary file not shown
View
BIN  vendor/cache/rack-protection-1.2.0.gem
Binary file not shown
View
BIN  vendor/cache/rack-protection-1.5.3.gem
Binary file not shown
View
BIN  vendor/cache/rack-test-0.6.1.gem
Binary file not shown
View
BIN  vendor/cache/rack-test-0.6.3.gem
Binary file not shown
View
BIN  vendor/cache/rake-0.9.2.2.gem
Binary file not shown
View
BIN  vendor/cache/rake-10.4.2.gem
Binary file not shown
View
BIN  vendor/cache/rspec-2.11.0.gem
Binary file not shown
View
BIN  vendor/cache/rspec-3.2.0.gem
Binary file not shown
View
BIN  vendor/cache/rspec-core-2.11.1.gem
Binary file not shown
View
BIN  vendor/cache/rspec-core-3.2.0.gem
Binary file not shown
View
BIN  vendor/cache/rspec-expectations-2.11.2.gem
Binary file not shown
View
BIN  vendor/cache/rspec-expectations-3.2.0.gem
Binary file not shown
View
BIN  vendor/cache/rspec-mocks-2.11.2.gem
Binary file not shown
View
BIN  vendor/cache/rspec-mocks-3.2.0.gem
Binary file not shown
View
BIN  vendor/cache/rspec-support-3.2.1.gem
Binary file not shown
View
BIN  vendor/cache/sinatra-1.3.2.gem
Binary file not shown
View
BIN  vendor/cache/sinatra-1.4.5.gem
Binary file not shown
View
BIN  vendor/cache/thin-1.3.1.gem
Binary file not shown
View
BIN  vendor/cache/thin-1.6.3.gem
Binary file not shown
View
BIN  vendor/cache/thor-0.18.1.gem
Binary file not shown
View
BIN  vendor/cache/thor-0.19.1.gem
Binary file not shown
View
BIN  vendor/cache/tilt-1.3.3.gem
Binary file not shown
View
BIN  vendor/cache/tilt-1.4.1.gem
Binary file not shown
View
BIN  vendor/cache/yajl-ruby-1.1.0.gem
Binary file not shown
View
BIN  vendor/cache/yajl-ruby-1.2.1.gem
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.