]> git.openstreetmap.org Git - chef.git/blob - cookbooks/munin/recipes/default.rb
Touch XML files to reflect date of original RRD file. Don't run dump in parallel...
[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 package "munin-node"
21
22 service "munin-node" do
23   if node[:lsb][:release].to_f >= 15.10
24     provider Chef::Provider::Service::Systemd
25   elsif 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") # ~FC010
33
34 servers.each do |server|
35   server.interfaces(:role => :external) do |interface|
36     firewall_rule "accept-munin-#{server}" do
37       action :accept
38       family interface[:family]
39       source "#{interface[:zone]}:#{interface[:address]}"
40       dest "fw"
41       proto "tcp:syn"
42       dest_ports "munin"
43       source_ports "1024:"
44     end
45   end
46 end
47
48 template "/etc/munin/munin-node.conf" do
49   source "munin-node.conf.erb"
50   owner "root"
51   group "root"
52   mode 0o644
53   variables :servers => servers
54   notifies :restart, "service[munin-node]"
55 end
56
57 remote_directory "/usr/local/share/munin/plugins" do
58   source "plugins"
59   owner "root"
60   group "root"
61   mode 0o755
62   files_owner "root"
63   files_group "root"
64   files_mode 0o755
65   purge true
66 end
67
68 remote_directory "/etc/munin/plugin-conf.d" do
69   source "plugin-conf.d"
70   owner "root"
71   group "munin"
72   mode 0o750
73   files_owner "root"
74   files_group "root"
75   files_mode 0o644
76   purge false
77   notifies :restart, "service[munin-node]"
78 end
79
80 if Dir.glob("/proc/acpi/thermal_zone/*/temperature").empty?
81   munin_plugin "acpi" do
82     action :delete
83   end
84 else
85   munin_plugin "acpi"
86 end
87
88 # apcpdu_
89 munin_plugin "cpu"
90
91 if File.exist?("/sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state")
92   munin_plugin "cpuspeed"
93 else
94   munin_plugin "cpuspeed" do
95     action :delete
96   end
97 end
98
99 munin_plugin_conf "df" do
100   template "df.erb"
101 end
102
103 munin_plugin "df"
104 munin_plugin "df_inode"
105
106 munin_plugin "diskstats"
107 munin_plugin "entropy"
108 munin_plugin "forks"
109
110 if node[:kernel][:modules].include?("nf_conntrack")
111   package "conntrack"
112
113   munin_plugin "fw_conntrack"
114   munin_plugin "fw_forwarded_local"
115 else
116   munin_plugin "fw_conntrack" do
117     action :delete
118   end
119
120   munin_plugin "fw_forwarded_local" do
121     action :delete
122   end
123 end
124
125 if File.read("/proc/sys/net/ipv4/ip_forward").chomp == "1"
126   munin_plugin "fw_packets"
127 else
128   munin_plugin "fw_packets" do
129     action :delete
130   end
131 end
132
133 if File.exist?("/sbin/hpasmcli")
134   munin_plugin "hpasmcli2_temp" do
135     target "hpasmcli2_"
136   end
137
138   munin_plugin "hpasmcli2_fans" do
139     target "hpasmcli2_"
140   end
141 else
142   munin_plugin "hpasmcli2_temp" do
143     action :delete
144   end
145
146   munin_plugin "hpasmcli2_fans" do
147     action :delete
148   end
149 end
150
151 munin_plugin "hpasmcli_temp" do # ~FC005
152   action :delete
153 end
154
155 munin_plugin "hpasmcli_fans" do
156   action :delete
157 end
158
159 munin_plugin "http_loadtime" do
160   action :delete
161 end
162
163 node[:network][:interfaces].each do |ifname, ifattr|
164   if ifattr[:encapsulation] == "Ethernet" && ifattr[:state] == "up"
165     if node[:hardware] &&
166        node[:hardware][:network] &&
167        node[:hardware][:network][ifname][:device] =~ /^virtio/
168       munin_plugin_conf "if_#{ifname}" do
169         template "if.erb"
170         variables :ifname => ifname
171       end
172     else
173       munin_plugin_conf "if_#{ifname}" do
174         action :delete
175       end
176     end
177
178     munin_plugin "if_err_#{ifname}" do
179       target "if_err_"
180     end
181
182     munin_plugin "if_#{ifname}" do
183       target "if_"
184     end
185   else
186     munin_plugin "if_err_#{ifname}" do
187       action :delete
188     end
189
190     munin_plugin "if_#{ifname}" do
191       action :delete
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_conf "ipmi" do
202     action :delete
203   end
204
205   munin_plugin "ipmi_fans" do
206     action :delete
207   end
208
209   munin_plugin "ipmi_temp" do
210     action :delete
211   end
212
213   munin_plugin "ipmi_power" do
214     action :delete
215     only_if { node[:lsb][:release].to_f >= 14.04 }
216   end
217 else
218   munin_plugin_conf "ipmi" do
219     template "ipmi.erb"
220   end
221
222   munin_plugin "ipmi_fans" do
223     target "ipmi_"
224   end
225
226   munin_plugin "ipmi_temp" do
227     target "ipmi_"
228   end
229
230   munin_plugin "ipmi_power" do
231     target "ipmi_"
232     only_if { node[:lsb][:release].to_f >= 14.04 }
233   end
234 end
235
236 munin_plugin "irqstats"
237 munin_plugin "load"
238 munin_plugin "memory"
239 munin_plugin "netstat"
240
241 if node[:kernel][:modules].include?("nfsv3")
242   munin_plugin "nfs_client"
243 else
244   munin_plugin "nfs_client" do
245     action :delete
246   end
247 end
248
249 if node[:kernel][:modules].include?("nfsv4")
250   munin_plugin "nfs4_client"
251 else
252   munin_plugin "nfs4_client" do
253     action :delete
254   end
255 end
256
257 if node[:kernel][:modules].include?("nfsd")
258   munin_plugin "nfsd"
259   munin_plugin "nfsd4"
260 else
261   munin_plugin "nfsd" do
262     action :delete
263   end
264
265   munin_plugin "nfsd4" do
266     action :delete
267   end
268 end
269
270 munin_plugin "open_files"
271 munin_plugin "open_inodes"
272
273 munin_plugin "postfix_mailqueue" do
274   action :delete
275 end
276
277 munin_plugin "postfix_mailvolume" do
278   action :delete
279 end
280
281 munin_plugin "processes"
282 munin_plugin "proc_pri"
283
284 sensors_fan = false
285 sensors_temp = false
286 sensors_volt = false
287
288 Dir.glob("/sys/class/hwmon/hwmon*").each do |hwmon|
289   hwmon = "#{hwmon}/device" unless File.exist?("#{hwmon}/name")
290
291   sensors_fan = true unless Dir.glob("#{hwmon}/fan*_input").empty?
292   sensors_temp = true unless Dir.glob("#{hwmon}/temp*_input").empty?
293   sensors_volt = true unless Dir.glob("#{hwmon}/in*_input").empty?
294 end
295
296 package "lm-sensors" if sensors_fan || sensors_temp || sensors_volt
297
298 if sensors_fan
299   munin_plugin "sensors_fan" do
300     target "sensors_"
301   end
302 else
303   munin_plugin "sensors_fan" do
304     action :delete
305   end
306 end
307
308 if sensors_temp
309   munin_plugin "sensors_temp" do
310     target "sensors_"
311   end
312 else
313   munin_plugin "sensors_temp" do
314     action :delete
315   end
316 end
317
318 if sensors_volt
319   munin_plugin "sensors_volt" do
320     target "sensors_"
321     conf "sensors_volt.erb"
322   end
323 else
324   munin_plugin "sensors_volt" do
325     action :delete
326   end
327 end
328
329 munin_plugin "swap"
330 munin_plugin "tcp"
331 munin_plugin "threads"
332 munin_plugin "uptime"
333 munin_plugin "users"
334 munin_plugin "vmstat"