Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Measuring and Logging everything in Real-Time

Measuring and Logging everything in Real-Time

Web Developer Conference 2012, Hamburg

Bastian Hofmann

September 18, 2012
Tweet

More Decks by Bastian Hofmann

Other Decks in Programming

Transcript

  1. LogFormat "%h %l %u %t \"%r\" %>s %b" custom CustomLog

    /var/logs/apache/access.log custom http://httpd.apache.org/docs/2.2/mod/ mod_log_config.html#logformat
  2. <?php use Monolog\Logger; use Monolog\Handler\StreamHandler; // create a log channel

    $log = new Logger('name'); $log->pushHandler( new StreamHandler( 'path/to/your.log', Logger::WARNING ) ); // add records to the log $log->addWarning('Foo'); $log->addError('Bar');
  3. Handlers • Stream • Mail • FirePHP • ChromePHP •

    Socket • Roating File • MongoDB • Syslog • Gelf • Null • Test • FingersCrossed
  4. <?php use Monolog\Logger; use Monolog\Handler\StreamHandler; use Monolog\Processor\MemoryUsageProcessor; $log = new

    Logger('name'); $handler = new StreamHandler( 'path/to/your.log', Logger::WARNING ); $log->pushHandler($handler); $log->pushProcessor( new MemoryUsageProcessor() );
  5. <?php use Monolog\Logger; use Monolog\Handler\StreamHandler; use Monolog\Formatter\JsonFormatter; $log = new

    Logger('name'); $handler = new StreamHandler( 'path/to/your.log', Logger::WARNING ); $handler->setFormatter(new JsonFormatter()); $log->pushHandler($handler);
  6. $ wget http://getcomposer.org/composer.phar $ php composer.phar install Installing dependencies -

    Installing monolog/monolog (1.1.0) Downloading: 100% ... monolog/monolog suggests installing mlehner/ gelf-php (Allow sending log messages to a GrayLog2 server) Writing lock file Generating autoload files
  7. web server db memcached db http service create unique trace_id

    for request user request trace_id trace_id trace_id trace_id log log log log log
  8. { "version": "1.0", "host": "www1", "short_message": "Short message", "full_message": "Backtrace

    here\n \nmore stuff", "timestamp": 1291899928.412, "level": 1, "facility": "payment-backend", "file": "/var/www/somefile.rb", "line": 356, "_user_id": 42, "_something_else": "foo" }
  9. file { type => "error" path => [ "/var/logs/php/*.log" ]

    add_field => [ "severity", "error" ] } file { type => "access" path => [ "/var/logs/apache/*_access.log" ] add_field => [ "severity", "info" ] }
  10. filter{ grok { match => ["@source", "\/%{USERNAME:facility}\.log$"] } grok {

    type => "access" pattern => "^%{IP:OriginalIp} \s[a-zA-Z0-9_-]+\s[a-zA-Z0-9_-]+\s\[.*? \]\s\"%{DATA:Request}..." } }
  11. input { amqp { host => 'amqp.host' port => '5672'

    exchange => 'logs' name => 'logs' type => 'logs' exclusive => false } }
  12. A/B

  13. BUY IT BUY IT $userId % 2 === 0 $userId

    = 24 save that option A was clicked save that option A is shown conversion = option A clicked / option A shown
  14. BUY IT BUY IT save random decision in session $userId

    = 24 save that option A was clicked save that option A is shown conversion = option A clicked / option A shown
  15. BUY IT BUY IT random decision $userId = 24 save

    that option A was clicked save that option A is shown conversion = option A clicked / option A shown 1