Application Logging
With The ELK Stack
@bwaine - #DPC15
Monday, 29 June 15
2
Ben Andersen-Waine
Software Engineer
Contractor
Deployed ELK To Prod
Numerous Times
Monday, 29 June 15
Logging?
Monday, 29 June 15
System Logs
Monday, 29 June 15
5
Monday, 29 June 15
Application Log
Monday, 29 June 15
Debug Information - Errors (connections,
uncaught exceptions, resource exhaustion)
Narrative Information - Methods Calls,
Event Triggers
Business Events - Purchases, Logins,
Registrations, Unsubscribes
7
Application Log
Monday, 29 June 15
ssh webserver@mydomain.net
tail -f /var/log/nginx/my-site.access.log
tail -f /var/log/my.application.log
ssh data@mydomain.net
tail -f /var/log/mysql/mysql.log
ssh q@mydomain.net
tail -f /var/log/rabbitmq/nodename.log
8
Keeping Track Of All This....
Monday, 29 June 15
9
The Elk Stack
Monday, 29 June 15
Monday, 29 June 15
1) Monolog
2) Everything else....
11
PHP Logging Tools
Monday, 29 June 15
1) Monolog: Loggers And Handlers
2) Monolog:Tags & Formatters
3) Logging business events
12
Basic Logging Examples
Monday, 29 June 15
use MonologLogger;
use MonologHandlerFingersCrossedHandler;
use MonologHandlerStreamHandler;
$logEnv = getenv('LOG_LEVEL');
$level = empty($logLevel) ? $logEnv : Logger::WARNING;
$appLog = new Logger('AppLog');
$strHandler = new StreamHandler('/var/log/app.log', Logger::DEBUG);
$fcHandler = new FingersCrossedHandler($strHandler, $level);
$appLog−>pushHandler($fcHandler);
$appLog−>debug('LOGGING!');
EG1: Loggers And Handlers
13
Monday, 29 June 15
// Set A Log Level
$logEnv = getenv('LOG_LEVEL');
$level = empty($logLevel) ? $logEnv : Logger::WARNING;
// Create A Logger
$appLog = new Logger('AppLog');
14
Monday, 29 June 15
$strHandler
= new StreamHandler('/var/log/app.log', Logger::DEBUG);
$fcHandler
= new FingersCrossedHandler($strHandler, $level);
// Create Handlers
$appLog−>pushHandler($fcHandler);
$appLog−>debug('Start Logging!');
$appLog−>emergency('Something Terrible Happened');
// Push The Handler And Start Logging
15
Monday, 29 June 15
EG 2:Tagging Formatting
$appLog = new Logger('AppLog');
$strHandler = new StreamHandler('/var/lg.lg', $level);
$formatter = new LogstashFormatter("helloapp", "application");
$strHandler−>setFormatter($formatter);
$appLog−>pushHandler($strHandler));
$id = $_SERVER('X_VARNISH');
$tag = new TagProcessor(['request−id' => $id])
$appLog−>pushProcessor($tag);
$appLog−>debug("LOGGING!");
16
Monday, 29 June 15
// Create A Logger
$appLog = new Logger('AppLog');
$strHandler = new StreamHandler('/var/lg.lg', $level);
$formatter = new LogstashFormatter("helloapp", "app");
// Create A Handler & Formatter
// Set Formatter Onto Handler
$strHandler−>setFormatter($formatter);
$appLog−>pushHandler($strHandler));
//Push Handler Onto Logger
17
Monday, 29 June 15
$id = $_SERVER('X_VARNISH');
$tag = new TagProcessor(['request−id' => $id])
$appLog−>pushProcessor($tag);
$appLog−>debug("LOGGING!");
// Capture A Unique Id, Create A Tag Processor, Push
18
Monday, 29 June 15
2009 - RFC 5424 - Syslog Protocol
Code / Severity
0 Emergency: system is unusable
1 Alert: action must be taken immediately
2 Critical: critical conditions
3 Error: error conditions
4 Warning: warning conditions
5 Notice: normal but significant condition
6 Informational: informational messages
7 Debug: debug-level messages
https://tools.ietf.org/html/rfc5424
19
Log Levels
Monday, 29 June 15
2013 - PSR03 - PHP Logging Interface Standard
http://www.php-fig.org/psr/psr-3/
20
PSR3
Monday, 29 June 15
EG 3: Event Logging
use MonologLogger;
use SymfonyComponentEventDispatcherEventDispatcher;
$dispatcher = new EventDispatcher();
$dispatcher−>addListener(
"business.registration.post",
function () use ($busLog) {
$busLog−>info("Customer registered");
}
);
$dispatcher−>dispatch("business.registration.post");
Monday, 29 June 15
Logstash Architecture
1. Logstash Shipper ships logs to
logstash
2. Logstash processes them
3. Logstash Inserts Into Elastic
Search
4. Kibana exposes a web interface
to Elastic Search data
Monday, 29 June 15
Logstash Architecture
Monday, 29 June 15
Why not rate the talk now BEFORE
the demo?
24
https://joind.in/talk/view/14235
Monday, 29 June 15
ELK Demo
25
1) Discover Data (search / diagnose)
2)Visualize Data
3) Produce A Dashboard
4) Demonstrate ‘the new hotness’ of Kibana 4
Monday, 29 June 15
26
https://github.com/LoveSoftware/
getting-started-with-the-elk-stack
Monday, 29 June 15
Monday, 29 June 15
Monday, 29 June 15
Monday, 29 June 15
Monday, 29 June 15
Logstash Config
31
Monday, 29 June 15
Logstash Collecting
{
"network": {
"servers": [ "logs.logstashdemo.com:5000" ],
"timeout": 15,
"ssl ca":
"/etc/pki/tls/certs/logstash−forwarder.crt"
},
"files": [
{
"paths": [
"/var/log/nginx/helloapp.access.log"
],
"fields": { "type": "nginx−access" }
}
]
}
32
Monday, 29 June 15
Logstash Processing
input {
lumberjack {
port => 5000
ssl_certificate =>
"/etc/pki/tls/certs/logstash−forwarder.crt"
ssl_key =>
"/etc/pki/tls/private/logstash−forwarder.key"
}
}
Input
33
Monday, 29 June 15
Logstash Processing
Filtering
filter {
if [type] == "nginx−access" {
grok {
match => { "message" => "%{COMBINEDAPACHELOG}" }
add_field => [ "received_at", "%{@timestamp}" ]
add_field => [ "received_from", "%{host}" ]
}
date {
match => [ "logdate", "dd/MMM/yyyy:HH:mm:ss Z" ]
}
}
}
34
Monday, 29 June 15
Logstash Processing
Output
output {
elasticsearch { host => localhost }
}
35
Monday, 29 June 15
Groking
grok {
match => { "message" => "%{COMBINEDAPACHELOG}" }
}
https://github.com/elasticsearch/logstash/blob/v1.4.2/patterns/grok-patterns
http://grokdebug.herokuapp.com/
55.3.244.1 GET /index.html 15824 0.043
%{IP:client}
%{WORD:method}
%{URIPATHPARAM:request}
%{NUMBER:bytes}
%{NUMBER:duration}
Monday, 29 June 15
37
Hey Ben....
Have you got time for that
gratuitously flashy geo data demo?
Monday, 29 June 15
Monday, 29 June 15
Logging Ideas
Release Marker
Error rates of various applications over time
Latency in various percentiles of each application tier
HTTP Responses: 400 series responses
HTTP Responses: 500 series responses
Auto git blame production errors
Auth and Syslogs
39
Monday, 29 June 15
Go Forth And Log....
BUT
Remember log rotation
Beware running out of space
Beware file logging on NFS
40
Monday, 29 June 15
Questions?
41
Monday, 29 June 15
https://joind.in/talk/view/14235
42
Monday, 29 June 15

More Related Content

PDF
Application Logging With Logstash
PDF
LogStash - Yes, logging can be awesome
PDF
From zero to hero - Easy log centralization with Logstash and Elasticsearch
ODP
Using Logstash, elasticsearch & kibana
PDF
Got Logs? Get Answers with Elasticsearch ELK - PuppetConf 2014
PPTX
Elastic stack
PPTX
Deploying E.L.K stack w Puppet
PDF
Webscraping with asyncio
Application Logging With Logstash
LogStash - Yes, logging can be awesome
From zero to hero - Easy log centralization with Logstash and Elasticsearch
Using Logstash, elasticsearch & kibana
Got Logs? Get Answers with Elasticsearch ELK - PuppetConf 2014
Elastic stack
Deploying E.L.K stack w Puppet
Webscraping with asyncio

What's hot (20)

PDF
Asynchronous PHP and Real-time Messaging
ODP
Turbo charge your logs
PPT
Realtime Analytics Using MongoDB, Python, Gevent, and ZeroMQ
PPT
Web::Scraper
PPTX
Android and REST
PDF
Real-time search in Drupal with Elasticsearch @Moldcamp
PDF
Designing net-aws-glacier
KEY
Dancing with websocket
PDF
PuppetDB: A Single Source for Storing Your Puppet Data - PUG NY
PDF
Real-time search in Drupal. Meet Elasticsearch
PDF
PuppetDB, Puppet Explorer and puppetdbquery
ODP
When dynamic becomes static: the next step in web caching techniques
PDF
Analyse Yourself
PPT
Don’t turn your logs into cuneiform
PPTX
Caching Up and Down the Stack
PDF
TDC2016SP - Trilha DevOps Java
PDF
N hidden gems in forge (as of may '17)
PDF
AnyMQ, Hippie, and the real-time web
PDF
React for Beginners
PDF
Jean-Baptiste Favre - How to Monitor Bilions of Miles Shared by 20 Million Us...
Asynchronous PHP and Real-time Messaging
Turbo charge your logs
Realtime Analytics Using MongoDB, Python, Gevent, and ZeroMQ
Web::Scraper
Android and REST
Real-time search in Drupal with Elasticsearch @Moldcamp
Designing net-aws-glacier
Dancing with websocket
PuppetDB: A Single Source for Storing Your Puppet Data - PUG NY
Real-time search in Drupal. Meet Elasticsearch
PuppetDB, Puppet Explorer and puppetdbquery
When dynamic becomes static: the next step in web caching techniques
Analyse Yourself
Don’t turn your logs into cuneiform
Caching Up and Down the Stack
TDC2016SP - Trilha DevOps Java
N hidden gems in forge (as of may '17)
AnyMQ, Hippie, and the real-time web
React for Beginners
Jean-Baptiste Favre - How to Monitor Bilions of Miles Shared by 20 Million Us...
Ad

Viewers also liked (6)

PDF
Fluentd and docker monitoring
PDF
Integrando Redis en aplicaciones Symfony2
PDF
Fluentd and PHP
PDF
From Zero to Hero - Centralized Logging with Logstash & Elasticsearch
PDF
Fluentd vs. Logstash for OpenStack Log Management
PDF
Logging with Elasticsearch, Logstash & Kibana
Fluentd and docker monitoring
Integrando Redis en aplicaciones Symfony2
Fluentd and PHP
From Zero to Hero - Centralized Logging with Logstash & Elasticsearch
Fluentd vs. Logstash for OpenStack Log Management
Logging with Elasticsearch, Logstash & Kibana
Ad

Similar to Application Logging With The ELK Stack (20)

PDF
Application Logging in the 21st century - 2014.key
PPT
ELK stack at weibo.com
PDF
Log analysis with the elk stack
PPT
Logstash
KEY
Messaging, interoperability and log aggregation - a new framework
PPTX
Elk with Openstack
PDF
LogStash in action
PPTX
Elk ruminating on logs
PDF
More than syntax
PDF
Docker Logging and analysing with Elastic Stack - Jakub Hajek
PDF
Docker Logging and analysing with Elastic Stack
PDF
2015 03-16-elk at-bsides
PPTX
ELK Ruminating on Logs (Zendcon 2016)
PPTX
Elk stack
PDF
Logstash: Get to know your logs
PDF
ELK: a log management framework
PPTX
The ELK Stack - Get to Know Logs
PDF
elk_stack_alexander_szalonnas
PPTX
Scaling an ELK stack at bol.com
PDF
Elk devops
Application Logging in the 21st century - 2014.key
ELK stack at weibo.com
Log analysis with the elk stack
Logstash
Messaging, interoperability and log aggregation - a new framework
Elk with Openstack
LogStash in action
Elk ruminating on logs
More than syntax
Docker Logging and analysing with Elastic Stack - Jakub Hajek
Docker Logging and analysing with Elastic Stack
2015 03-16-elk at-bsides
ELK Ruminating on Logs (Zendcon 2016)
Elk stack
Logstash: Get to know your logs
ELK: a log management framework
The ELK Stack - Get to Know Logs
elk_stack_alexander_szalonnas
Scaling an ELK stack at bol.com
Elk devops

More from benwaine (9)

PDF
DPC 2016 - 53 Minutes or Less - Architecting For Failure
PDF
The Road To Technical Team Lead
PDF
PHPNW14 - Getting Started With AWS
PDF
Business selectors
PDF
The Art Of Application Logging PHPNW12
PDF
Behat dpc12
PDF
Acceptance & Integration Testing With Behat (PBC11)
PDF
Acceptance & Integration Testing With Behat (PHPNw2011)
PDF
Say no to var_dump
DPC 2016 - 53 Minutes or Less - Architecting For Failure
The Road To Technical Team Lead
PHPNW14 - Getting Started With AWS
Business selectors
The Art Of Application Logging PHPNW12
Behat dpc12
Acceptance & Integration Testing With Behat (PBC11)
Acceptance & Integration Testing With Behat (PHPNw2011)
Say no to var_dump

Recently uploaded (20)

PDF
IT-ITes Industry bjjbnkmkhkhknbmhkhmjhjkhj
PDF
LMS bot: enhanced learning management systems for improved student learning e...
PDF
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf
PDF
Auditboard EB SOX Playbook 2023 edition.
PDF
substrate PowerPoint Presentation basic one
PDF
Co-training pseudo-labeling for text classification with support vector machi...
PDF
Ensemble model-based arrhythmia classification with local interpretable model...
PDF
AI.gov: A Trojan Horse in the Age of Artificial Intelligence
PPTX
Internet of Everything -Basic concepts details
PDF
Human Computer Interaction Miterm Lesson
PDF
Decision Optimization - From Theory to Practice
PDF
Transform-Your-Streaming-Platform-with-AI-Driven-Quality-Engineering.pdf
PDF
SaaS reusability assessment using machine learning techniques
PDF
Electrocardiogram sequences data analytics and classification using unsupervi...
PDF
A symptom-driven medical diagnosis support model based on machine learning te...
PPTX
Build automations faster and more reliably with UiPath ScreenPlay
PDF
Introduction to MCP and A2A Protocols: Enabling Agent Communication
PDF
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
PDF
Advancing precision in air quality forecasting through machine learning integ...
PPTX
AI-driven Assurance Across Your End-to-end Network With ThousandEyes
IT-ITes Industry bjjbnkmkhkhknbmhkhmjhjkhj
LMS bot: enhanced learning management systems for improved student learning e...
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf
Auditboard EB SOX Playbook 2023 edition.
substrate PowerPoint Presentation basic one
Co-training pseudo-labeling for text classification with support vector machi...
Ensemble model-based arrhythmia classification with local interpretable model...
AI.gov: A Trojan Horse in the Age of Artificial Intelligence
Internet of Everything -Basic concepts details
Human Computer Interaction Miterm Lesson
Decision Optimization - From Theory to Practice
Transform-Your-Streaming-Platform-with-AI-Driven-Quality-Engineering.pdf
SaaS reusability assessment using machine learning techniques
Electrocardiogram sequences data analytics and classification using unsupervi...
A symptom-driven medical diagnosis support model based on machine learning te...
Build automations faster and more reliably with UiPath ScreenPlay
Introduction to MCP and A2A Protocols: Enabling Agent Communication
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
Advancing precision in air quality forecasting through machine learning integ...
AI-driven Assurance Across Your End-to-end Network With ThousandEyes

Application Logging With The ELK Stack

  • 1. Application Logging With The ELK Stack @bwaine - #DPC15 Monday, 29 June 15
  • 2. 2 Ben Andersen-Waine Software Engineer Contractor Deployed ELK To Prod Numerous Times Monday, 29 June 15
  • 7. Debug Information - Errors (connections, uncaught exceptions, resource exhaustion) Narrative Information - Methods Calls, Event Triggers Business Events - Purchases, Logins, Registrations, Unsubscribes 7 Application Log Monday, 29 June 15
  • 8. ssh [email protected] tail -f /var/log/nginx/my-site.access.log tail -f /var/log/my.application.log ssh [email protected] tail -f /var/log/mysql/mysql.log ssh [email protected] tail -f /var/log/rabbitmq/nodename.log 8 Keeping Track Of All This.... Monday, 29 June 15
  • 11. 1) Monolog 2) Everything else.... 11 PHP Logging Tools Monday, 29 June 15
  • 12. 1) Monolog: Loggers And Handlers 2) Monolog:Tags & Formatters 3) Logging business events 12 Basic Logging Examples Monday, 29 June 15
  • 13. use MonologLogger; use MonologHandlerFingersCrossedHandler; use MonologHandlerStreamHandler; $logEnv = getenv('LOG_LEVEL'); $level = empty($logLevel) ? $logEnv : Logger::WARNING; $appLog = new Logger('AppLog'); $strHandler = new StreamHandler('/var/log/app.log', Logger::DEBUG); $fcHandler = new FingersCrossedHandler($strHandler, $level); $appLog−>pushHandler($fcHandler); $appLog−>debug('LOGGING!'); EG1: Loggers And Handlers 13 Monday, 29 June 15
  • 14. // Set A Log Level $logEnv = getenv('LOG_LEVEL'); $level = empty($logLevel) ? $logEnv : Logger::WARNING; // Create A Logger $appLog = new Logger('AppLog'); 14 Monday, 29 June 15
  • 15. $strHandler = new StreamHandler('/var/log/app.log', Logger::DEBUG); $fcHandler = new FingersCrossedHandler($strHandler, $level); // Create Handlers $appLog−>pushHandler($fcHandler); $appLog−>debug('Start Logging!'); $appLog−>emergency('Something Terrible Happened'); // Push The Handler And Start Logging 15 Monday, 29 June 15
  • 16. EG 2:Tagging Formatting $appLog = new Logger('AppLog'); $strHandler = new StreamHandler('/var/lg.lg', $level); $formatter = new LogstashFormatter("helloapp", "application"); $strHandler−>setFormatter($formatter); $appLog−>pushHandler($strHandler)); $id = $_SERVER('X_VARNISH'); $tag = new TagProcessor(['request−id' => $id]) $appLog−>pushProcessor($tag); $appLog−>debug("LOGGING!"); 16 Monday, 29 June 15
  • 17. // Create A Logger $appLog = new Logger('AppLog'); $strHandler = new StreamHandler('/var/lg.lg', $level); $formatter = new LogstashFormatter("helloapp", "app"); // Create A Handler & Formatter // Set Formatter Onto Handler $strHandler−>setFormatter($formatter); $appLog−>pushHandler($strHandler)); //Push Handler Onto Logger 17 Monday, 29 June 15
  • 18. $id = $_SERVER('X_VARNISH'); $tag = new TagProcessor(['request−id' => $id]) $appLog−>pushProcessor($tag); $appLog−>debug("LOGGING!"); // Capture A Unique Id, Create A Tag Processor, Push 18 Monday, 29 June 15
  • 19. 2009 - RFC 5424 - Syslog Protocol Code / Severity 0 Emergency: system is unusable 1 Alert: action must be taken immediately 2 Critical: critical conditions 3 Error: error conditions 4 Warning: warning conditions 5 Notice: normal but significant condition 6 Informational: informational messages 7 Debug: debug-level messages https://tools.ietf.org/html/rfc5424 19 Log Levels Monday, 29 June 15
  • 20. 2013 - PSR03 - PHP Logging Interface Standard http://www.php-fig.org/psr/psr-3/ 20 PSR3 Monday, 29 June 15
  • 21. EG 3: Event Logging use MonologLogger; use SymfonyComponentEventDispatcherEventDispatcher; $dispatcher = new EventDispatcher(); $dispatcher−>addListener( "business.registration.post", function () use ($busLog) { $busLog−>info("Customer registered"); } ); $dispatcher−>dispatch("business.registration.post"); Monday, 29 June 15
  • 22. Logstash Architecture 1. Logstash Shipper ships logs to logstash 2. Logstash processes them 3. Logstash Inserts Into Elastic Search 4. Kibana exposes a web interface to Elastic Search data Monday, 29 June 15
  • 24. Why not rate the talk now BEFORE the demo? 24 https://joind.in/talk/view/14235 Monday, 29 June 15
  • 25. ELK Demo 25 1) Discover Data (search / diagnose) 2)Visualize Data 3) Produce A Dashboard 4) Demonstrate ‘the new hotness’ of Kibana 4 Monday, 29 June 15
  • 32. Logstash Collecting { "network": { "servers": [ "logs.logstashdemo.com:5000" ], "timeout": 15, "ssl ca": "/etc/pki/tls/certs/logstash−forwarder.crt" }, "files": [ { "paths": [ "/var/log/nginx/helloapp.access.log" ], "fields": { "type": "nginx−access" } } ] } 32 Monday, 29 June 15
  • 33. Logstash Processing input { lumberjack { port => 5000 ssl_certificate => "/etc/pki/tls/certs/logstash−forwarder.crt" ssl_key => "/etc/pki/tls/private/logstash−forwarder.key" } } Input 33 Monday, 29 June 15
  • 34. Logstash Processing Filtering filter { if [type] == "nginx−access" { grok { match => { "message" => "%{COMBINEDAPACHELOG}" } add_field => [ "received_at", "%{@timestamp}" ] add_field => [ "received_from", "%{host}" ] } date { match => [ "logdate", "dd/MMM/yyyy:HH:mm:ss Z" ] } } } 34 Monday, 29 June 15
  • 35. Logstash Processing Output output { elasticsearch { host => localhost } } 35 Monday, 29 June 15
  • 36. Groking grok { match => { "message" => "%{COMBINEDAPACHELOG}" } } https://github.com/elasticsearch/logstash/blob/v1.4.2/patterns/grok-patterns http://grokdebug.herokuapp.com/ 55.3.244.1 GET /index.html 15824 0.043 %{IP:client} %{WORD:method} %{URIPATHPARAM:request} %{NUMBER:bytes} %{NUMBER:duration} Monday, 29 June 15
  • 37. 37 Hey Ben.... Have you got time for that gratuitously flashy geo data demo? Monday, 29 June 15
  • 39. Logging Ideas Release Marker Error rates of various applications over time Latency in various percentiles of each application tier HTTP Responses: 400 series responses HTTP Responses: 500 series responses Auto git blame production errors Auth and Syslogs 39 Monday, 29 June 15
  • 40. Go Forth And Log.... BUT Remember log rotation Beware running out of space Beware file logging on NFS 40 Monday, 29 June 15