]> git.openstreetmap.org Git - chef.git/blob - cookbooks/munin/recipes/server.rb
3e72ea160194a10cacbf5dea978fa837dd3aa502
[chef.git] / cookbooks / munin / recipes / server.rb
1 #
2 # Cookbook Name:: munin
3 # Recipe:: server
4 #
5 # Copyright 2010, OpenStreetMap Foundation
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #     http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19
20 include_recipe "apache"
21
22 package "munin"
23 package "rrdcached"
24
25 template "/etc/default/rrdcached" do
26   source "rrdcached.erb"
27   owner "root"
28   group "root"
29   mode 0644
30 end
31
32 directory "/var/lib/munin/rrdcached" do
33   owner "munin"
34   group "munin"
35   mode 0755
36 end
37
38 service "rrdcached" do
39   action [:enable, :start]
40   subscribes :restart, "template[/etc/default/rrdcached]"
41 end
42
43 munin_plugin "rrdcached"
44
45 expiry_time = 14 * 86400
46
47 clients = search(:node, "recipes:munin").select { |n| n[:munin] }.sort_by { |n| n[:hostname] }
48 frontends = search(:node, "recipes:web\\:\\:frontend").reject { |n| Time.now - Time.at(n[:ohai_time]) > expiry_time }.map { |n| n[:hostname] }.sort
49 backends = search(:node, "recipes:web\\:\\:backend").reject { |n| Time.now - Time.at(n[:ohai_time]) > expiry_time }.map { |n| n[:hostname] }.sort
50 tilecaches = search(:node, "roles:tilecache").reject { |n| Time.now - Time.at(n[:ohai_time]) > expiry_time }.sort_by { |n| n[:hostname] }.map do |n|
51   { :name => n[:hostname], :interface => n.interfaces(:role => :external).first[:interface] }
52 end
53 renderers = search(:node, "roles:tile").reject { |n| Time.now - Time.at(n[:ohai_time]) > expiry_time }.sort_by { |n| n[:hostname] }.map do |n|
54   { :name => n[:hostname], :interface => n.interfaces(:role => :external).first[:interface] }
55 end
56
57 template "/etc/munin/munin.conf" do
58   source "munin.conf.erb"
59   owner "root"
60   group "root"
61   mode 0644
62   variables :expiry_time => expiry_time, :clients => clients, :frontends => frontends, :backends => backends, :tilecaches => tilecaches, :renderers => renderers
63 end
64
65 apache_site "munin.openstreetmap.org" do
66   template "apache.erb"
67 end
68
69 munin_plugin "munin_stats"
70 munin_plugin "munin_update"