May 13, 2011

Using Chef to write out a munin.conf file which uses the Chef Server node name to label clients

Pretty much what it says on the tin. If you configure your munin server using Opscode chef, and you're looking at EC2/Opscode nodes, it's advantageous to label the munin clients in the munin conf using the Opscode node name so that you can quickly match them to the proper records on Opscode. Also, the Opscode name has the EC2 instance ID suffixed to it, which makes it easy to find the node on EC2 as well.

In addition, you want to group your nodes into reasonable groups! So let's say you have project/environment/type attributes which describe each node (like, for example, myapp-staging-app).

Pass an array of nodes into the template as @munin_nodes. Inside the template erb file which you use to write out the munin.conf file, use the following:

# a simple host tree
<% @munin_nodes.each do |system| -%>
[<%= system[:project]] %>-<%= system[:environment] %>-<%= system[:type] %>;<%= %>]
    address <%= system[:ipaddress] %>
    use_node_name yes

<% end -%>
This will give you a nice conf file, with each node configured to be part of a node group and each node configured to have munin talk to it using its IP address rather than your label as a DNS name.

This is pretty straightforward, except for that '' call. Although I had gotten used to pulling any attribute I wanted out as symbols (node[:symbol]) it turns out there is no symbol that links to the Chef server node name - that attribute is at a 'higher level' than the attributes you can get to with symbols. So you have to use (here to get to it.

Posted by jbz at May 13, 2011 6:06 PM | TrackBack

Post a comment

Remember personal info?