Class: Drone::Interfaces::Json
- Inherits:
-
Base
- Object
- Base
- Drone::Interfaces::Json
- Defined in:
- lib/drone_json/json.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(address = '0.0.0.0', port = 3001) ⇒ Json
constructor
A new instance of Json.
Constructor Details
#initialize(address = '0.0.0.0', port = 3001) ⇒ Json
Returns a new instance of Json.
10 11 12 13 14 15 |
# File 'lib/drone_json/json.rb', line 10 def initialize(address = '0.0.0.0', port = 3001) me = self Thin::Server.start(address, port) do map('/'){ run(me) } end end |
Instance Method Details
#call(env) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/drone_json/json.rb', line 17 def call(env) ret = {} Drone::each_metric do |m| case m when Metrics::Gauge ret[m.name] = gauge_hash(m) when Metrics::Counter ret[m.name] = counter_hash(m) when Metrics::Timer tmp = { 'type' => 'timer' } tmp = histogram_hash(m, tmp) ret[m.name] = tmp when Metrics::Meter ret[m.name] = meter_hash(m, { 'type' => 'meter' }) when Metrics::Histogram ret[m.name] = histogram_hash(m, { 'type' => 'histogram' }) else puts "Unknown metric: #{m}" end end [ 200, {'Content-Type' => 'application/json'}, ret.to_json ] end |