]> git.openstreetmap.org Git - chef.git/blob - cookbooks/munin/recipes/default.rb
fb1225c2f25a056e7572b5e936e0f91de60ae8fd
[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") # ~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 0644
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 0755
62   files_owner "root"
63   files_group "root"
64   files_mode 0755
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 0750
73   files_owner "root"
74   files_group "root"
75   files_mode 0644
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 "df"
100 munin_plugin "df_inode"
101 munin_plugin "diskstats"
102 munin_plugin "entropy"
103 munin_plugin "forks"
104
105 if node[:kernel][:modules].include?("nf_conntrack")
106   package "conntrack"
107
108   munin_plugin "fw_conntrack"
109   munin_plugin "fw_forwarded_local"
110 else
111   munin_plugin "fw_conntrack" do
112     action :delete
113   end
114
115   munin_plugin "fw_forwarded_local" do
116     action :delete
117   end
118 end
119
120 if File.read("/proc/sys/net/ipv4/ip_forward").chomp == "1"
121   munin_plugin "fw_packets"
122 else
123   munin_plugin "fw_packets" do
124     action :delete
125   end
126 end
127
128 if File.exist?("/sbin/hpasmcli")
129   munin_plugin "hpasmcli2_temp" do
130     target "hpasmcli2_"
131   end
132
133   munin_plugin "hpasmcli2_fans" do
134     target "hpasmcli2_"
135   end
136 else
137   munin_plugin "hpasmcli2_temp" do
138     action :delete
139   end
140
141   munin_plugin "hpasmcli2_fans" do
142     action :delete
143   end
144 end
145
146 munin_plugin "hpasmcli_temp" do # ~FC005
147   action :delete
148 end
149
150 munin_plugin "hpasmcli_fans" do
151   action :delete
152 end
153
154 munin_plugin "http_loadtime" do
155   action :delete
156 end
157
158 node[:network][:interfaces].each do |ifname, ifattr|
159   if ifattr[:encapsulation] == "Ethernet" && ifattr[:state] == "up"
160     munin_plugin "if_err_#{ifname}" do
161       target "if_err_"
162     end
163
164     munin_plugin "if_#{ifname}" do
165       target "if_"
166     end
167   else
168     munin_plugin "if_err_#{ifname}" do
169       action :delete
170     end
171
172     munin_plugin "if_#{ifname}" do
173       action :delete
174     end
175   end
176 end
177
178 munin_plugin "interrupts"
179 munin_plugin "iostat"
180 munin_plugin "iostat_ios"
181
182 if Dir.glob("/dev/ipmi*").empty?
183   munin_plugin_conf "ipmi" do
184     action :delete
185   end
186
187   munin_plugin "ipmi_fans" do
188     action :delete
189   end
190
191   munin_plugin "ipmi_temp" do
192     action :delete
193   end
194
195   munin_plugin "ipmi_power" do
196     action :delete
197     only_if { node[:lsb][:release].to_f >= 14.04 }
198   end
199 else
200   munin_plugin_conf "ipmi" do
201     template "ipmi.erb"
202   end
203
204   munin_plugin "ipmi_fans" do
205     target "ipmi_"
206   end
207
208   munin_plugin "ipmi_temp" do
209     target "ipmi_"
210   end
211
212   munin_plugin "ipmi_power" do
213     target "ipmi_"
214     only_if { node[:lsb][:release].to_f >= 14.04 }
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.exist?("#{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     conf "sensors_volt.erb"
306   end
307 else
308   munin_plugin "sensors_volt" do
309     action :delete
310   end
311 end
312
313 munin_plugin "swap"
314 munin_plugin "tcp"
315 munin_plugin "threads"
316 munin_plugin "uptime"
317 munin_plugin "users"
318 munin_plugin "vmstat"