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