DevOps Zone is brought to you in partnership with:

Trevor Parsons is Chief Scientist and Co-founder of Logentries, 'the log management and intelligence platform'. Trevor has over 10 years experience in enterprise software and in particular has specialised in developing enterprise monitoring and performance tools for enterprise systems. He is also a research fellow at the Performance Engineering Lab Research Group and was formerly a Scientist at the IBM Center for Advanced Studies. Trevor holds a PhD from University College Dublin, Ireland. Trevor is a DZone MVB and is not an employee of DZone and has posted 87 posts at DZone. You can read more from them at their website. View Full User Profile

Cooking Up Engine Yard Logs with Chef

10.12.2012
| 4994 views |
  • submit to reddit

Opscode’s Chef is an open-source automation framework for the cloud, involving ‘recipes’ that can be triggered by events such as servers booting or restarting. Chef scripts are written in Ruby, but will often use OS-specific system calls to manipulate server instances. Chef is a great way to automate your cloud, and in particular its useful as your environment grows! On Engine Yard, Chef recipes can also be used to configure add-on’s (like Logentries) on your servers as we will explain…

Each server deployed in an Engine Yard environment uses the Linux-based Gentoo operating system, with Chef installed as standard. To make customisation of your application really simple, Engine Yard offers a RubyGem for hassle-free editing and uploading of Chef scripts. This, along with the wide variety of cookbooks offered for Engine Yard customers, means it is possible to automate a lot of otherwise complicated tasks without ever ‘SSHing’ into your instances. Because of this user-friendly interfacing and Engine Yard’s very open user access policy, using a log management service will not require lots of time and effort that could be better spent developing and testing your app.

Logging on Engine Yard
Engine Yard allows full access to the file system on each Gentoo Linux instance, either using Chef automation or via SSH. This includes a number of different log files in several different locations, but all of which can be sent to Logentries for analysis and error detection. Check out this previous blog post by my colleague Trevor Parsons, which gives an insight into what to look out for in Engine Yard logs. Some files that might be of interest are:

  • ~/yourapp-deploy.log: deployment related events for this instance
  • /var/log/engineyard/apps/yourapp/production.log: Rails application errors and events
  • /var/log/daemon.log: background daemon information
  • /db/mysql/{major_version}/log/ or db/mysql/log/: MySQL database logs
  • General Linux logs: as outlined here

The Logentries Cookbook
The Logentries cookbook installs and configures an agent to monitor log files and to send events to the Logentries service. This is performed automatically, with the user only required to edit one or two user specific variables in advance. The agent is packaged in a Gentoo Linux application, which is downloaded from the Logentries server, installed and started. A daemon process constantly monitors the files being followed for new events – don’t worry, it uses very little CPU. The Chef script also checks the daemon every time it is run, to make sure multiple processes are not started.

The cookbook is available for download from GitHub, and can be added to a larger set of cookbooks or used on its own. To start using Logentries with Engine Yard, simply set up a Logentries account and retrieve your user key from the Account page. You will need to add this to /cookbooks/le/attributes/recipe.rb in the indicated location. Some common files are followed by default -

  • “/var/log/syslog”
  • “/var/log/auth.log”
  • “/var/log/daemon.log”
  • “/var/log/nginx/#{app_name}.access.log”

- you can modify this list in cookbooks/le/recipes/configure.rb.

Then use the standard Engine Yard gem to upload the recipes to your instance – simply run

ey recipes upload -e ENVIRONMENT_NAME
ey recipes apply -e ENVIRONMENT_NAME

Adding additional files to your Logentries setup is very easy – just SSH into your Gentoo instance and use sudo le follow [file], or edit the recipes and re-upload if you prefer to avoid the command line. For more detailed instructions, see our Engine Yard docs.

Published at DZone with permission of Trevor Parsons, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)