Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f9080d1
commit 4148694
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env ruby | ||
# encoding: UTF-8 | ||
|
||
## | ||
## Consuming data from the event stream (zmq subscriber): | ||
## MaxValueTracker will track and display the metric with the highest value. | ||
## | ||
|
||
require 'bundler' | ||
Bundler.require :server | ||
require 'time' | ||
|
||
class MaxValueTracker | ||
def initialize | ||
@max = 0 | ||
end | ||
|
||
def on_readable(socket, messages) | ||
messages.each {|msg| process *msg.copy_out_string.split(' ') } | ||
end | ||
|
||
def process(channel, metric_in_json) | ||
metric = JSON.parse(metric_in_json) | ||
|
||
if metric['value'] > @max | ||
@max = metric['value'] | ||
p [:NEW_MAXIMUM, metric] | ||
end | ||
end | ||
end | ||
|
||
ctx = EM::ZeroMQ::Context.new(1) | ||
EM::run do | ||
socket = ctx.socket ZMQ::SUB, MaxValueTracker.new | ||
socket.identity = "tracker-#{Process.pid}" | ||
socket.connect "tcp://127.0.0.1:8890" | ||
socket.subscribe 'metric' | ||
end |