Fluentd and PHP

42
PHP & Fluentd

Transcript of Fluentd and PHP

Page 1: Fluentd and PHP

PHP  &  Fluentd

Page 2: Fluentd and PHP

@chobi_e

Page 3: Fluentd and PHP

chobi_e  is:    PECL  Sundown  Author  (will  be  release  soon)  h>ps://github.com/chobie/php-­‐sundown  

libgit2  PHP  Binding  Author  h>ps://github.com/libgit2/php-­‐git  

phpredis  contributor  

h>ps://github.com/nicolasff/phpredis  

Page 4: Fluentd and PHP

Scaling  web  servers.

Page 5: Fluentd and PHP

Scaling  web  servers.  basically,  just  add  web  server  to  the  array.

Page 6: Fluentd and PHP

then,  how  about  collecLng  log  files?

Page 7: Fluentd and PHP

using  log  file  

Page 8: Fluentd and PHP

using  log  file   Are  you  serious?

Page 9: Fluentd and PHP

using  syslog  like  middleware

Page 10: Fluentd and PHP

using  syslog  like  middleware Not  Bad.

Page 11: Fluentd and PHP

using  reliable  and  distributed  log  collector:  

Note:  fluent-­‐logger-­‐php  does  not  support  output  buffering.  So  local  fluentd  as  a  buffer  in  this  case.

Page 12: Fluentd and PHP

using  reliable  and  distributed  log  collector:  

that’s  the  best  soluLon  IMHO

Note:  fluent-­‐logger-­‐php  does  not  support  output  buffering.  So  local  fluentd  as  a  buffer  in  this  case.

Page 13: Fluentd and PHP

fluentd  provides  robust  messaging  soluLon

Page 14: Fluentd and PHP

Data  Mining

for  Data  Mining

Page 15: Fluentd and PHP

Data  Mining

Queued  job

for  queued  job

Page 16: Fluentd and PHP

fluentd  first  step  with  PHP

Page 17: Fluentd and PHP

install  by  composer

Page 18: Fluentd and PHP
Page 19: Fluentd and PHP

#  composer.json  {      "name":  "my-­‐project",      "version":  "1.0.0",      "require":  {          "fluent/logger":  "master-­‐dev"      }  }

Page 20: Fluentd and PHP

wget  h>p://getcomposer.org/composer.phar  php  -­‐d  detect_unicode=0  composer.phar  install

Page 21: Fluentd and PHP

<?php  require  "vendor/.composer/autoload.php";    use  Fluent\Logger\FluentLogger;    $logger  =  FluentLogger::open(        "debug.test",        "localhost",        "24224”  );

Page 22: Fluentd and PHP

install  by  copy  the  tree.

Page 23: Fluentd and PHP

git  clone  h>ps://github.com/fluent/fluent-­‐logger-­‐php.git  cp  -­‐r  src/Fluent  <path/to/your_project>

Page 24: Fluentd and PHP

php  library  which  using  Fluentd.

Page 25: Fluentd and PHP

Monolog\Fluent  by  nrk  h>ps://github.com/nrk/monolog-­‐fluent.git

Page 26: Fluentd and PHP

what  is  Monolog?    Monolog  by  Seldaek.  h>ps://github.com/Seldaek/monolog      Monolog  is:  heavily  inspired  by  Python's  Logbook  library,  although  most  concepts  have  been  adjusted  to  fit  to  the  PHP  world.    

Page 27: Fluentd and PHP

install  $  wget  h>p://getcomposer.org/composer.phar  $  php  composer.phar  install    

Page 28: Fluentd and PHP

<?php  use  Nrk\Fluent\Monolog\FluentHandler;    $log  =  new  Monolog\Logger('debug.monolog');    $log-­‐>pushHandler(new  FluentHandler('h>p://127.0.0.1'));  $log-­‐>pushHandler(new  FluentHandler('tcp://127.0.0.1'));    $log-­‐>addError("OH  NOES!!11!1!");

Page 29: Fluentd and PHP

introduce  my  fluent  plugin

Page 30: Fluentd and PHP

fluent-­‐plugin-­‐delayed    -­‐  delayed  output  plugin.    h>ps://github.com/chobie/fluent-­‐plugin-­‐delayed  

Page 31: Fluentd and PHP

fluent-­‐plugin-­‐delayed    -­‐  delayed  output  plugin.    h>ps://github.com/chobie/fluent-­‐plugin-­‐delayed  

delayed  plugin

event{    Lme:  2011-­‐10-­‐22  10:00:05,  #  5  seconds  future    ...  }  

Client

:  aler  5  seconds.  then  delayed  plugin  outputs  the  data  to  other  output  plugin.  

output

Page 32: Fluentd and PHP

other  Ideas.    fluent-­‐plugin-­‐cooldown    -­‐  coolodowned  outputs  when  specified  key  received.    fluent-­‐plugin-­‐sampler    -­‐  only  outputs  N  %  data.  

Page 33: Fluentd and PHP

GitHQ  /  Kokuban  Github  /  gist  clone  (sLll  under  development)

Page 34: Fluentd and PHP

updaLng  ssh  key    is    pain  in  ass. /home/git/.ssh/authorized_keys

Page 35: Fluentd and PHP

web  server fluentd cooldown exec client

redis update  authorized_keys  

send  public  key

sending  message  via  fluentd\Logger

only  pass  cooldowned  message.

updaLng  SSH  Authorized  keys

obtain  ssh  public  keys

Page 36: Fluentd and PHP

Web  developer  only  knows  tag  for  queued  job.

Page 37: Fluentd and PHP

Web  developer  only  knows  tag  for  queued  job.

Server  engineer  only  implements  reliable  consumer  plugin  for  Fluentd.

Page 38: Fluentd and PHP

Sounds  good?

Page 39: Fluentd and PHP

fluent-­‐logger-­‐php  status.

Page 40: Fluentd and PHP

fluentd  protocol  support  ✔  h>p  protocol  support  ✔  composer  support  ✔  PEAR  package  support  ✔  -­‐  but  I  don’t  provide  pear  channel.    

 message  pack  support  buffering  support  -­‐  does  not  support  as  there’s  trouble  some  for  using  persistent  variables  for  buffer.    

Page 41: Fluentd and PHP

That’s  all  

Page 42: Fluentd and PHP

That’s  all  i  need  more  developer!  please  feel  free  to  pull  req  me.    h>ps://github.com/chobie