]> git.openstreetmap.org Git - chef.git/blob - cookbooks/munin/recipes/default.rb
Use hpasmcli2_ instead of hpasmcli_
[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 node[:dmi] and node[:dmi][:system] and node[:dmi][:system][:manufacturer] == "HP"
83   case node[:dmi][:system][:product_name]
84   when "ProLiant DL360 G6", "ProLiant DL360 G7"
85     template "/etc/sensors.d/disable-bad-acpi-sensor.conf" do
86       source "disable-bad-acpi-sensor.conf.erb"
87       owner "root"
88       group "root"
89       mode 0644
90     end
91   end
92 end
93
94 if Dir.glob("/proc/acpi/thermal_zone/*/temperature").empty?
95   munin_plugin "acpi" do
96     action :delete
97   end
98 else
99   munin_plugin "acpi"
100 end
101
102 # apcpdu_
103 munin_plugin "cpu"
104
105 if File.exists?("/sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state")
106   munin_plugin "cpuspeed"
107 else
108   munin_plugin "cpuspeed" do
109     action :delete
110   end
111 end
112
113 munin_plugin "df"
114 munin_plugin "df_inode"
115 munin_plugin "diskstats"
116 munin_plugin "entropy"
117 munin_plugin "forks"
118
119 if node[:kernel][:modules].include?("nf_conntrack")
120   package "conntrack"
121
122   munin_plugin "fw_conntrack"
123   munin_plugin "fw_forwarded_local"
124 else
125   munin_plugin "fw_conntrack" do
126     action :delete
127   end
128
129   munin_plugin "fw_forwarded_local" do
130     action :delete
131   end
132 end
133
134 if File.read("/proc/sys/net/ipv4/ip_forward").chomp == "1"
135   munin_plugin "fw_packets"
136 else
137   munin_plugin "fw_packets" do
138     action :delete
139   end
140 end
141
142 disks = node[:block_device].select do |name,attributes|
143   [ "ATA", "FUJITSU", "SEAGATE", "DELL", "COMPAQ", "IBM-ESXS" ].include?(attributes[:vendor])
144 end
145
146 if disks.empty?
147   munin_plugin "hddtemp_smartctl" do
148     action :delete
149   end
150 else
151   munin_plugin "hddtemp_smartctl" do
152     conf "hddtemp.erb"
153     conf_variables :disks => disks
154   end
155 end
156
157 if File.exists?("/sbin/hpasmcli")
158   munin_plugin "hpasmcli2_temp" do
159     target "hpasmcli2_"
160   end
161
162   munin_plugin "hpasmcli2_fans" do
163     target "hpasmcli2_"
164   end
165 else
166   munin_plugin "hpasmcli2_temp" do
167     action :delete
168   end
169
170   munin_plugin "hpasmcli2_fans" do
171     action :delete
172   end
173 end
174
175 munin_plugin "hpasmcli_temp" do
176   action :delete
177 end
178
179 munin_plugin "hpasmcli_fans" do
180   action :delete
181 end
182
183 munin_plugin "http_loadtime" do
184   action :delete
185 end
186
187 node[:network][:interfaces].each do |ifname,ifattr|
188   if ifname =~ /^eth\d+$/
189     if ifattr[:flags] and ifattr[:flags].include?("UP")
190       munin_plugin "if_err_#{ifname}" do
191         target "if_err_"
192       end
193
194       munin_plugin "if_#{ifname}" do
195         target "if_"
196       end
197     else
198       munin_plugin "if_err_#{ifname}" do
199         action :delete
200       end
201
202       munin_plugin "if_#{ifname}" do
203         action :delete
204       end
205     end
206   end
207 end
208
209 munin_plugin "interrupts"
210 munin_plugin "iostat"
211 munin_plugin "iostat_ios"
212
213 if Dir.glob("/dev/ipmi*").empty?
214   munin_plugin "ipmi_fans" do
215     action :delete
216   end
217
218   munin_plugin "ipmi_temp" do
219     action :delete
220   end
221
222   munin_plugin "ipmi_power" do
223     action :delete
224     only_if { node[:lsb][:release].to_f >= 14.04 }
225   end
226 else
227   munin_plugin "ipmi_fans" do
228     target "ipmi_"
229   end
230
231   munin_plugin "ipmi_temp" do
232     target "ipmi_"
233   end
234
235   munin_plugin "ipmi_power" do
236     target "ipmi_"
237     only_if { node[:lsb][:release].to_f >= 14.04 }
238   end
239 end
240
241 munin_plugin "irqstats"
242 munin_plugin "load"
243 munin_plugin "memory"
244 munin_plugin "netstat"
245
246 if node[:kernel][:modules].include?("nfsv3")
247   munin_plugin "nfs_client"
248 else
249   munin_plugin "nfs_client" do
250     action :delete
251   end
252 end
253
254 if node[:kernel][:modules].include?("nfsv4")
255   munin_plugin "nfs4_client"
256 else
257   munin_plugin "nfs4_client" do
258     action :delete
259   end
260 end
261
262 if node[:kernel][:modules].include?("nfsd")
263   munin_plugin "nfsd"
264   munin_plugin "nfsd4"
265 else
266   munin_plugin "nfsd" do
267     action :delete
268   end
269
270   munin_plugin "nfsd4" do
271     action :delete
272   end
273 end
274
275 munin_plugin "open_files"
276 munin_plugin "open_inodes"
277
278 munin_plugin "postfix_mailqueue" do
279   action :delete
280 end
281
282 munin_plugin "postfix_mailvolume" do
283   action :delete
284 end
285
286 munin_plugin "processes"
287 munin_plugin "proc_pri"
288
289 sensors_fan = false
290 sensors_temp = false
291 sensors_volt = false
292
293 Dir.glob("/sys/class/hwmon/hwmon*").each do |hwmon|
294   hwmon = "#{hwmon}/device" unless File.exists?("#{hwmon}/name")
295
296   sensors_fan = true unless Dir.glob("#{hwmon}/fan*_input").empty?
297   sensors_temp = true unless Dir.glob("#{hwmon}/temp*_input").empty?
298   sensors_volt = true unless Dir.glob("#{hwmon}/in*_input").empty?
299 end
300
301 if sensors_fan || sensors_temp || sensors_volt
302   package "lm-sensors"
303 end
304
305 if sensors_fan
306   munin_plugin "sensors_fan" do
307     target "sensors_"
308   end
309 else
310   munin_plugin "sensors_fan" do
311     action :delete
312   end
313 end
314
315 if sensors_temp
316   munin_plugin "sensors_temp" do
317     target "sensors_"
318   end
319 else
320   munin_plugin "sensors_temp" do
321     action :delete
322   end
323 end
324
325 if sensors_volt
326   munin_plugin "sensors_volt" do
327     target "sensors_"
328   end
329 else
330   munin_plugin "sensors_volt" do
331     action :delete
332   end
333 end
334
335 node[:block_device].each do |name,attributes|
336   if attributes[:vendor] == "ATA"
337     munin_plugin "smart_#{name}" do
338       target "smart_"
339     end
340   else
341     munin_plugin "smart_#{name}" do
342       action :delete
343     end
344   end
345 end
346
347 munin_plugin "swap"
348 munin_plugin "tcp"
349 munin_plugin "threads"
350 munin_plugin "uptime"
351 munin_plugin "users"
352 munin_plugin "vmstat"