78
So, logging! 1

Keep an eye on your app with logging and graphs - PHPBenelux 2014

Embed Size (px)

DESCRIPTION

Logging, metrics and graphs are often an afterthought. This usually becomes painfully clear when something goes wrong and you feel like you're running in the dark with a blindfold on. You need to know what's going on in your application! We're going to have a deeper look at tools like logstash, statsd and friends to see how they can help developers and the business as a whole. You'll fix problems quicker and will gain more insights in how your application is doing.

Citation preview

Page 1: Keep an eye on your app with logging and graphs - PHPBenelux 2014

So, logging!

!1

Page 2: Keep an eye on your app with logging and graphs - PHPBenelux 2014

http://www.egeniq.com [email protected]

@egeniq

PHPBenelux 2014Felix De Vliegher

Keep an eye on your app with logging and graphs

Page 3: Keep an eye on your app with logging and graphs - PHPBenelux 2014

• Back-end developer

• Sysadmin

• <3 APIs

• Travelling

• @felixdv

About me

!3

Page 4: Keep an eye on your app with logging and graphs - PHPBenelux 2014

About me

!4

Page 5: Keep an eye on your app with logging and graphs - PHPBenelux 2014

About me

!5

Page 6: Keep an eye on your app with logging and graphs - PHPBenelux 2014

About me

!6

Page 7: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Logging shows what exactly happens in your app. !

Metrics show the impact

Terminology

!7

Page 8: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Logging shows what exactly happens in your app. !

Metrics show the impact

Terminology

!8

Page 9: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Both are important (but for different reasons)

!9

Page 10: Keep an eye on your app with logging and graphs - PHPBenelux 2014

What is this talk about?

Knowing what is going on in your application!

!10

Page 11: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Questionnaire

• Who uses logging in their app?

• Aggregation, filtering, manipulation?

• Who collects metrics?

• Who visualises this data in a dashboard?

• Metric correlations?

!11

Page 12: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Logging

!12

Page 13: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Ye olden days

• Logs per server

• Requires SSH for inspection

• Decentralised (for once not an advantage)

• Hard to search

!13

Page 14: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Goals

Make logs searchable

!14

Page 15: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Goals

!15

Page 16: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Goals

Collect and manipulate logs

!16

Page 17: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Goals

!17

Page 18: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Goals

Extract metrics

!18

Page 19: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Enter Mr. logstash (hipster mo’ included)

!19

Page 20: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Logstash

• Inputs

• Filters

• Outputs

!20

Page 21: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Inputs

• File

• Redis

• syslog

• varnishlog

• rabbitmq

• …

!21

Page 22: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Filters

Modify the input data !

• grok • mutate • dns • json • geoip • …

!22

Page 23: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Grok

!23

Page 24: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Grok

!24

Page 25: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Mutate

!25

Page 26: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Json

!26

Page 27: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Json

!27

Page 28: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Outputs

• email • graphite • irc • mongodb • pagerduty • sns • elasticsearch • …

!28

Page 29: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Setup

!29

Page 30: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Example shipper config

!30

Page 31: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Example indexer config

!31

Page 32: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Example indexer config (contd.)

!32

Page 33: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Logstash

!33

Page 34: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Elasticsearch

!34

Page 35: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Elasticsearch

• Distributed search and analytics

• Based on Apache lucene (but better)

• Document-oriented DB

• Easy scaling

• Restful API

• Great for storing logs!

!35

Page 36: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Elasticsearch

!36

!

Getting data in and out:

Page 37: Keep an eye on your app with logging and graphs - PHPBenelux 2014

!

• Logstash defaults to using daily indexes

• Easy retention = delete indexes after x days

• Can be configured in other ways

Elasticsearch

!37

Page 38: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Kibana

!38

Page 39: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Kibana

• Search your logs

• The v3 rewrite is pretty awesome :-)

• HTML + JS only

• Elasticsearch project

• Almost no-config setup

!39

Page 40: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Kibana

!40

Page 41: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Kibana

!41

Page 42: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Kibana

!42

Page 43: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Kibana

!43

Page 44: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Kibana

!44

Page 45: Keep an eye on your app with logging and graphs - PHPBenelux 2014
Page 46: Keep an eye on your app with logging and graphs - PHPBenelux 2014

StatsD

• Metrics aggregation framework

• Made by Etsy

• Node.js

• UDP

• Dead easy to use

!46

Page 47: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Metrics

“Track everything that moves”

!47

Page 48: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Metrics

!48

Page 49: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Running StatsD

!49

Page 50: Keep an eye on your app with logging and graphs - PHPBenelux 2014

StatsD config

!50

Page 51: Keep an eye on your app with logging and graphs - PHPBenelux 2014

StatsD config

!51

Page 52: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Console backend

!52

Page 53: Keep an eye on your app with logging and graphs - PHPBenelux 2014

StatsD Metric types

• Counters

• Timers

• Gauges

!53

Page 54: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Counters

!54

Page 55: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Timers

!55

Page 56: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Gauges

Arbitrary values:

!56

Page 57: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Sampling data

!57

Page 58: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Example: ZF Controller plugin

!58

Page 59: Keep an eye on your app with logging and graphs - PHPBenelux 2014

StatsD naming

!59

Page 60: Keep an eye on your app with logging and graphs - PHPBenelux 2014

But…

!60

StatsD is for collection and aggregation only

Page 61: Keep an eye on your app with logging and graphs - PHPBenelux 2014

We want pretty graphs

!61

Page 62: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Coffee is important too

!62

Page 63: Keep an eye on your app with logging and graphs - PHPBenelux 2014

StatsD config

!63

Page 64: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Graphite

• Store and visualise time-series data

• Carbon, whisper and graphite UI

• Rendering graphs

• Powerful function library

!64

Page 65: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Graphite UI

!65

Page 66: Keep an eye on your app with logging and graphs - PHPBenelux 2014

StatsD => Graphite

!66

production.api.httpstatus.200

Page 67: Keep an eye on your app with logging and graphs - PHPBenelux 2014

StatsD => Graphite

!67

Page 68: Keep an eye on your app with logging and graphs - PHPBenelux 2014

The render API

!68

Page 69: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Json output

!69

Add &format=json to the render API

Page 70: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Functions

• cumulative(‘server*.api.logins’) • asPercent(‘connections.failed’, ‘connections.attempted’) • drawAsInfinite(‘app.deploys’) • summarize(‘app.errors’, ‘1hour’) • stacked() • movingAverage()

!• http://graphite.readthedocs.org/en/latest/functions.html

!70

Page 71: Keep an eye on your app with logging and graphs - PHPBenelux 2014

StatsD

!71

Page 72: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Functions

• cumulative(‘server*.api.logins’) • asPercent(‘connections.failed’, ‘connections.attempted’) • drawAsInfinite(‘app.deploys’) • summarize(‘app.errors’, ‘1hour’) • stacked() • movingAverage()

!• http://graphite.readthedocs.org/en/latest/functions.html

!72

Page 73: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Alternative dashboards

!73

Page 74: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Dashing

!74

Page 75: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Tasseo

!75

Page 76: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Descartes

!76

Page 77: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Conclusion

• No excuse not to log

• Manage your logs with logstash and kibana

• Track everything using statsd

• Visualise with graphite dashboards

• Get insight in your application!

!77

Page 78: Keep an eye on your app with logging and graphs - PHPBenelux 2014

Thank you! Questions?

http://www.egeniq.com [email protected]

@egeniq

Feedback: https://joind.in/10276 Contact: @felixdv