Logging & monitoring

Preview:

Citation preview

Logging & MonitoringKnowing your shit

by Tobias Nyholm

Logging

Logging?

Logging

Composer?

LoggingJordi Boggiano @seldaek

Talk overview

About me• Tobias Nyholm, @tobiasnyholm

• Happyr.com

• Co-host of Sound of Symfony podcast

• Organizer of PHP Stockholm

What do you do today?

Google analyticsUser statistics What pages visited Time spent on the site How the users moves Where they come from etc…

Comment was created Call to API Media uploaded Data fetched User was imported

We want to log more

Example logging

Use monolog

Use monologLog with different levels Use streams No issue with locking Extendable!

Building blocks• Handlers - Do stuff with an entry

• Formatters - Defines how an entry should look

• Processors - Add extra data to the entry

Building blocks

Logger (channel)

HandlerHandler

Handler

Processor

ProcessorProcessorFormatter

Formatter

Formatter

HandlerFormatter

ProcessorProcessor

Monolog handlers

Monolog handlers

Custom handler

Formatters

Processors

Processors• IntrospectionProcessor: Adds the line/file/class/method from which

the log call originated.

• WebProcessor: Adds the current request URI, request method and client IP to a log record.

• MemoryUsageProcessor: Adds the current memory usage to a log record.

• MemoryPeakUsageProcessor: Adds the peak memory usage to a log record.

• GitProcessor: Adds the current git branch and commit to a log record.

• TagProcessor: Adds an array of predefined tags to a log record.

Log exceptions

Log exceptions

Log exceptions

Symfony Kernel

Symfony’s HttpKernel

RecapApplication events Monolog Handlers Exceptions

Everything put into one file

We got tons of entries

Log files/var/www/my_site/log.txt /var/log/php5-fpm.log /var/log/php5-fpm/access.log /var/log/php5-fpm/errors.log /var/log/php5-fpm/slow.log /var/log/apache2/access.log /var/log/apache2/error.log /var/log/syslog

I introduce to you: A logging server!

Logging serverGraylog 2

Elastic stack (former Elk)

Demo images on graylog

–Johnny Appleseed

“Type a quote here.”

Processors

Processors

Processors

Add extra data

I introduce to you: New Relic

–Johnny Appleseed

“Type a quote here.”

–Johnny Appleseed

“Type a quote here.”

–Johnny Appleseed

“Type a quote here.”

Thank you@tobiasnyholm

SeminarsNewRelic workshop - May 3rd http://newrelic.com/rsvp/20160503stockholmapmwkshp

Meetup with PHP security - May 11th http://www.meetup.com/php-stockholm/events/228580453/

Recommended