hallmonitor 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +50 -0
- data/.rvmrc +81 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +20 -0
- data/README.md +77 -0
- data/Rakefile +20 -0
- data/bin/example.rb +38 -0
- data/hallmonitor.gemspec +31 -0
- data/lib/hallmonitor.rb +6 -0
- data/lib/hallmonitor/event.rb +24 -0
- data/lib/hallmonitor/gauge_event.rb +16 -0
- data/lib/hallmonitor/middleware.rb +29 -0
- data/lib/hallmonitor/monitored.rb +74 -0
- data/lib/hallmonitor/outputter.rb +25 -0
- data/lib/hallmonitor/outputters/iooutputter.rb +27 -0
- data/lib/hallmonitor/outputters/statsd_outputter.rb +27 -0
- data/lib/hallmonitor/timed_event.rb +33 -0
- data/lib/hallmonitor/version.rb +10 -0
- data/test/helper.rb +18 -0
- data/test/monitored_test.rb +17 -0
- metadata +187 -0
data/.document
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# rcov generated
|
2
|
+
coverage
|
3
|
+
coverage.data
|
4
|
+
|
5
|
+
# rdoc generated
|
6
|
+
rdoc
|
7
|
+
|
8
|
+
# yard generated
|
9
|
+
doc
|
10
|
+
.yardoc
|
11
|
+
|
12
|
+
# bundler
|
13
|
+
.bundle
|
14
|
+
|
15
|
+
# jeweler generated
|
16
|
+
pkg
|
17
|
+
|
18
|
+
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
|
19
|
+
#
|
20
|
+
# * Create a file at ~/.gitignore
|
21
|
+
# * Include files you want ignored
|
22
|
+
# * Run: git config --global core.excludesfile ~/.gitignore
|
23
|
+
#
|
24
|
+
# After doing this, these files will be ignored in all your git projects,
|
25
|
+
# saving you from having to 'pollute' every project you touch with them
|
26
|
+
#
|
27
|
+
# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
|
28
|
+
#
|
29
|
+
# For MacOS:
|
30
|
+
#
|
31
|
+
#.DS_Store
|
32
|
+
|
33
|
+
# For TextMate
|
34
|
+
#*.tmproj
|
35
|
+
#tmtags
|
36
|
+
|
37
|
+
# For emacs:
|
38
|
+
#*~
|
39
|
+
#\#*
|
40
|
+
#.\#*
|
41
|
+
|
42
|
+
# For vim:
|
43
|
+
#*.swp
|
44
|
+
|
45
|
+
# For redcar:
|
46
|
+
#.redcar
|
47
|
+
|
48
|
+
# For rubinius:
|
49
|
+
#*.rbc
|
50
|
+
Gemfile.lock
|
data/.rvmrc
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
|
7
|
+
environment_id="ruby-1.9.3-p0@hallmonitor"
|
8
|
+
|
9
|
+
#
|
10
|
+
# Uncomment the following lines if you want to verify rvm version per project
|
11
|
+
#
|
12
|
+
# rvmrc_rvm_version="1.10.2" # 1.10.1 seams as a safe start
|
13
|
+
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
14
|
+
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
15
|
+
# return 1
|
16
|
+
# }
|
17
|
+
#
|
18
|
+
|
19
|
+
#
|
20
|
+
# Uncomment following line if you want options to be set only for given project.
|
21
|
+
#
|
22
|
+
# PROJECT_JRUBY_OPTS=( --1.9 )
|
23
|
+
#
|
24
|
+
# The variable PROJECT_JRUBY_OPTS requires the following to be run in shell:
|
25
|
+
#
|
26
|
+
# chmod +x ${rvm_path}/hooks/after_use_jruby_opts
|
27
|
+
#
|
28
|
+
|
29
|
+
#
|
30
|
+
# First we attempt to load the desired environment directly from the environment
|
31
|
+
# file. This is very fast and efficient compared to running through the entire
|
32
|
+
# CLI and selector. If you want feedback on which environment was used then
|
33
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
34
|
+
#
|
35
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
|
36
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
37
|
+
then
|
38
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
39
|
+
|
40
|
+
if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
|
41
|
+
then
|
42
|
+
. "${rvm_path:-$HOME/.rvm}/hooks/after_use"
|
43
|
+
fi
|
44
|
+
else
|
45
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
46
|
+
if ! rvm --create "$environment_id"
|
47
|
+
then
|
48
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
49
|
+
return 1
|
50
|
+
fi
|
51
|
+
fi
|
52
|
+
|
53
|
+
#
|
54
|
+
# If you use an RVM gemset file to install a list of gems (*.gems), you can have
|
55
|
+
# it be automatically loaded. Uncomment the following and adjust the filename if
|
56
|
+
# necessary.
|
57
|
+
#
|
58
|
+
# filename=".gems"
|
59
|
+
# if [[ -s "$filename" ]]
|
60
|
+
# then
|
61
|
+
# rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
|
62
|
+
# fi
|
63
|
+
|
64
|
+
# If you use bundler, this might be useful to you:
|
65
|
+
# if [[ -s Gemfile ]] && ! command -v bundle >/dev/null
|
66
|
+
# then
|
67
|
+
# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
|
68
|
+
# gem install bundler
|
69
|
+
# fi
|
70
|
+
# if [[ -s Gemfile ]] && command -v bundle
|
71
|
+
# then
|
72
|
+
# bundle install
|
73
|
+
# fi
|
74
|
+
|
75
|
+
if [[ $- == *i* ]] # check for interactive shells
|
76
|
+
then
|
77
|
+
echo "Using: $(tput setaf 2)$GEM_HOME$(tput sgr0)" # show the user the ruby and gemset they are using in green
|
78
|
+
else
|
79
|
+
echo "Using: $GEM_HOME" # don't use colors in interactive shells
|
80
|
+
fi
|
81
|
+
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Chris TenHarmsel
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# Hallmonitor
|
2
|
+
|
3
|
+
Hallmonitor is a simple event monitoring framework for Ruby. It allows programs to define and emit events.
|
4
|
+
|
5
|
+
Hallmonitor supports publishing events to a Statsd instance if the 'statsd-ruby' gem is installed. See https://github.com/reinh/statsd for details
|
6
|
+
|
7
|
+
## Setup
|
8
|
+
Before you can use Hallmonitor you have to do a tiny bit of configuration in the form of adding outputters
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
Hallmonitor::Outputter.add_outputter Hallmonitor::Outputters::IOOutputter.new("STDOUT", STDOUT)
|
12
|
+
Hallmonitor::Outputter.add_outputter Hallmonitor::Outputters::StatsdOutputter.new("example", "localhost")
|
13
|
+
```
|
14
|
+
|
15
|
+
The StatsdOutputter is only available if you've installed the `statsd-ruby` gem. If it's not available, StatsdOutputter's intitialize method will raise a RuntimeError
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
There are a few different ways to use Hallmonitor:
|
20
|
+
|
21
|
+
### Included in your class
|
22
|
+
```ruby
|
23
|
+
class Foo
|
24
|
+
include Hallmonitor::Monitored
|
25
|
+
|
26
|
+
# This method will emit 100 events
|
27
|
+
def bar
|
28
|
+
# Emit 100 events. The string will be the name of the Event object that gets emitted
|
29
|
+
100.times do
|
30
|
+
emit("event")
|
31
|
+
end
|
32
|
+
|
33
|
+
# You can also just emit Event objects themselves
|
34
|
+
emit(Event.new("new_event"))
|
35
|
+
|
36
|
+
# emit also takes a block, if you want to modify the event before it is emitted
|
37
|
+
emit(Event.new("event")) do |e|
|
38
|
+
e.name = "changed"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# This method will emit 1 TimedEvent for the block
|
43
|
+
def time_me
|
44
|
+
watch("timed") do |x|
|
45
|
+
sleep(10)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
foo = Foo.new
|
51
|
+
foo.bar # Will emit 10 events
|
52
|
+
foo.time_me # Will emit a single TimedEvent
|
53
|
+
```
|
54
|
+
|
55
|
+
### Explicit Event objects
|
56
|
+
```ruby
|
57
|
+
event = Hallmonitor::Event.new("event")
|
58
|
+
event.emit
|
59
|
+
```
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
## Contributing to Hallmonitor
|
64
|
+
|
65
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
66
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
67
|
+
* Fork the project.
|
68
|
+
* Start a feature/bugfix branch.
|
69
|
+
* Commit and push until you are happy with your contribution.
|
70
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
71
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
72
|
+
|
73
|
+
## Copyright
|
74
|
+
|
75
|
+
Copyright (c) 2012 Chris TenHarmsel. See LICENSE.txt for
|
76
|
+
further details.
|
77
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler/gem_tasks'
|
5
|
+
require 'rake/testtask'
|
6
|
+
Rake::TestTask.new(:test) do |test|
|
7
|
+
test.libs << 'lib' << 'test'
|
8
|
+
test.pattern = 'test/**/*_test.rb'
|
9
|
+
test.verbose = true
|
10
|
+
end
|
11
|
+
|
12
|
+
task :default => :test
|
13
|
+
|
14
|
+
require 'rdoc/task'
|
15
|
+
Rake::RDocTask.new do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = "hallmonitor #{Hallmonitor::Version::STRING}"
|
18
|
+
rdoc.rdoc_files.include('README*')
|
19
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
20
|
+
end
|
data/bin/example.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
lib = File.expand_path('../../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
require 'hallmonitor'
|
5
|
+
require 'hallmonitor/outputters/iooutputter'
|
6
|
+
require 'hallmonitor/outputters/statsd_outputter'
|
7
|
+
require 'pry'
|
8
|
+
|
9
|
+
Hallmonitor::Outputter.add_outputter Hallmonitor::Outputters::IOOutputter.new("STDOUT", STDOUT)
|
10
|
+
Hallmonitor::Outputter.add_outputter Hallmonitor::Outputters::StatsdOutputter.new("example", "graphite.demo.transis.net")
|
11
|
+
|
12
|
+
class Foo
|
13
|
+
include Hallmonitor::Monitored
|
14
|
+
|
15
|
+
def do_something
|
16
|
+
sleep_time_ms = ((Random.rand * 100).floor) * 2
|
17
|
+
puts "Sleeping for #{sleep_time_ms} milliseconds"
|
18
|
+
sleep(sleep_time_ms / 1000.0)
|
19
|
+
end
|
20
|
+
timer_for :do_something
|
21
|
+
count_for :do_something
|
22
|
+
|
23
|
+
def emit_events(count=30)
|
24
|
+
# Emit 100 events
|
25
|
+
count.times do
|
26
|
+
emit("event")
|
27
|
+
sleep(1)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def time_me
|
32
|
+
watch("timed") do |x|
|
33
|
+
sleep(10)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
binding.pry
|
data/hallmonitor.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
lib = File.expand_path('../lib', __FILE__)
|
6
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
7
|
+
require 'hallmonitor/version'
|
8
|
+
|
9
|
+
Gem::Specification.new do |s|
|
10
|
+
s.name = "hallmonitor"
|
11
|
+
s.version = Hallmonitor::Version::STRING
|
12
|
+
|
13
|
+
s.authors = ["Chris TenHarmsel"]
|
14
|
+
s.summary = "Simple Ruby Event Monitoring"
|
15
|
+
s.description = "Hallmonitor is a simple event monitoring framework in Ruby"
|
16
|
+
s.email = ["chris@tenharmsel.com"]
|
17
|
+
s.homepage = "http://github.com/epchris/hallmonitor"
|
18
|
+
s.licenses = ["MIT"]
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split($/)
|
21
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
22
|
+
s.require_paths = ["lib"]
|
23
|
+
|
24
|
+
s.add_runtime_dependency("json", [">= 0"])
|
25
|
+
s.add_runtime_dependency("statsd-ruby", [">= 0"])
|
26
|
+
s.add_development_dependency("shoulda", [">= 0"])
|
27
|
+
s.add_development_dependency("rdoc", [">= 0"])
|
28
|
+
s.add_development_dependency("bundler", ["~> 1.3"])
|
29
|
+
s.add_development_dependency("pry-debugger", [">= 0"])
|
30
|
+
s.add_development_dependency("rake", [">= 0"])
|
31
|
+
end
|
data/lib/hallmonitor.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'hallmonitor/monitored'
|
2
|
+
module Hallmonitor
|
3
|
+
##
|
4
|
+
# The event class is a single-fire event
|
5
|
+
class Event
|
6
|
+
include Hallmonitor::Monitored
|
7
|
+
|
8
|
+
attr_accessor :name, :time, :count
|
9
|
+
|
10
|
+
def initialize(name, count=1)
|
11
|
+
@name = name
|
12
|
+
@time = Time.now
|
13
|
+
@count = count
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_json(*a)
|
17
|
+
{
|
18
|
+
name: @name,
|
19
|
+
time: @time,
|
20
|
+
count: @count
|
21
|
+
}.to_json(*a)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'hallmonitor/outputter'
|
2
|
+
|
3
|
+
module Hallmonitor
|
4
|
+
class Middleware
|
5
|
+
def initialize(app)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
request = Rack::Request.new(env)
|
11
|
+
@event_base_name = "http.#{request.path_info.gsub('/', '.')}.#{request.request_method}"
|
12
|
+
if !request.path_info.match(/^\/?assets/)
|
13
|
+
@event = Hallmonitor::TimedEvent.new("#{@event_base_name}.response_time")
|
14
|
+
@event.start = Time.now
|
15
|
+
else
|
16
|
+
@event = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
response = @app.call(env)
|
20
|
+
|
21
|
+
if @event
|
22
|
+
@event.stop = Time.now
|
23
|
+
Hallmonitor::Outputter.output(@event)
|
24
|
+
Hallmonitor::Outputter.output(Hallmonitor::Event.new("#{@event_base_name}.count"))
|
25
|
+
end
|
26
|
+
response
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
##
|
2
|
+
# Include this module in classes where you want monitoring capabilities
|
3
|
+
module Hallmonitor
|
4
|
+
module Monitored
|
5
|
+
module ClassMethods
|
6
|
+
def timer_for(method_sym, options={})
|
7
|
+
metric_name = options[:metric_name] || "#{self.underscore(self.name)}.#{method_sym.to_s}.time"
|
8
|
+
self.send(:define_method, "#{method_sym.to_s}_with_hallmonitor_timer") do |*args|
|
9
|
+
watch(metric_name) do
|
10
|
+
self.send("#{method_sym.to_s}_without_hallmonitor_timer".to_sym, *args)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
alias_method "#{method_sym.to_s}_without_hallmonitor_timer".to_sym, method_sym
|
15
|
+
alias_method method_sym, "#{method_sym.to_s}_with_hallmonitor_timer".to_sym
|
16
|
+
end
|
17
|
+
|
18
|
+
def count_for(method_sym, options={})
|
19
|
+
metric_name = options[:metric_name] || "#{self.underscore(self.name)}.#{method_sym.to_s}.count"
|
20
|
+
self.send(:define_method, "#{method_sym.to_s}_with_hallmonitor_counter") do |*args|
|
21
|
+
emit(metric_name)
|
22
|
+
self.send("#{method_sym.to_s}_without_hallmonitor_counter".to_sym, *args)
|
23
|
+
end
|
24
|
+
|
25
|
+
alias_method "#{method_sym.to_s}_without_hallmonitor_counter".to_sym, method_sym
|
26
|
+
alias_method method_sym, "#{method_sym.to_s}_with_hallmonitor_counter".to_sym
|
27
|
+
end
|
28
|
+
|
29
|
+
def underscore(value)
|
30
|
+
word = value.dup
|
31
|
+
word.gsub!(/::/, '/')
|
32
|
+
word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
|
33
|
+
word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
|
34
|
+
word.tr!("-", "_")
|
35
|
+
word.downcase!
|
36
|
+
word
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.included(base)
|
41
|
+
base.extend(ClassMethods)
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# Emits an event: either self or an event if one is passed in, or constructs
|
46
|
+
# a base event from the passed in param
|
47
|
+
# If the parameter is a #Hallmonitor::Event, it will be emitted as is.
|
48
|
+
# Otherwise, a new Hallmonitor::Event will be created with the parameter and emitted.
|
49
|
+
def emit(event = nil)
|
50
|
+
to_emit = self;
|
51
|
+
if(!event.nil?)
|
52
|
+
to_emit = event.kind_of?(Hallmonitor::Event) ? event : Hallmonitor::Event.new(event)
|
53
|
+
end
|
54
|
+
|
55
|
+
# If we were given a block, then we want to execute that
|
56
|
+
if block_given?
|
57
|
+
yield(to_emit)
|
58
|
+
end
|
59
|
+
|
60
|
+
Outputter.output(to_emit)
|
61
|
+
end
|
62
|
+
|
63
|
+
##
|
64
|
+
# Executes and times a block of code and emits a Hallmonitor::TimedEvent
|
65
|
+
def watch(name)
|
66
|
+
event = Hallmonitor::TimedEvent.new(name)
|
67
|
+
event.start = Time.now
|
68
|
+
yield(event)
|
69
|
+
event.stop = Time.now
|
70
|
+
emit(event)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Hallmonitor
|
2
|
+
class Outputter
|
3
|
+
attr_reader :name
|
4
|
+
@@outputters = Array.new
|
5
|
+
|
6
|
+
def initialize(name)
|
7
|
+
raise(ArgumentError, "Outputter expects a name") if name.nil?
|
8
|
+
@name = name
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.add_outputter(outputter)
|
12
|
+
@@outputters << outputter if outputter.respond_to?(:process)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.output(event)
|
16
|
+
@@outputters.each do |o|
|
17
|
+
o.process(event)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def process(event)
|
22
|
+
# Nothing
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Hallmonitor
|
4
|
+
module Outputters
|
5
|
+
class IOOutputter < Outputter
|
6
|
+
|
7
|
+
def initialize(name, out)
|
8
|
+
super(name)
|
9
|
+
@out = out
|
10
|
+
end
|
11
|
+
|
12
|
+
def process(event)
|
13
|
+
begin
|
14
|
+
@out.print "EVENT: #{event.to_json}\n"
|
15
|
+
@out.flush
|
16
|
+
rescue IOError => e
|
17
|
+
close
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def close
|
23
|
+
@out.close unless @out.nil?
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
begin
|
2
|
+
require 'statsd'
|
3
|
+
rescue LoadError
|
4
|
+
end
|
5
|
+
|
6
|
+
module Hallmonitor
|
7
|
+
module Outputters
|
8
|
+
class StatsdOutputter < Outputter
|
9
|
+
def initialize(prefix, host="localhost", port=8125)
|
10
|
+
raise "In order to use StatsdOutputter, statsd gem must be installed" unless defined?(Statsd)
|
11
|
+
super(prefix)
|
12
|
+
@statsd = Statsd.new(host).tap{|sd| sd.namespace = name}
|
13
|
+
end
|
14
|
+
|
15
|
+
def process(event)
|
16
|
+
if(event.respond_to?(:duration))
|
17
|
+
@statsd.timing(event.name, event.duration)
|
18
|
+
elsif(event.respond_to?(:value))
|
19
|
+
@statsd.guage(event.name, event.value)
|
20
|
+
else
|
21
|
+
@statsd.count(event.name, event.count)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Hallmonitor
|
2
|
+
class TimedEvent < Event
|
3
|
+
attr_accessor :start, :stop
|
4
|
+
|
5
|
+
def initialize(name, duration=nil)
|
6
|
+
super(name)
|
7
|
+
@duration = duration
|
8
|
+
end
|
9
|
+
|
10
|
+
# Duration, should be set in ms, will take precedence over
|
11
|
+
# calculating via start and stop times
|
12
|
+
attr_writer :duration
|
13
|
+
|
14
|
+
# Reports duration of this timed event in ms
|
15
|
+
def duration
|
16
|
+
if @duration
|
17
|
+
@duration
|
18
|
+
elsif @start && @stop
|
19
|
+
(@stop - @start) * 1000
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_json(*a)
|
24
|
+
{
|
25
|
+
name: @name,
|
26
|
+
time: @time,
|
27
|
+
start: @start,
|
28
|
+
stop: @stop,
|
29
|
+
duration: self.duration
|
30
|
+
}.to_json(*a)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'hallmonitor'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class MonitoredTest < Test::Unit::TestCase
|
4
|
+
class TestMe
|
5
|
+
include Hallmonitor::Monitored
|
6
|
+
end
|
7
|
+
context "A class that includes Monitored module" do
|
8
|
+
|
9
|
+
setup do
|
10
|
+
@test_me = TestMe.new
|
11
|
+
end
|
12
|
+
|
13
|
+
should "add an emit method to instances" do
|
14
|
+
@test_me.respond_to?(:emit)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,187 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hallmonitor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Chris TenHarmsel
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-11-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: json
|
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: statsd-ruby
|
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: shoulda
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
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: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rdoc
|
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
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: bundler
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '1.3'
|
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.3'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: pry-debugger
|
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: rake
|
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: Hallmonitor is a simple event monitoring framework in Ruby
|
127
|
+
email:
|
128
|
+
- chris@tenharmsel.com
|
129
|
+
executables: []
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- .document
|
134
|
+
- .gitignore
|
135
|
+
- .rvmrc
|
136
|
+
- Gemfile
|
137
|
+
- LICENSE.txt
|
138
|
+
- README.md
|
139
|
+
- Rakefile
|
140
|
+
- bin/example.rb
|
141
|
+
- hallmonitor.gemspec
|
142
|
+
- lib/hallmonitor.rb
|
143
|
+
- lib/hallmonitor/event.rb
|
144
|
+
- lib/hallmonitor/gauge_event.rb
|
145
|
+
- lib/hallmonitor/middleware.rb
|
146
|
+
- lib/hallmonitor/monitored.rb
|
147
|
+
- lib/hallmonitor/outputter.rb
|
148
|
+
- lib/hallmonitor/outputters/iooutputter.rb
|
149
|
+
- lib/hallmonitor/outputters/statsd_outputter.rb
|
150
|
+
- lib/hallmonitor/timed_event.rb
|
151
|
+
- lib/hallmonitor/version.rb
|
152
|
+
- test/helper.rb
|
153
|
+
- test/monitored_test.rb
|
154
|
+
homepage: http://github.com/epchris/hallmonitor
|
155
|
+
licenses:
|
156
|
+
- MIT
|
157
|
+
post_install_message:
|
158
|
+
rdoc_options: []
|
159
|
+
require_paths:
|
160
|
+
- lib
|
161
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
162
|
+
none: false
|
163
|
+
requirements:
|
164
|
+
- - ! '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
segments:
|
168
|
+
- 0
|
169
|
+
hash: -2588159144270088520
|
170
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
171
|
+
none: false
|
172
|
+
requirements:
|
173
|
+
- - ! '>='
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
version: '0'
|
176
|
+
segments:
|
177
|
+
- 0
|
178
|
+
hash: -2588159144270088520
|
179
|
+
requirements: []
|
180
|
+
rubyforge_project:
|
181
|
+
rubygems_version: 1.8.23
|
182
|
+
signing_key:
|
183
|
+
specification_version: 3
|
184
|
+
summary: Simple Ruby Event Monitoring
|
185
|
+
test_files:
|
186
|
+
- test/helper.rb
|
187
|
+
- test/monitored_test.rb
|