]> git.openstreetmap.org Git - chef.git/blob - cookbooks/munin/recipes/default.rb
Manage ipmi_power munin plugin on 14.04 machines
[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 "hpasmcli_temp"
159   munin_plugin "hpasmcli_fans"
160 else
161   munin_plugin "hpasmcli_temp" do
162     action :delete
163   end
164
165   munin_plugin "hpasmcli_fans" do
166     action :delete
167   end
168 end
169
170 munin_plugin "http_loadtime" do
171   action :delete
172 end
173
174 node[:network][:interfaces].each do |ifname,ifattr|
175   if ifname =~ /^eth\d+$/
176     if ifattr[:flags] and ifattr[:flags].include?("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 end
195
196 munin_plugin "interrupts"
197 munin_plugin "iostat"
198 munin_plugin "iostat_ios"
199
200 if Dir.glob("/dev/ipmi*").empty?
201   munin_plugin "ipmi_fans" do
202     action :delete
203   end
204
205   munin_plugin "ipmi_temp" do
206     action :delete
207   end
208
209   munin_plugin "ipmi_power" do
210     action :delete
211     only_if { node[:lsb][:release].to_f >= 14.04 }
212   end
213 else
214   munin_plugin "ipmi_fans" do
215     target "ipmi_"
216   end
217
218   munin_plugin "ipmi_temp" do
219     target "ipmi_"
220   end
221
222   munin_plugin "ipmi_power" do
223     target "ipmi_"
224     only_if { node[:lsb][:release].to_f >= 14.04 }
225   end
226 end
227
228 munin_plugin "irqstats"
229 munin_plugin "load"
230 munin_plugin "memory"
231 munin_plugin "netstat"
232
233 if node[:kernel][:modules].include?("nfsv3")
234   munin_plugin "nfs_client"
235 else
236   munin_plugin "nfs_client" do
237     action :delete
238   end
239 end
240
241 if node[:kernel][:modules].include?("nfsv4")
242   munin_plugin "nfs4_client"
243 else
244   munin_plugin "nfs4_client" do
245     action :delete
246   end
247 end
248
249 if node[:kernel][:modules].include?("nfsd")
250   munin_plugin "nfsd"
251   munin_plugin "nfsd4"
252 else
253   munin_plugin "nfsd" do
254     action :delete
255   end
256
257   munin_plugin "nfsd4" do
258     action :delete
259   end
260 end
261
262 munin_plugin "open_files"
263 munin_plugin "open_inodes"
264
265 munin_plugin "postfix_mailqueue" do
266   action :delete
267 end
268
269 munin_plugin "postfix_mailvolume" do
270   action :delete
271 end
272
273 munin_plugin "processes"
274 munin_plugin "proc_pri"
275
276 sensors_fan = false
277 sensors_temp = false
278 sensors_volt = false
279
280 Dir.glob("/sys/class/hwmon/hwmon*").each do |hwmon|
281   hwmon = "#{hwmon}/device" unless File.exists?("#{hwmon}/name")
282
283   sensors_fan = true unless Dir.glob("#{hwmon}/fan*_input").empty?
284   sensors_temp = true unless Dir.glob("#{hwmon}/temp*_input").empty?
285   sensors_volt = true unless Dir.glob("#{hwmon}/in*_input").empty?
286 end
287
288 if sensors_fan || sensors_temp || sensors_volt
289   package "lm-sensors"
290 end
291
292 if sensors_fan
293   munin_plugin "sensors_fan" do
294     target "sensors_"
295   end
296 else
297   munin_plugin "sensors_fan" do
298     action :delete
299   end
300 end
301
302 if sensors_temp
303   munin_plugin "sensors_temp" do
304     target "sensors_"
305   end
306 else
307   munin_plugin "sensors_temp" do
308     action :delete
309   end
310 end
311
312 if sensors_volt
313   munin_plugin "sensors_volt" do
314     target "sensors_"
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     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"