]> git.openstreetmap.org Git - chef.git/blob - cookbooks/munin/recipes/default.rb
Treat munin-node as an upstart managed service on 14.04
[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 else
209   munin_plugin "ipmi_fans" do
210     target "ipmi_"
211   end
212
213   munin_plugin "ipmi_temp" do
214     target "ipmi_"
215   end
216 end
217
218 munin_plugin "irqstats"
219 munin_plugin "load"
220 munin_plugin "memory"
221 munin_plugin "netstat"
222
223 if node[:kernel][:modules].include?("nfsv3")
224   munin_plugin "nfs_client"
225 else
226   munin_plugin "nfs_client" do
227     action :delete
228   end
229 end
230
231 if node[:kernel][:modules].include?("nfsv4")
232   munin_plugin "nfs4_client"
233 else
234   munin_plugin "nfs4_client" do
235     action :delete
236   end
237 end
238
239 if node[:kernel][:modules].include?("nfsd")
240   munin_plugin "nfsd"
241   munin_plugin "nfsd4"
242 else
243   munin_plugin "nfsd" do
244     action :delete
245   end
246
247   munin_plugin "nfsd4" do
248     action :delete
249   end
250 end
251
252 munin_plugin "open_files"
253 munin_plugin "open_inodes"
254
255 munin_plugin "postfix_mailqueue" do
256   action :delete
257 end
258
259 munin_plugin "postfix_mailvolume" do
260   action :delete
261 end
262
263 munin_plugin "processes"
264 munin_plugin "proc_pri"
265
266 sensors_fan = false
267 sensors_temp = false
268 sensors_volt = false
269
270 Dir.glob("/sys/class/hwmon/hwmon*").each do |hwmon|
271   hwmon = "#{hwmon}/device" unless File.exists?("#{hwmon}/name")
272
273   sensors_fan = true unless Dir.glob("#{hwmon}/fan*_input").empty?
274   sensors_temp = true unless Dir.glob("#{hwmon}/temp*_input").empty?
275   sensors_volt = true unless Dir.glob("#{hwmon}/in*_input").empty?
276 end
277
278 if sensors_fan || sensors_temp || sensors_volt
279   package "lm-sensors"
280 end
281
282 if sensors_fan
283   munin_plugin "sensors_fan" do
284     target "sensors_"
285   end
286 else
287   munin_plugin "sensors_fan" do
288     action :delete
289   end
290 end
291
292 if sensors_temp
293   munin_plugin "sensors_temp" do
294     target "sensors_"
295   end
296 else
297   munin_plugin "sensors_temp" do
298     action :delete
299   end
300 end
301
302 if sensors_volt
303   munin_plugin "sensors_volt" do
304     target "sensors_"
305   end
306 else
307   munin_plugin "sensors_volt" do
308     action :delete
309   end
310 end
311
312 node[:block_device].each do |name,attributes|
313   if attributes[:vendor] == "ATA"
314     munin_plugin "smart_#{name}" do
315       target "smart_"
316     end
317   else
318     munin_plugin "smart_#{name}" do
319       action :delete
320     end
321   end
322 end
323
324 munin_plugin "swap"
325 munin_plugin "tcp"
326 munin_plugin "threads"
327 munin_plugin "uptime"
328 munin_plugin "users"
329 munin_plugin "vmstat"