drone_json 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 +4 -0
- data/Gemfile +6 -0
- data/LICENSE +20 -0
- data/README.md +9 -0
- data/Rakefile +2 -0
- data/drone_json.gemspec +34 -0
- data/examples/json.rb +51 -0
- data/lib/drone_json/json.rb +98 -0
- data/lib/drone_json/version.rb +3 -0
- data/lib/drone_json.rb +8 -0
- data/specs/common.rb +63 -0
- metadata +142 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011-2011 Julien Ammous
|
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
data/Rakefile
ADDED
data/drone_json.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "drone_json/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "drone_json"
|
7
|
+
s.version = DroneJson::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Julien Ammous"]
|
10
|
+
s.email = []
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{Drone Interface}
|
13
|
+
s.description = %q{JSON Interface for Drone}
|
14
|
+
|
15
|
+
s.rubyforge_project = "drone_json"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency('drone')
|
23
|
+
s.add_dependency('thin')
|
24
|
+
|
25
|
+
if RUBY_VERSION < "1.9.1"
|
26
|
+
s.add_dependency('json')
|
27
|
+
end
|
28
|
+
|
29
|
+
s.add_development_dependency("mocha")
|
30
|
+
s.add_development_dependency("bacon")
|
31
|
+
s.add_development_dependency("schmurfy-em-spec")
|
32
|
+
s.add_development_dependency("delorean")
|
33
|
+
s.add_development_dependency("simplecov")
|
34
|
+
end
|
data/examples/json.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'drone'
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
|
6
|
+
require 'drone_json'
|
7
|
+
|
8
|
+
|
9
|
+
Drone::init_drone()
|
10
|
+
Drone::register_gauge("cpu:0/user"){ rand(200) }
|
11
|
+
|
12
|
+
class User
|
13
|
+
include Drone::Monitoring
|
14
|
+
|
15
|
+
def initialize(name)
|
16
|
+
@name = name
|
17
|
+
end
|
18
|
+
|
19
|
+
monitor_rate("users:rename")
|
20
|
+
def rename(new_name)
|
21
|
+
@name = new_name
|
22
|
+
end
|
23
|
+
|
24
|
+
monitor_time("users:do_something")
|
25
|
+
def do_something
|
26
|
+
# just eat some cpu
|
27
|
+
0.upto(rand(2000)) do |n|
|
28
|
+
str = "a"
|
29
|
+
200.times{ str << "b" }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
EM::run do
|
35
|
+
Drone::add_output(:json, '127.0.0.1', 3001)
|
36
|
+
Drone::start_monitoring()
|
37
|
+
|
38
|
+
counter1 = Drone::register_counter("something_counted")
|
39
|
+
counter1.increment()
|
40
|
+
|
41
|
+
a = User.new("bob")
|
42
|
+
|
43
|
+
EM::add_periodic_timer(2) do
|
44
|
+
rand(100).times{|n| a.rename("user#{n}") }
|
45
|
+
counter1.increment()
|
46
|
+
end
|
47
|
+
|
48
|
+
EM::add_periodic_timer(1) do
|
49
|
+
a.do_something()
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'thin'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Drone
|
5
|
+
module Interfaces
|
6
|
+
|
7
|
+
class Json < Base
|
8
|
+
def initialize(address = '0.0.0.0', port = 3001)
|
9
|
+
me = self
|
10
|
+
Thin::Server.start(address, port) do
|
11
|
+
map('/'){ run(me) }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
ret = {}
|
17
|
+
|
18
|
+
Drone::each_metric do |m|
|
19
|
+
case m
|
20
|
+
when Metrics::Gauge
|
21
|
+
ret[m.name] = gauge_hash(m)
|
22
|
+
|
23
|
+
when Metrics::Counter
|
24
|
+
ret[m.name] = counter_hash(m)
|
25
|
+
|
26
|
+
when Metrics::Timer
|
27
|
+
tmp = {
|
28
|
+
'type' => 'timer'
|
29
|
+
}
|
30
|
+
|
31
|
+
tmp = histogram_hash(m, tmp)
|
32
|
+
|
33
|
+
ret[m.name] = tmp
|
34
|
+
|
35
|
+
when Metrics::Meter
|
36
|
+
ret[m.name] = meter_hash(m, { 'type' => 'meter' })
|
37
|
+
|
38
|
+
when Metrics::Histogram
|
39
|
+
ret[m.name] = histogram_hash(m, { 'type' => 'histogram' })
|
40
|
+
|
41
|
+
else
|
42
|
+
puts "Unknown metric: #{m}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
[
|
48
|
+
200,
|
49
|
+
{'Content-Type' => 'application/json'},
|
50
|
+
ret.to_json
|
51
|
+
]
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
def gauge_hash(m)
|
56
|
+
{
|
57
|
+
'type' => 'gauge',
|
58
|
+
'value' => m.value
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
def counter_hash(m)
|
63
|
+
{
|
64
|
+
'type' => 'counter',
|
65
|
+
'value' => m.value
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
def meter_hash(m, h = {})
|
70
|
+
h.merge({
|
71
|
+
'count' => m.count,
|
72
|
+
'mean_rate' => m.mean_rate,
|
73
|
+
'rate_1' => m.one_minute_rate,
|
74
|
+
'rate_5' => m.five_minutes_rate,
|
75
|
+
'rate_15' => m.fifteen_minutes_rate
|
76
|
+
})
|
77
|
+
end
|
78
|
+
|
79
|
+
def histogram_hash(m, h = {})
|
80
|
+
percentiles = m.percentiles(0.5, 0.75, 0.95, 0.98, 0.99, 0.999)
|
81
|
+
|
82
|
+
h.merge({
|
83
|
+
'min' => m.min,
|
84
|
+
'max' => m.max,
|
85
|
+
'mean' => m.mean,
|
86
|
+
'stddev' => m.stdDev,
|
87
|
+
'median' => percentiles[0],
|
88
|
+
'75p' => percentiles[1],
|
89
|
+
'95p' => percentiles[2],
|
90
|
+
'98p' => percentiles[3],
|
91
|
+
'99p' => percentiles[4],
|
92
|
+
'999p' => percentiles[5]
|
93
|
+
})
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|
data/lib/drone_json.rb
ADDED
data/specs/common.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
$:.reject! { |e| e.include? 'TextMate' }
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
|
5
|
+
puts "Testing with ruby #{RUBY_VERSION} and rubygems #{Gem::VERSION}"
|
6
|
+
|
7
|
+
require 'bundler/setup'
|
8
|
+
|
9
|
+
if (RUBY_VERSION >= "1.9") && ENV['COVERAGE']
|
10
|
+
require 'simplecov'
|
11
|
+
ROOT = File.expand_path('../../', __FILE__)
|
12
|
+
|
13
|
+
puts "[[ SimpleCov enabled ]]"
|
14
|
+
|
15
|
+
SimpleCov.start do
|
16
|
+
add_filter '/gems/'
|
17
|
+
add_filter '/specs/'
|
18
|
+
|
19
|
+
root(ROOT)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'bacon'
|
24
|
+
require 'mocha'
|
25
|
+
require 'delorean'
|
26
|
+
require 'em-spec/bacon'
|
27
|
+
EM.spec_backend = EventMachine::Spec::Bacon
|
28
|
+
|
29
|
+
$LOAD_PATH << File.expand_path('../../lib', __FILE__)
|
30
|
+
|
31
|
+
module Bacon
|
32
|
+
module MochaRequirementsCounter
|
33
|
+
def self.increment
|
34
|
+
Counter[:requirements] += 1
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class Context
|
39
|
+
include Mocha::API
|
40
|
+
|
41
|
+
alias_method :it_before_mocha, :it
|
42
|
+
|
43
|
+
def it(description)
|
44
|
+
it_before_mocha(description) do
|
45
|
+
begin
|
46
|
+
mocha_setup
|
47
|
+
yield
|
48
|
+
mocha_verify(MochaRequirementsCounter)
|
49
|
+
rescue Mocha::ExpectationError => e
|
50
|
+
raise Error.new(:failed, "#{e.message}\n#{e.backtrace[0...10].join("\n")}")
|
51
|
+
ensure
|
52
|
+
mocha_teardown
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def focus(test_label)
|
60
|
+
Bacon.const_set(:RestrictName, %r{#{test_label}})
|
61
|
+
end
|
62
|
+
|
63
|
+
Bacon.summary_on_exit()
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: drone_json
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Julien Ammous
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-04-21 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: drone
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: thin
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0"
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: mocha
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id003
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: bacon
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
type: :development
|
58
|
+
version_requirements: *id004
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: schmurfy-em-spec
|
61
|
+
prerelease: false
|
62
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
type: :development
|
69
|
+
version_requirements: *id005
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: delorean
|
72
|
+
prerelease: false
|
73
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: "0"
|
79
|
+
type: :development
|
80
|
+
version_requirements: *id006
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: simplecov
|
83
|
+
prerelease: false
|
84
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: "0"
|
90
|
+
type: :development
|
91
|
+
version_requirements: *id007
|
92
|
+
description: JSON Interface for Drone
|
93
|
+
email: []
|
94
|
+
|
95
|
+
executables: []
|
96
|
+
|
97
|
+
extensions: []
|
98
|
+
|
99
|
+
extra_rdoc_files: []
|
100
|
+
|
101
|
+
files:
|
102
|
+
- .gitignore
|
103
|
+
- Gemfile
|
104
|
+
- LICENSE
|
105
|
+
- README.md
|
106
|
+
- Rakefile
|
107
|
+
- drone_json.gemspec
|
108
|
+
- examples/json.rb
|
109
|
+
- lib/drone_json.rb
|
110
|
+
- lib/drone_json/json.rb
|
111
|
+
- lib/drone_json/version.rb
|
112
|
+
- specs/common.rb
|
113
|
+
homepage: ""
|
114
|
+
licenses: []
|
115
|
+
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: "0"
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
none: false
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: "0"
|
133
|
+
requirements: []
|
134
|
+
|
135
|
+
rubyforge_project: drone_json
|
136
|
+
rubygems_version: 1.7.2
|
137
|
+
signing_key:
|
138
|
+
specification_version: 3
|
139
|
+
summary: Drone Interface
|
140
|
+
test_files: []
|
141
|
+
|
142
|
+
has_rdoc:
|