]> git.openstreetmap.org Git - chef.git/blob - cookbooks/munin/recipes/default.rb
c01d84130a08469e9f0c32a66e0f475f94bbd28c
[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 >= 15.10
26     provider Chef::Provider::Service::Systemd
27   elsif node[:lsb][:release].to_f >= 14.04
28     provider Chef::Provider::Service::Upstart
29   end
30   action [:enable, :start]
31   supports :status => true, :restart => true, :reload => true
32 end
33
34 servers = search(:node, "recipes:munin\\:\\:server") # ~FC010
35
36 servers.each do |server|
37   server.interfaces(:role => :external) do |interface|
38     firewall_rule "accept-munin-#{server}" do
39       action :accept
40       family interface[:family]
41       source "#{interface[:zone]}:#{interface[:address]}"
42       dest "fw"
43       proto "tcp:syn"
44       dest_ports "munin"
45       source_ports "1024:"
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 Dir.glob("/proc/acpi/thermal_zone/*/temperature").empty?
83   munin_plugin "acpi" do
84     action :delete
85   end
86 else
87   munin_plugin "acpi"
88 end
89
90 # apcpdu_
91 munin_plugin "cpu"
92
93 if File.exist?("/sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state")
94   munin_plugin "cpuspeed"
95 else
96   munin_plugin "cpuspeed" do
97     action :delete
98   end
99 end
100
101 munin_plugin_conf "df" do
102   template "df.erb"
103 end
104
105 munin_plugin "df"
106 munin_plugin "df_inode"
107
108 munin_plugin "diskstats"
109 munin_plugin "entropy"
110 munin_plugin "forks"
111
112 if node[:kernel][:modules].include?("nf_conntrack")
113   package "conntrack"
114
115   munin_plugin "fw_conntrack"
116   munin_plugin "fw_forwarded_local"
117 else
118   munin_plugin "fw_conntrack" do
119     action :delete
120   end
121
122   munin_plugin "fw_forwarded_local" do
123     action :delete
124   end
125 end
126
127 if File.read("/proc/sys/net/ipv4/ip_forward").chomp == "1"
128   munin_plugin "fw_packets"
129 else
130   munin_plugin "fw_packets" do
131     action :delete
132   end
133 end
134
135 if File.exist?("/sbin/hpasmcli")
136   munin_plugin "hpasmcli2_temp" do
137     target "hpasmcli2_"
138   end
139
140   munin_plugin "hpasmcli2_fans" do
141     target "hpasmcli2_"
142   end
143 else
144   munin_plugin "hpasmcli2_temp" do
145     action :delete
146   end
147
148   munin_plugin "hpasmcli2_fans" do
149     action :delete
150   end
151 end
152
153 munin_plugin "hpasmcli_temp" do # ~FC005
154   action :delete
155 end
156
157 munin_plugin "hpasmcli_fans" do
158   action :delete
159 end
160
161 munin_plugin "http_loadtime" do
162   action :delete
163 end
164
165 node[:network][:interfaces].each do |ifname, ifattr|
166   if ifattr[:encapsulation] == "Ethernet" && ifattr[:state] == "up"
167     munin_plugin "if_err_#{ifname}" do
168       target "if_err_"
169     end
170
171     munin_plugin "if_#{ifname}" do
172       target "if_"
173     end
174   else
175     munin_plugin "if_err_#{ifname}" do
176       action :delete
177     end
178
179     munin_plugin "if_#{ifname}" do
180       action :delete
181     end
182   end
183 end
184
185 munin_plugin "interrupts"
186 munin_plugin "iostat"
187 munin_plugin "iostat_ios"
188
189 if Dir.glob("/dev/ipmi*").empty?
190   munin_plugin_conf "ipmi" do
191     action :delete
192   end
193
194   munin_plugin "ipmi_fans" do
195     action :delete
196   end
197
198   munin_plugin "ipmi_temp" do
199     action :delete
200   end
201
202   munin_plugin "ipmi_power" do
203     action :delete
204     only_if { node[:lsb][:release].to_f >= 14.04 }
205   end
206 else
207   munin_plugin_conf "ipmi" do
208     template "ipmi.erb"
209   end
210
211   munin_plugin "ipmi_fans" do
212     target "ipmi_"
213   end
214
215   munin_plugin "ipmi_temp" do
216     target "ipmi_"
217   end
218
219   munin_plugin "ipmi_power" do
220     target "ipmi_"
221     only_if { node[:lsb][:release].to_f >= 14.04 }
222   end
223 end
224
225 munin_plugin "irqstats"
226 munin_plugin "load"
227 munin_plugin "memory"
228 munin_plugin "netstat"
229
230 if node[:kernel][:modules].include?("nfsv3")
231   munin_plugin "nfs_client"
232 else
233   munin_plugin "nfs_client" do
234     action :delete
235   end
236 end
237
238 if node[:kernel][:modules].include?("nfsv4")
239   munin_plugin "nfs4_client"
240 else
241   munin_plugin "nfs4_client" do
242     action :delete
243   end
244 end
245
246 if node[:kernel][:modules].include?("nfsd")
247   munin_plugin "nfsd"
248   munin_plugin "nfsd4"
249 else
250   munin_plugin "nfsd" do
251     action :delete
252   end
253
254   munin_plugin "nfsd4" do
255     action :delete
256   end
257 end
258
259 munin_plugin "open_files"
260 munin_plugin "open_inodes"
261
262 munin_plugin "postfix_mailqueue" do
263   action :delete
264 end
265
266 munin_plugin "postfix_mailvolume" do
267   action :delete
268 end
269
270 munin_plugin "processes"
271 munin_plugin "proc_pri"
272
273 sensors_fan = false
274 sensors_temp = false
275 sensors_volt = false
276
277 Dir.glob("/sys/class/hwmon/hwmon*").each do |hwmon|
278   hwmon = "#{hwmon}/device" unless File.exist?("#{hwmon}/name")
279
280   sensors_fan = true unless Dir.glob("#{hwmon}/fan*_input").empty?
281   sensors_temp = true unless Dir.glob("#{hwmon}/temp*_input").empty?
282   sensors_volt = true unless Dir.glob("#{hwmon}/in*_input").empty?
283 end
284
285 if sensors_fan || sensors_temp || sensors_volt
286   package "lm-sensors"
287 end
288
289 if sensors_fan
290   munin_plugin "sensors_fan" do
291     target "sensors_"
292   end
293 else
294   munin_plugin "sensors_fan" do
295     action :delete
296   end
297 end
298
299 if sensors_temp
300   munin_plugin "sensors_temp" do
301     target "sensors_"
302   end
303 else
304   munin_plugin "sensors_temp" do
305     action :delete
306   end
307 end
308
309 if sensors_volt
310   munin_plugin "sensors_volt" do
311     target "sensors_"
312     conf "sensors_volt.erb"
313   end
314 else
315   munin_plugin "sensors_volt" do
316     action :delete
317   end
318 end
319
320 munin_plugin "swap"
321 munin_plugin "tcp"
322 munin_plugin "threads"
323 munin_plugin "uptime"
324 munin_plugin "users"
325 munin_plugin "vmstat"