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