]> git.openstreetmap.org Git - chef.git/blob - cookbooks/munin/recipes/default.rb
Use systemd to manage munin-node on Ubuntu 15.10
[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 "df"
102 munin_plugin "df_inode"
103 munin_plugin "diskstats"
104 munin_plugin "entropy"
105 munin_plugin "forks"
106
107 if node[:kernel][:modules].include?("nf_conntrack")
108   package "conntrack"
109
110   munin_plugin "fw_conntrack"
111   munin_plugin "fw_forwarded_local"
112 else
113   munin_plugin "fw_conntrack" do
114     action :delete
115   end
116
117   munin_plugin "fw_forwarded_local" do
118     action :delete
119   end
120 end
121
122 if File.read("/proc/sys/net/ipv4/ip_forward").chomp == "1"
123   munin_plugin "fw_packets"
124 else
125   munin_plugin "fw_packets" do
126     action :delete
127   end
128 end
129
130 if File.exist?("/sbin/hpasmcli")
131   munin_plugin "hpasmcli2_temp" do
132     target "hpasmcli2_"
133   end
134
135   munin_plugin "hpasmcli2_fans" do
136     target "hpasmcli2_"
137   end
138 else
139   munin_plugin "hpasmcli2_temp" do
140     action :delete
141   end
142
143   munin_plugin "hpasmcli2_fans" do
144     action :delete
145   end
146 end
147
148 munin_plugin "hpasmcli_temp" do # ~FC005
149   action :delete
150 end
151
152 munin_plugin "hpasmcli_fans" do
153   action :delete
154 end
155
156 munin_plugin "http_loadtime" do
157   action :delete
158 end
159
160 node[:network][:interfaces].each do |ifname, ifattr|
161   if ifattr[:encapsulation] == "Ethernet" && ifattr[:state] == "up"
162     munin_plugin "if_err_#{ifname}" do
163       target "if_err_"
164     end
165
166     munin_plugin "if_#{ifname}" do
167       target "if_"
168     end
169   else
170     munin_plugin "if_err_#{ifname}" do
171       action :delete
172     end
173
174     munin_plugin "if_#{ifname}" do
175       action :delete
176     end
177   end
178 end
179
180 munin_plugin "interrupts"
181 munin_plugin "iostat"
182 munin_plugin "iostat_ios"
183
184 if Dir.glob("/dev/ipmi*").empty?
185   munin_plugin_conf "ipmi" do
186     action :delete
187   end
188
189   munin_plugin "ipmi_fans" do
190     action :delete
191   end
192
193   munin_plugin "ipmi_temp" do
194     action :delete
195   end
196
197   munin_plugin "ipmi_power" do
198     action :delete
199     only_if { node[:lsb][:release].to_f >= 14.04 }
200   end
201 else
202   munin_plugin_conf "ipmi" do
203     template "ipmi.erb"
204   end
205
206   munin_plugin "ipmi_fans" do
207     target "ipmi_"
208   end
209
210   munin_plugin "ipmi_temp" do
211     target "ipmi_"
212   end
213
214   munin_plugin "ipmi_power" do
215     target "ipmi_"
216     only_if { node[:lsb][:release].to_f >= 14.04 }
217   end
218 end
219
220 munin_plugin "irqstats"
221 munin_plugin "load"
222 munin_plugin "memory"
223 munin_plugin "netstat"
224
225 if node[:kernel][:modules].include?("nfsv3")
226   munin_plugin "nfs_client"
227 else
228   munin_plugin "nfs_client" do
229     action :delete
230   end
231 end
232
233 if node[:kernel][:modules].include?("nfsv4")
234   munin_plugin "nfs4_client"
235 else
236   munin_plugin "nfs4_client" do
237     action :delete
238   end
239 end
240
241 if node[:kernel][:modules].include?("nfsd")
242   munin_plugin "nfsd"
243   munin_plugin "nfsd4"
244 else
245   munin_plugin "nfsd" do
246     action :delete
247   end
248
249   munin_plugin "nfsd4" do
250     action :delete
251   end
252 end
253
254 munin_plugin "open_files"
255 munin_plugin "open_inodes"
256
257 munin_plugin "postfix_mailqueue" do
258   action :delete
259 end
260
261 munin_plugin "postfix_mailvolume" do
262   action :delete
263 end
264
265 munin_plugin "processes"
266 munin_plugin "proc_pri"
267
268 sensors_fan = false
269 sensors_temp = false
270 sensors_volt = false
271
272 Dir.glob("/sys/class/hwmon/hwmon*").each do |hwmon|
273   hwmon = "#{hwmon}/device" unless File.exist?("#{hwmon}/name")
274
275   sensors_fan = true unless Dir.glob("#{hwmon}/fan*_input").empty?
276   sensors_temp = true unless Dir.glob("#{hwmon}/temp*_input").empty?
277   sensors_volt = true unless Dir.glob("#{hwmon}/in*_input").empty?
278 end
279
280 if sensors_fan || sensors_temp || sensors_volt
281   package "lm-sensors"
282 end
283
284 if sensors_fan
285   munin_plugin "sensors_fan" do
286     target "sensors_"
287   end
288 else
289   munin_plugin "sensors_fan" do
290     action :delete
291   end
292 end
293
294 if sensors_temp
295   munin_plugin "sensors_temp" do
296     target "sensors_"
297   end
298 else
299   munin_plugin "sensors_temp" do
300     action :delete
301   end
302 end
303
304 if sensors_volt
305   munin_plugin "sensors_volt" do
306     target "sensors_"
307     conf "sensors_volt.erb"
308   end
309 else
310   munin_plugin "sensors_volt" do
311     action :delete
312   end
313 end
314
315 munin_plugin "swap"
316 munin_plugin "tcp"
317 munin_plugin "threads"
318 munin_plugin "uptime"
319 munin_plugin "users"
320 munin_plugin "vmstat"