Monday, September 9, 2013

Notify New Relic of Deployments with Chef

You can tell New Relic about your deployments and they’ll add vertical lines to the graphs at the corresponding times. This is super helpful as the (often dramatic) impact of a deployment becomes easy to grok.

The documentation on the Events > Deployments page is very helpful, but I still had to tinker with my message to New Relic’s API to get it to work. Here’s what I ended up with:

At the end of my recipe, post to the API with the http_request resource:

http_request "notify_new_relic" do
  action :post
  url "https://rpm.newrelic.com/deployments.xml"
  headers "x-api-key" => "#{node["newrelic"]["apikey"]}"
  message "application_id" => "#{node["newrelic"]["appid"]}"
end

I’m loading the key and application id from attributes. And it works (this is dev…no traffic there :))!

deployment-markers

This was crazy simple to do, though it might be better implemented as a report handler. If you go that route please share.