This document discusses monitoring systems using syslog and EventMachine. It proposes building a lightweight, polyglot system that aggregates syslog events and displays metrics and visualizations using various protocols like WebSockets, Server-Sent Events, and Graphite. Event sources would send syslog messages which an EventMachine server would parse and pass to an EM:Channel. A JavaScript client could subscribe to the channel for real-time updates.
8. monitor |ˈmänəәtəәr|
verb [ with obj. ]
observe and check the progress or
quality of (something) over a period of
time; keep under systematic review:
equipment was installed to monitor air quality.
Oxford Dictionary
44. Syslog
• Standard logging solution for Unix/Linux
• Facility (daemon, cron, user, local0, etc.)
• Priority/Level (Alert, Critical, Error,
Warning, etc.)
• Client and server
• Since 1980
45. ... It also provides devices which
would otherwise be unable to
communicate a means to notify
administrators of problems or
performance.
http://en.wikipedia.org/wiki/Syslog
46. Syslog Format
Date Hostname Program : Message
Jan 1 12:12:12 10.245.3.99 foo[421] : this is a message
60. require 'em-websocket'
EM.run do
channel = EM::Channel.new
options = {:host => "0.0.0.0", :port => 8080}
EM::WebSocket.start(options) do |ws|
ws.onopen do
sid = channel.subscribe{|msg| ws.send msg}
end
ws.onclose do
channel.unsubscribe(sid)
end
end
end
61. Pass on
EM:Channel
EM.run {
channel = EM::Channel.new
# define your websocket server here
# start udp server
host = "127.0.0.1"
port = "3000"
# pass in the channel to the data handler
EM::open_datagram_socket(host, port, Handler,
channel)
}
62. New Handler
class Handler < EM::Connection
def initialize(*args)
@channel = args[0]
@counter = 0
super *args
end
def receive_data(data)
if data && data.size > 0
@counter += 1
@channel.push(@counter)
end
end
end
63. JavaScript
var socket;
var host = "ws://localhost:8080";
var socket = new WebSocket(host);
socket.onopen = function(){
console.log('open');
}
socket.onmessage = function(msg){
console.log(msg.data);
}
socket.onclose = function(){
console.log('closed');
}