wrangling logs with logstash and elasticsearchassets.en.oreilly.com/1/event/80/wrangling logs with...

38
Wrangling Logs with Logstash and ElasticSearch Nate Jones & David Castro Media Temple OSCON 2012 Thursday, July 19, 12

Upload: nguyentuyen

Post on 12-Feb-2018

258 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: Wrangling Logs with Logstash and ElasticSearchassets.en.oreilly.com/1/event/80/Wrangling Logs with Logstash and... · Wrangling Logs with Logstash and ElasticSearch Nate Jones & David

Wrangling Logs withLogstash and ElasticSearch

Nate Jones & David Castro

Media Temple

OSCON 2012

Thursday, July 19, 12

Page 2: Wrangling Logs with Logstash and ElasticSearchassets.en.oreilly.com/1/event/80/Wrangling Logs with Logstash and... · Wrangling Logs with Logstash and ElasticSearch Nate Jones & David

Why are we here?

Thursday, July 19, 12

Page 3: Wrangling Logs with Logstash and ElasticSearchassets.en.oreilly.com/1/event/80/Wrangling Logs with Logstash and... · Wrangling Logs with Logstash and ElasticSearch Nate Jones & David

Size

EfficiencyQuantity

Thursday, July 19, 12

Page 4: Wrangling Logs with Logstash and ElasticSearchassets.en.oreilly.com/1/event/80/Wrangling Logs with Logstash and... · Wrangling Logs with Logstash and ElasticSearch Nate Jones & David

Access

Locality Method Filtering

Thursday, July 19, 12

Page 5: Wrangling Logs with Logstash and ElasticSearchassets.en.oreilly.com/1/event/80/Wrangling Logs with Logstash and... · Wrangling Logs with Logstash and ElasticSearch Nate Jones & David

Grokability

Noise Structure Metrics

Thursday, July 19, 12

Page 6: Wrangling Logs with Logstash and ElasticSearchassets.en.oreilly.com/1/event/80/Wrangling Logs with Logstash and... · Wrangling Logs with Logstash and ElasticSearch Nate Jones & David

Use Case:Mail Logs

Thursday, July 19, 12

Page 7: Wrangling Logs with Logstash and ElasticSearchassets.en.oreilly.com/1/event/80/Wrangling Logs with Logstash and... · Wrangling Logs with Logstash and ElasticSearch Nate Jones & David

Size30 mail servers

2G logs / day / server

60GB / day total

1.8 TB / month

21 TB / year

1 billion log lines per week

Thursday, July 19, 12

Page 8: Wrangling Logs with Logstash and ElasticSearchassets.en.oreilly.com/1/event/80/Wrangling Logs with Logstash and... · Wrangling Logs with Logstash and ElasticSearch Nate Jones & David

AccessFront-line, easy access

No SSH

Shareable

Thursday, July 19, 12

Page 9: Wrangling Logs with Logstash and ElasticSearchassets.en.oreilly.com/1/event/80/Wrangling Logs with Logstash and... · Wrangling Logs with Logstash and ElasticSearch Nate Jones & David

GrokabilityOperationalDid the email get delivered?Why was the message marked as SPAM?Are messages being rejected?

MetricsWhat's the inbound/outbound message rate?How often are we seeing particular errors?

Thursday, July 19, 12

Page 10: Wrangling Logs with Logstash and ElasticSearchassets.en.oreilly.com/1/event/80/Wrangling Logs with Logstash and... · Wrangling Logs with Logstash and ElasticSearch Nate Jones & David

The Solution

Thursday, July 19, 12

Page 11: Wrangling Logs with Logstash and ElasticSearchassets.en.oreilly.com/1/event/80/Wrangling Logs with Logstash and... · Wrangling Logs with Logstash and ElasticSearch Nate Jones & David

Overview

Thursday, July 19, 12

Page 12: Wrangling Logs with Logstash and ElasticSearchassets.en.oreilly.com/1/event/80/Wrangling Logs with Logstash and... · Wrangling Logs with Logstash and ElasticSearch Nate Jones & David

Overview

Thursday, July 19, 12

Page 13: Wrangling Logs with Logstash and ElasticSearchassets.en.oreilly.com/1/event/80/Wrangling Logs with Logstash and... · Wrangling Logs with Logstash and ElasticSearch Nate Jones & David

Logstash Overviewhttp://logsta.sh/

1. Parse log line

2. Transform/extract

3. Structure and send JSON

Thursday, July 19, 12

Page 14: Wrangling Logs with Logstash and ElasticSearchassets.en.oreilly.com/1/event/80/Wrangling Logs with Logstash and... · Wrangling Logs with Logstash and ElasticSearch Nate Jones & David

Logstash ParsingLog line input2012-07-10T20:00:02.446220-04:00 mail01 spamd[2478]: spamd: clean message (-3.4/5.0) for nobody:93 in 0.0 seconds, 886 bytes.

JSON output{ "@timestamp" : "2012-07-16T06:44:00.548000Z", "@tags" : [], "@fields" : {}, "@source_path" : "/client/127.0.0.1:40010", "@source" : "tcp://0.0.0.0:6999/client/127.0.0.1:40010", "@source_host" : "0.0.0.0", "@message" : "2012-07-10T20:00:02.446220-04:00 mail01 spamd[2478]: spamd: clean message (-3.4/5.0) for nobody:93 in 0.0 seconds, 886 bytes.", "@type" : "maillog"}

Thursday, July 19, 12

Page 15: Wrangling Logs with Logstash and ElasticSearchassets.en.oreilly.com/1/event/80/Wrangling Logs with Logstash and... · Wrangling Logs with Logstash and ElasticSearch Nate Jones & David

grok { type => "maillog" pattern => "%{TIMESTAMP_ISO8601:timestamp} %{WORD:host} %{SYSLOGPROG:service}: %{GREEDYDATA:message}"}mutate { type => "maillog" # replace the timestamp, correcting import timestamp replace => ["@timestamp", "%{timestamp}"] # replace the message sans-timestamp/host/service replace => ["@message", "%{message}"]}

Logstash Parsing

Thursday, July 19, 12

Page 16: Wrangling Logs with Logstash and ElasticSearchassets.en.oreilly.com/1/event/80/Wrangling Logs with Logstash and... · Wrangling Logs with Logstash and ElasticSearch Nate Jones & David

{ "@timestamp" : "2012-07-10T20:00:02.446220-04:00", "@tags" : [], "@fields" : { "pid" : [ "2478" ], "service" : [ "spamd[2478]" ], "program" : [ "spamd" ], "host" : [ "mail01" ] }, "@source_path" : "/client/127.0.0.1:39998", "@source" : "tcp://0.0.0.0:6999/client/127.0.0.1:39998", "@source_host" : "0.0.0.0", "@message" : "spamd: clean message (-3.4/5.0) for nobody:93 in 0.0 seconds, 886 bytes.", "@type" : "maillog"}

Logstash Parsing

Thursday, July 19, 12

Page 17: Wrangling Logs with Logstash and ElasticSearchassets.en.oreilly.com/1/event/80/Wrangling Logs with Logstash and... · Wrangling Logs with Logstash and ElasticSearch Nate Jones & David

RabbitMQ Overviewhttp://www.rabbitmq.com/

Message Queue

AMQP

Clustered

Thursday, July 19, 12

Page 18: Wrangling Logs with Logstash and ElasticSearchassets.en.oreilly.com/1/event/80/Wrangling Logs with Logstash and... · Wrangling Logs with Logstash and ElasticSearch Nate Jones & David

Elasticsearch Introhttp://www.elasticsearch.org/

Index in Lucene shards

Cluster-able

Fault tolerant

Thursday, July 19, 12

Page 19: Wrangling Logs with Logstash and ElasticSearchassets.en.oreilly.com/1/event/80/Wrangling Logs with Logstash and... · Wrangling Logs with Logstash and ElasticSearch Nate Jones & David

Elasticsearch Head

Thursday, July 19, 12

Page 20: Wrangling Logs with Logstash and ElasticSearchassets.en.oreilly.com/1/event/80/Wrangling Logs with Logstash and... · Wrangling Logs with Logstash and ElasticSearch Nate Jones & David

Elasticsearch Browser

Thursday, July 19, 12

Page 21: Wrangling Logs with Logstash and ElasticSearchassets.en.oreilly.com/1/event/80/Wrangling Logs with Logstash and... · Wrangling Logs with Logstash and ElasticSearch Nate Jones & David

Kibana Introhttp://rashidkpc.github.com/Kibana/

User friendly front-end to elasticsearch

Search log lines

Graph, score, trend

Streaming dashboard

Thursday, July 19, 12

Page 22: Wrangling Logs with Logstash and ElasticSearchassets.en.oreilly.com/1/event/80/Wrangling Logs with Logstash and... · Wrangling Logs with Logstash and ElasticSearch Nate Jones & David

Kibana Queries

QuestionHow many errors of a particular type are we seeing in the logs?

Query@message:"Permission Denied"

Thursday, July 19, 12

Page 23: Wrangling Logs with Logstash and ElasticSearchassets.en.oreilly.com/1/event/80/Wrangling Logs with Logstash and... · Wrangling Logs with Logstash and ElasticSearch Nate Jones & David

Kibana Queries

Thursday, July 19, 12

Page 24: Wrangling Logs with Logstash and ElasticSearchassets.en.oreilly.com/1/event/80/Wrangling Logs with Logstash and... · Wrangling Logs with Logstash and ElasticSearch Nate Jones & David

QuestionWhy did the mail for user X get marked as SPAM?

Query@message:"domain.com" AND @message:"X-SPAM"

Kibana Queries

Thursday, July 19, 12

Page 25: Wrangling Logs with Logstash and ElasticSearchassets.en.oreilly.com/1/event/80/Wrangling Logs with Logstash and... · Wrangling Logs with Logstash and ElasticSearch Nate Jones & David

Kibana Queries

Thursday, July 19, 12

Page 26: Wrangling Logs with Logstash and ElasticSearchassets.en.oreilly.com/1/event/80/Wrangling Logs with Logstash and... · Wrangling Logs with Logstash and ElasticSearch Nate Jones & David

QuestionHow many messages are being rejected due to the sending host being listed in an RBL?

Query@message:"zen.spamhaus.org"

Kibana Queries

Thursday, July 19, 12

Page 27: Wrangling Logs with Logstash and ElasticSearchassets.en.oreilly.com/1/event/80/Wrangling Logs with Logstash and... · Wrangling Logs with Logstash and ElasticSearch Nate Jones & David

Kibana Queries

Thursday, July 19, 12

Page 28: Wrangling Logs with Logstash and ElasticSearchassets.en.oreilly.com/1/event/80/Wrangling Logs with Logstash and... · Wrangling Logs with Logstash and ElasticSearch Nate Jones & David

QuestionHow many log messages do we have for a specific mail host?

Query@source_host:"n31"

Kibana Queries

Thursday, July 19, 12

Page 29: Wrangling Logs with Logstash and ElasticSearchassets.en.oreilly.com/1/event/80/Wrangling Logs with Logstash and... · Wrangling Logs with Logstash and ElasticSearch Nate Jones & David

Kibana Queries

Thursday, July 19, 12

Page 30: Wrangling Logs with Logstash and ElasticSearchassets.en.oreilly.com/1/event/80/Wrangling Logs with Logstash and... · Wrangling Logs with Logstash and ElasticSearch Nate Jones & David

Report Card

Thursday, July 19, 12

Page 31: Wrangling Logs with Logstash and ElasticSearchassets.en.oreilly.com/1/event/80/Wrangling Logs with Logstash and... · Wrangling Logs with Logstash and ElasticSearch Nate Jones & David

Size

EfficiencyQuantity

Thursday, July 19, 12

Page 32: Wrangling Logs with Logstash and ElasticSearchassets.en.oreilly.com/1/event/80/Wrangling Logs with Logstash and... · Wrangling Logs with Logstash and ElasticSearch Nate Jones & David

Access

Locality Method Filtering

Thursday, July 19, 12

Page 33: Wrangling Logs with Logstash and ElasticSearchassets.en.oreilly.com/1/event/80/Wrangling Logs with Logstash and... · Wrangling Logs with Logstash and ElasticSearch Nate Jones & David

Grokability

Noise Structure Metrics

Thursday, July 19, 12

Page 34: Wrangling Logs with Logstash and ElasticSearchassets.en.oreilly.com/1/event/80/Wrangling Logs with Logstash and... · Wrangling Logs with Logstash and ElasticSearch Nate Jones & David

Next Steps

Push more stats into graphite

Further breaking down log messages

More stuff

Thursday, July 19, 12

Page 35: Wrangling Logs with Logstash and ElasticSearchassets.en.oreilly.com/1/event/80/Wrangling Logs with Logstash and... · Wrangling Logs with Logstash and ElasticSearch Nate Jones & David

Everything you needInstructions and softwarehttp://logwrangler.mtcode.com/

Puppet code and slideshttp://github.com/mediatemple/logwrangler

Local wifi share: logwrangler (guest/guest)

Thursday, July 19, 12

Page 36: Wrangling Logs with Logstash and ElasticSearchassets.en.oreilly.com/1/event/80/Wrangling Logs with Logstash and... · Wrangling Logs with Logstash and ElasticSearch Nate Jones & David

DemoNetcat port for Logstash

RabbitMQ

Elasticsearch

Kibana

Thursday, July 19, 12

Page 38: Wrangling Logs with Logstash and ElasticSearchassets.en.oreilly.com/1/event/80/Wrangling Logs with Logstash and... · Wrangling Logs with Logstash and ElasticSearch Nate Jones & David

Questions?

Thursday, July 19, 12