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