]> git.openstreetmap.org Git - chef.git/blob - cookbooks/munin/recipes/default.rb
c2a360aa4011ca1e56db444738568b7d20304d6d
[chef.git] / cookbooks / munin / recipes / default.rb
1 #
2 # Cookbook Name:: munin
3 # Recipe:: default
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 "networking"
21
22 package "munin-node"
23
24 service "munin-node" do
25   if node[:lsb][:release].to_f >= 14.04
26     provider Chef::Provider::Service::Upstart
27   end
28   action [ :enable, :start ]
29   supports :status => true, :restart => true, :reload => true
30 end
31
32 servers = search(:node, "recipes:munin\\:\\:server")
33
34 servers.each do |server|
35   server.interfaces(:role => :external) do |interface|
36     if interface[:zone]
37       firewall_rule "accept-munin-#{server}" do
38         action :accept
39         family interface[:family]
40         source "#{interface[:zone]}:#{interface[:address]}"
41         dest "fw"
42         proto "tcp:syn"
43         dest_ports "munin"
44         source_ports "1024:"
45       end
46     end
47   end
48 end
49
50 template "/etc/munin/munin-node.conf" do
51   source "munin-node.conf.erb"
52   owner "root"
53   group "root"
54   mode 0644
55   variables :servers => servers
56   notifies :restart, "service[munin-node]"
57 end
58
59 remote_directory "/usr/local/share/munin/plugins" do
60   source "plugins"
61   owner "root"
62   group "root"
63   mode 0755
64   files_owner "root"
65   files_group "root"
66   files_mode 0755
67   purge true
68 end
69
70 remote_directory "/etc/munin/plugin-conf.d" do
71   source "plugin-conf.d"
72   owner "root"
73   group "munin"
74   mode 0750
75   files_owner "root"
76   files_group "root"
77   files_mode 0644
78   purge false
79   notifies :restart, "service[munin-node]"
80 end
81
82 if Dir.glob("/proc/acpi/thermal_zone/*/temperature").empty?
83   munin_plugin "acpi" do
84     action :delete
85   end
86 else
87   munin_plugin "acpi"
88 end
89
90 # apcpdu_
91 munin_plugin "cpu"
92
93 if File.exists?("/sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state")
94   munin_plugin "cpuspeed"
95 else
96   munin_plugin "cpuspeed" do
97     action :delete
98   end
99 end
100
101 munin_plugin "df"
102 munin_plugin "df_inode"
103 munin_plugin "diskstats"
104 munin_plugin "entropy"
105 munin_plugin "forks"
106
107 if node[:kernel][:modules].include?("nf_conntrack")
108   package "conntrack"
109
110   munin_plugin "fw_conntrack"
111   munin_plugin "fw_forwarded_local"
112 else
113   munin_plugin "fw_conntrack" do
114     action :delete
115   end
116
117   munin_plugin "fw_forwarded_local" do
118     action :delete
119   end
120 end
121
122 if File.read("/proc/sys/net/ipv4/ip_forward").chomp == "1"
123   munin_plugin "fw_packets"
124 else
125   munin_plugin "fw_packets" do
126     action :delete
127   end
128 end
129
130 disks = node[:block_device].select do |name,attributes|
131   [ "ATA", "FUJITSU", "SEAGATE", "DELL", "COMPAQ", "IBM-ESXS" ].include?(attributes[:vendor])
132 end
133
134 if disks.empty?
135   munin_plugin "hddtemp_smartctl" do
136     action :delete
137   end
138 else
139   munin_plugin "hddtemp_smartctl" do
140     conf "hddtemp.erb"
141     conf_variables :disks => disks
142   end
143 end
144
145 if File.exists?("/sbin/hpasmcli")
146   munin_plugin "hpasmcli2_temp" do
147     target "hpasmcli2_"
148   end
149
150   munin_plugin "hpasmcli2_fans" do
151     target "hpasmcli2_"
152   end
153 else
154   munin_plugin "hpasmcli2_temp" do
155     action :delete
156   end
157
158   munin_plugin "hpasmcli2_fans" do
159     action :delete
160   end
161 end
162
163 munin_plugin "hpasmcli_temp" do
164   action :delete
165 end
166
167 munin_plugin "hpasmcli_fans" do
168   action :delete
169 end
170
171 munin_plugin "http_loadtime" do
172   action :delete
173 end
174
175 node[:network][:interfaces].each do |ifname,ifattr|
176   if ifname =~ /^eth\d+$/
177     if ifattr[:flags] and ifattr[:flags].include?("UP")
178       munin_plugin "if_err_#{ifname}" do
179         target "if_err_"
180       end
181
182       munin_plugin "if_#{ifname}" do
183         target "if_"
184       end
185     else
186       munin_plugin "if_err_#{ifname}" do
187         action :delete
188       end
189
190       munin_plugin "if_#{ifname}" do
191         action :delete
192       end
193     end
194   end
195 end
196
197 munin_plugin "interrupts"
198 munin_plugin "iostat"
199 munin_plugin "iostat_ios"
200
201 if Dir.glob("/dev/ipmi*").empty?
202   munin_plugin "ipmi_fans" do
203     action :delete
204   end
205
206   munin_plugin "ipmi_temp" do
207     action :delete
208   end
209
210   munin_plugin "ipmi_power" do
211     action :delete
212     only_if { node[:lsb][:release].to_f >= 14.04 }
213   end
214 else
215   munin_plugin "ipmi_fans" do
216     target "ipmi_"
217   end
218
219   munin_plugin "ipmi_temp" do
220     target "ipmi_"
221   end
222
223   munin_plugin "ipmi_power" do
224     target "ipmi_"
225     only_if { node[:lsb][:release].to_f >= 14.04 }
226   end
227 end
228
229 munin_plugin "irqstats"
230 munin_plugin "load"
231 munin_plugin "memory"
232 munin_plugin "netstat"
233
234 if node[:kernel][:modules].include?("nfsv3")
235   munin_plugin "nfs_client"
236 else
237   munin_plugin "nfs_client" do
238     action :delete
239   end
240 end
241
242 if node[:kernel][:modules].include?("nfsv4")
243   munin_plugin "nfs4_client"
244 else
245   munin_plugin "nfs4_client" do
246     action :delete
247   end
248 end
249
250 if node[:kernel][:modules].include?("nfsd")
251   munin_plugin "nfsd"
252   munin_plugin "nfsd4"
253 else
254   munin_plugin "nfsd" do
255     action :delete
256   end
257
258   munin_plugin "nfsd4" do
259     action :delete
260   end
261 end
262
263 munin_plugin "open_files"
264 munin_plugin "open_inodes"
265
266 munin_plugin "postfix_mailqueue" do
267   action :delete
268 end
269
270 munin_plugin "postfix_mailvolume" do
271   action :delete
272 end
273
274 munin_plugin "processes"
275 munin_plugin "proc_pri"
276
277 sensors_fan = false
278 sensors_temp = false
279 sensors_volt = false
280
281 Dir.glob("/sys/class/hwmon/hwmon*").each do |hwmon|
282   hwmon = "#{hwmon}/device" unless File.exists?("#{hwmon}/name")
283
284   sensors_fan = true unless Dir.glob("#{hwmon}/fan*_input").empty?
285   sensors_temp = true unless Dir.glob("#{hwmon}/temp*_input").empty?
286   sensors_volt = true unless Dir.glob("#{hwmon}/in*_input").empty?
287 end
288
289 if sensors_fan || sensors_temp || sensors_volt
290   package "lm-sensors"
291 end
292
293 if sensors_fan
294   munin_plugin "sensors_fan" do
295     target "sensors_"
296   end
297 else
298   munin_plugin "sensors_fan" do
299     action :delete
300   end
301 end
302
303 if sensors_temp
304   munin_plugin "sensors_temp" do
305     target "sensors_"
306   end
307 else
308   munin_plugin "sensors_temp" do
309     action :delete
310   end
311 end
312
313 if sensors_volt
314   munin_plugin "sensors_volt" do
315     target "sensors_"
316   end
317 else
318   munin_plugin "sensors_volt" do
319     action :delete
320   end
321 end
322
323 node[:block_device].each do |name,attributes|
324   if attributes[:vendor] == "ATA"
325     munin_plugin "smart_#{name}" do
326       target "smart_"
327     end
328   else
329     munin_plugin "smart_#{name}" do
330       action :delete
331     end
332   end
333 end
334
335 munin_plugin "swap"
336 munin_plugin "tcp"
337 munin_plugin "threads"
338 munin_plugin "uptime"
339 munin_plugin "users"
340 munin_plugin "vmstat"