Thursday, December 21, 2017

Tail your logs from a web interface - rtail

Let us say you want to see realtime some logs like those coming from your lean release, deploy and e2e pipeline. Here is how to use rtail to expose logs streams on a web interface:
    Expose streams using rtail-server
    sudo npm install -g rtail
    mkdir ~/rtail-server
    cd ~/rtail-server
    Create a process.yaml in that directory
      - script : rtail-server
        name: 'rtail-server'
        instances: 0
        exec_mode: cluster
        merge_logs: true
        args: "--web-port 8080 --web-host"
    Run it
    pm2 start process.yaml
    pm2 save
    # logs are in ~/.pm2
  • Stream logs via rtail client with simple and effective cron:
    * * * * * ( flock -n 1 || exit 0; tail -F /var/log/ci/release.log | rtail --id "release.log" ) 1>~/rtail-release.lock
    * * * * * ( flock -n 2 || exit 0; tail -F /var/log/ci/gke-deploy.log | rtail --id "deploy.log" ) 2>~/rtail-deploy.lock
    * * * * * ( flock -n 3 || exit 0; tail -F /var/log/ci/e2e.log | rtail --id "e2e.log" ) 3>~/rtail-e2e.lock
  • At this point http://localhost:8080 should list the available streams and the log traces coming in from them.
  • WARNING: At the time of this writing there is a stream mixed output bug you should be aware of ( . To go around it use the below:
    sudo cp /usr/local/lib/node_modules/rtail/cli/rtail-server.js /usr/local/lib/node_modules/rtail/cli/rtail-server.js.old
    sudo curl -o /usr/local/lib/node_modules/rtail/cli/rtail-server.js
    ps -ef | grep rtail-server | grep -v grep | awk '{print $2}' | xargs kill
    diff /usr/local/lib/node_modules/rtail/cli/rtail-server.js /usr/local/lib/node_modules/rtail/cli/rtail-server.js.old
    Just refresh your browser and wait till the streams show up again.

No comments: