ns24-dashing-collector 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ns24-dashing-collector.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Sergio Tulentsev
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,29 @@
1
+ # Ns24::Dashing::Collector
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'ns24-dashing-collector'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install ns24-dashing-collector
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $stdout.sync = true
4
+ require 'ns24-dashing-collector'
5
+
6
+ Ns24::Dashing::Collector::Runner.new.run
@@ -0,0 +1,13 @@
1
+ require_relative 'informator_base'
2
+
3
+ class Apps < InformatorBase
4
+ def metric
5
+ 'active_apps'
6
+ end
7
+
8
+ def info
9
+ {
10
+ current: 50 + rand(50)
11
+ }
12
+ end
13
+ end
@@ -0,0 +1,30 @@
1
+ require 'redis'
2
+ require 'redis-namespace'
3
+
4
+ require_relative 'informator_base'
5
+
6
+ class Events < InformatorBase
7
+ def initialize
8
+ # configurize
9
+ host = '172.22.11.142'
10
+ @redis = Redis::Namespace.new('staging-resque:resque', redis: Redis.new(host: host))
11
+ end
12
+
13
+ attr_reader :redis
14
+
15
+ attr_accessor :prev_p
16
+
17
+ def metric
18
+ 'events_processed'
19
+ end
20
+
21
+ def info
22
+ p = redis.get('stat:processed').to_i
23
+
24
+ res = {current: p, last: prev_p || p}
25
+ self.prev_p = p
26
+ res
27
+ end
28
+
29
+
30
+ end
@@ -0,0 +1,9 @@
1
+ class InformatorBase
2
+ def metric
3
+ nil
4
+ end
5
+
6
+ def info
7
+ {}
8
+ end
9
+ end
@@ -0,0 +1,34 @@
1
+ require 'redis'
2
+ require 'redis-namespace'
3
+
4
+ require_relative 'informator_base'
5
+
6
+ class Queues < InformatorBase
7
+ def initialize
8
+ # configurize
9
+ host = '172.22.11.142'
10
+ @redis = Redis::Namespace.new('staging-resque:resque', redis: Redis.new(host: host))
11
+ end
12
+
13
+ attr_reader :redis
14
+
15
+ attr_accessor :prev_q
16
+
17
+ def metric
18
+ 'queue_size'
19
+ end
20
+
21
+ def info
22
+ queues = redis.smembers('queues')
23
+ q = queues.reduce(0) do |memo, el|
24
+ memo += redis.llen("queue:#{el}")
25
+ memo
26
+ end
27
+
28
+ res = {current: q, last: prev_q || q}
29
+ self.prev_q = q
30
+ res
31
+ end
32
+
33
+
34
+ end
@@ -0,0 +1,7 @@
1
+ require_relative 'informator_base'
2
+
3
+ class Usership < InformatorBase
4
+ def metric
5
+ 'dau'
6
+ end
7
+ end
@@ -0,0 +1,48 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'json'
4
+
5
+ # load all informators
6
+ Dir[File.join(File.dirname(__FILE__), 'informators/*.rb')].each {|f| require f }
7
+
8
+ module Ns24::Dashing::Collector
9
+ class Runner
10
+ def initialize
11
+ # @collectors = [Queues, Events, Apps, Usership].map(&:new)
12
+ @collectors = [Queues, Events].map(&:new)
13
+ end
14
+
15
+ attr_reader :collectors
16
+
17
+ def run
18
+ # loop here
19
+ loop do
20
+ collectors.each do |cl|
21
+ m, i = cl.metric, cl.info
22
+ post m, i
23
+ # puts "#{m}: #{i}"
24
+ end
25
+
26
+ sleep(2)
27
+ end
28
+ end
29
+
30
+ def post metric, info
31
+ info.merge! auth_token: ENV['AUTH_TOKEN']
32
+
33
+ uri = URI.parse("http://ns24-dashingboard.herokuapp.com/widgets/#{metric}")
34
+ http = Net::HTTP.new(uri.host, uri.port)
35
+
36
+ request = Net::HTTP::Post.new(uri.request_uri)
37
+ request.body = info.to_json
38
+
39
+ # handle errors here
40
+ response = http.request(request)
41
+
42
+ unless response.code =~ /2\d\d/
43
+ puts "metric: #{metric}, payload: #{info}"
44
+ puts "Error: #{response.body}"
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,7 @@
1
+ module Ns24
2
+ module Dashing
3
+ module Collector
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require "ns24-dashing-collector/version"
2
+ require "ns24-dashing-collector/runner"
3
+
4
+ module Ns24
5
+ module Dashing
6
+ module Collector
7
+ # Your code goes here...
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ns24-dashing-collector/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "ns24-dashing-collector"
8
+ gem.version = Ns24::Dashing::Collector::VERSION
9
+ gem.authors = ["Sergio Tulentsev"]
10
+ gem.email = ["sergei.tulentsev@gmail.com"]
11
+ gem.description = %q{This is a simple daemon that collects metrics from our system and puts them to dashing}
12
+ gem.summary = %q{This is a simple daemon that collects metrics from our system}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'redis'
21
+ gem.add_dependency 'redis-namespace'
22
+ gem.add_dependency 'json'
23
+
24
+
25
+ gem.add_development_dependency 'rspec'
26
+
27
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ns24-dashing-collector
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sergio Tulentsev
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: redis
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
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: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: redis-namespace
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: json
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
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: '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: '0'
78
+ description: This is a simple daemon that collects metrics from our system and puts
79
+ them to dashing
80
+ email:
81
+ - sergei.tulentsev@gmail.com
82
+ executables:
83
+ - ns24-dashing-collector
84
+ extensions: []
85
+ extra_rdoc_files: []
86
+ files:
87
+ - .gitignore
88
+ - Gemfile
89
+ - LICENSE.txt
90
+ - README.md
91
+ - Rakefile
92
+ - bin/ns24-dashing-collector
93
+ - lib/ns24-dashing-collector.rb
94
+ - lib/ns24-dashing-collector/informators/apps.rb
95
+ - lib/ns24-dashing-collector/informators/events.rb
96
+ - lib/ns24-dashing-collector/informators/informator_base.rb
97
+ - lib/ns24-dashing-collector/informators/queues.rb
98
+ - lib/ns24-dashing-collector/informators/usership.rb
99
+ - lib/ns24-dashing-collector/runner.rb
100
+ - lib/ns24-dashing-collector/version.rb
101
+ - ns24-dashing-collector.gemspec
102
+ homepage: ''
103
+ licenses: []
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ! '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 1.8.24
123
+ signing_key:
124
+ specification_version: 3
125
+ summary: This is a simple daemon that collects metrics from our system
126
+ test_files: []
127
+ has_rdoc: