]> git.openstreetmap.org Git - chef.git/blob - cookbooks/munin/recipes/default.rb
Yet more rubucop cleanups
[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.exist?("/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 |_, 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.exist?("/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 ifattr[:encapsulation] == "Ethernet" && ifattr[:state] == "up"
177     munin_plugin "if_err_#{ifname}" do
178       target "if_err_"
179     end
180
181     munin_plugin "if_#{ifname}" do
182       target "if_"
183     end
184   else
185     munin_plugin "if_err_#{ifname}" do
186       action :delete
187     end
188
189     munin_plugin "if_#{ifname}" do
190       action :delete
191     end
192   end
193 end
194
195 munin_plugin "interrupts"
196 munin_plugin "iostat"
197 munin_plugin "iostat_ios"
198
199 if Dir.glob("/dev/ipmi*").empty?
200   munin_plugin "ipmi_fans" do
201     action :delete
202   end
203
204   munin_plugin "ipmi_temp" do
205     action :delete
206   end
207
208   munin_plugin "ipmi_power" do
209     action :delete
210     only_if { node[:lsb][:release].to_f >= 14.04 }
211   end
212 else
213   munin_plugin "ipmi_fans" do
214     target "ipmi_"
215   end
216
217   munin_plugin "ipmi_temp" do
218     target "ipmi_"
219   end
220
221   munin_plugin "ipmi_power" do
222     target "ipmi_"
223     only_if { node[:lsb][:release].to_f >= 14.04 }
224   end
225 end
226
227 munin_plugin "irqstats"
228 munin_plugin "load"
229 munin_plugin "memory"
230 munin_plugin "netstat"
231
232 if node[:kernel][:modules].include?("nfsv3")
233   munin_plugin "nfs_client"
234 else
235   munin_plugin "nfs_client" do
236     action :delete
237   end
238 end
239
240 if node[:kernel][:modules].include?("nfsv4")
241   munin_plugin "nfs4_client"
242 else
243   munin_plugin "nfs4_client" do
244     action :delete
245   end
246 end
247
248 if node[:kernel][:modules].include?("nfsd")
249   munin_plugin "nfsd"
250   munin_plugin "nfsd4"
251 else
252   munin_plugin "nfsd" do
253     action :delete
254   end
255
256   munin_plugin "nfsd4" do
257     action :delete
258   end
259 end
260
261 munin_plugin "open_files"
262 munin_plugin "open_inodes"
263
264 munin_plugin "postfix_mailqueue" do
265   action :delete
266 end
267
268 munin_plugin "postfix_mailvolume" do
269   action :delete
270 end
271
272 munin_plugin "processes"
273 munin_plugin "proc_pri"
274
275 sensors_fan = false
276 sensors_temp = false
277 sensors_volt = false
278
279 Dir.glob("/sys/class/hwmon/hwmon*").each do |hwmon|
280   hwmon = "#{hwmon}/device" unless File.exist?("#{hwmon}/name")
281
282   sensors_fan = true unless Dir.glob("#{hwmon}/fan*_input").empty?
283   sensors_temp = true unless Dir.glob("#{hwmon}/temp*_input").empty?
284   sensors_volt = true unless Dir.glob("#{hwmon}/in*_input").empty?
285 end
286
287 if sensors_fan || sensors_temp || sensors_volt
288   package "lm-sensors"
289 end
290
291 if sensors_fan
292   munin_plugin "sensors_fan" do
293     target "sensors_"
294   end
295 else
296   munin_plugin "sensors_fan" do
297     action :delete
298   end
299 end
300
301 if sensors_temp
302   munin_plugin "sensors_temp" do
303     target "sensors_"
304   end
305 else
306   munin_plugin "sensors_temp" do
307     action :delete
308   end
309 end
310
311 if sensors_volt
312   munin_plugin "sensors_volt" do
313     target "sensors_"
314     conf "sensors_volt.erb"
315   end
316 else
317   munin_plugin "sensors_volt" do
318     action :delete
319   end
320 end
321
322 node[:block_device].each do |name, attributes|
323   if attributes[:vendor] == "ATA"
324     munin_plugin "smart_#{name}" do
325       target "smart_"
326       conf "smart.erb"
327       conf_variables :disk => name
328     end
329   else
330     munin_plugin "smart_#{name}" do
331       action :delete
332     end
333   end
334 end
335
336 munin_plugin "swap"
337 munin_plugin "tcp"
338 munin_plugin "threads"
339 munin_plugin "uptime"
340 munin_plugin "users"
341 munin_plugin "vmstat"