+ All Categories
Home > Technology > Monitoring with Syslog and EventMachine (RailswayConf 2012)

Monitoring with Syslog and EventMachine (RailswayConf 2012)

Date post: 14-May-2015
Category:
Upload: wooga
View: 2,527 times
Download: 2 times
Share this document with a friend
Popular Tags:
79
Monitoring with Syslog and EventMachine
Transcript
Page 1: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Monitoring with Syslog and

EventMachine

Page 2: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

"It’s up doesn’t mean it’s working"

Page 3: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Monitoring

Page 4: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

dashboards/monitoring

Page 5: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

sketching

dashboards/monitoring

Page 6: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

sketching

dashboards/monitoring

building

Page 7: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

sketching

dashboards/monitoring

building

outlook

Page 8: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Dashboards

Page 9: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)
Page 10: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)
Page 11: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)
Page 12: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)
Page 13: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Motivation

Page 14: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Moving Target

Page 15: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Failure is always an option

Page 16: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)
Page 17: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

“Since the last deploy, the number of signup errors has gone up by 300 %. We might have

broken something.”

Page 18: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)
Page 19: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Counting Things

Page 20: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Concurrent Users

Page 21: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Signups

Page 22: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Logins

Page 23: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Errors

Page 24: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Sketch it

Page 25: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Application Server

Application Server

Application Server

Event Aggregation

Dashboard

Page 26: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Criteria

Page 27: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Simple

Page 28: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Polyglot

Page 29: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Fire And Forget

Page 30: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Simple/Lightweight

Polyglot

Fire and Forget

Criteria

Page 31: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Background story

Page 32: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)
Page 33: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Not Supported

node.js NewRelic RPM

erlang NewRelic RPM

Page 34: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

haproxy

node.js node.js node.js

Load Balancer

Page 35: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

haproxy logs

haproxy[674]: 127.0.0.1:33320 [15/Oct/2003:08:32:17.654] px-http \  px-http/srv1 9/0/7/14/+30 200 +243 - - ---- 3/3/3/1/0 0/0 \  "GET /image.iso HTTP/1.0"

Page 36: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

haproxycustom syslog

server

New Relic

send logs

NewRelic Ruby Agent

Page 37: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

haproxy!rpm

http://github.com/wooga/haproxy2rpm

Page 38: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)
Page 39: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Syslog

Page 40: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

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

Page 41: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

... 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

Page 42: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Syslog Format

Date Hostname Program Message

Jan 1 12:12:12 10.245.3.99 foo[421] : this is a message

:

Page 43: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Syslog client

# man loggerlogger -p local0.notice -t HOSTIDM My Message

Page 44: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

UDP

Page 45: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Fire And Forget

Page 46: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Simple/Lightweight

Polyglot

Fire and Forget

Page 47: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Simple/Lightweight

Polyglot

Fire and Forget

Page 48: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Simple/Lightweight

Polyglot

Fire and Forget

Page 49: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Simple/Lightweight

Polyglot

Fire and Forget

Page 50: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Build it

Page 51: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Event Emitter

Dashboard

Event Aggregatorsend message

UDP : 514

Page 52: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Event Emitter Syslog

Dashboard Event Aggregator

send message

UDP : 514

forward

Page 53: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Emitting Eventsrequire 'syslog'

def log(message, level = :warning)  script_name = $0  syslog_option = Syslog::LOG_PID | Syslog::LOG_CONS  Syslog.open($0, syslog_option) do |s|    s.send(level, message)  endend

Page 54: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Server

• Listen on UDP

• receive and parse syslog messages

• update a counter

• push it out to dashboards

Page 55: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Serverclass UdpServer

HOST = '127.0.0.1' PORT = '3333'

def self.run EM::open_datagram_socket(HOST, PORT, Handler) endend

Page 56: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Handlerrequire 'eventmachine'

class Handler < EM::Connection def receive_data(data) puts "Received event: #{data.inspect}" puts SyslogParser.parse(data) endend

Page 58: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Web App

Page 59: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Event Source

Page 60: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Event Source Format

data: Hello dashboard\n\nevent: userlogon\ndata: {"username": "John123"}\n\nevent: update\ndata: {"username": "John123", "foo": "bar"}\n\n

Page 61: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Sinatrarequire 'sinatra'

get '/stream' do content_type 'text/event-stream' stream(:keep_open) do |out| endend

Page 62: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

class WebApp < Sinatra::Base

def self.connections @connections ||= [] end

get '/stream' do content_type 'text/event-stream' stream(:keep_open) do |out| WebApp.connections << out end endend

Page 63: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

class WebApp < Sinatra::Base # send the message to all clients def self.send_event(event = {}) connections.each do |c| if c.closed connections.delete(c) else c << "event: #{event[:event]}\n" c << "data: #{event[:data]}\n\n" end end end # here go sinatra routes ...end

Page 64: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

# disable sinatra's autorundisable :run

EM.run do WebApp.run! UdpServer.run Signal.trap("INT") { EventMachine.stop } Signal.trap("TERM") { EventMachine.stop }end

Page 65: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

View

Page 66: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

// Open up an event source socketvar source = new EventSource('/stream');

source.addEventListener('message', function(e) { console.log("message:" + e.data); }, false);

source.addEventListener('open', function(e) { console.log('event source opened:' + e); }, false);

source.addEventListener('error', function(e) { console.log('received an error:' + e); }, false);

EventSource Basics

Page 67: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Custom Eventssource.addEventListener('login', function(e) { console.log("login: " + e.data);}, false);

source.addEventListener('loginError', function(e) { console.log("login error: " + e.data);}, false);

Page 68: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Testingrequire 'socket'

desc 'send test data'task :send_test_data do socket = UDPSocket.new host = "127.0.0.1" port = "3333" events = ["message", "login", "loginError"]

while true do random_index = random_index(0..2) random_value = rand(0..1000) message = "#{events[random_index]}:#{random_value}" socket.send(message, 0, host, port sleep(1) endend

Page 70: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Missing features

• Persistency

• Querying

• More complex aggregations (avg, timers, etc.)

• Fancy visualization

Page 71: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)
Page 72: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Existing Solutions

• https://github.com/etsy/statsd

• https://github.com/noahhl/batsd

• https://github.com/eric/metriks

• http://square.github.com/cube/

Page 73: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Graphitehttp://graphite.wikidot.com/screen-shots

Page 75: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Monitor all the things!!!!

Page 76: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

wooga.com/jobs

WANTEDdead or alive

REWARD

www.wooga.com/ jobs/

BACKEND DEVELOPER

Page 78: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

Slideshttp://www.slideshare.net/wooga

Page 79: Monitoring  with  Syslog and EventMachine (RailswayConf 2012)

CreditsCliff (Flickr)

!"#K (Flickr)

Scott Kidder (Flickr)


Recommended