]> git.openstreetmap.org Git - chef.git/blob - cookbooks/munin/recipes/default.rb
Use multipackage installs throughout
[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   action [:enable, :start]
24   supports :status => true, :restart => true, :reload => true
25 end
26
27 servers = search(:node, "recipes:munin\\:\\:server") # ~FC010
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 "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     if node[:hardware] &&
161        node[:hardware][:network] &&
162        node[:hardware][:network][ifname][:device] =~ /^virtio/
163       munin_plugin_conf "if_#{ifname}" do
164         template "if.erb"
165         variables :ifname => ifname
166       end
167     else
168       munin_plugin_conf "if_#{ifname}" do
169         action :delete
170       end
171     end
172
173     munin_plugin "if_err_#{ifname}" do
174       target "if_err_"
175     end
176
177     munin_plugin "if_#{ifname}" do
178       target "if_"
179     end
180   else
181     munin_plugin "if_err_#{ifname}" do
182       action :delete
183     end
184
185     munin_plugin "if_#{ifname}" do
186       action :delete
187     end
188   end
189 end
190
191 munin_plugin "interrupts"
192 munin_plugin "iostat"
193 munin_plugin "iostat_ios"
194
195 if Dir.glob("/dev/ipmi*").empty?
196   munin_plugin_conf "ipmi" do
197     action :delete
198   end
199
200   munin_plugin "ipmi_fans" do
201     action :delete
202   end
203
204   munin_plugin "ipmi_temp" do
205     action :delete
206   end
207
208   munin_plugin "ipmi_power" do
209     action :delete
210   end
211 else
212   munin_plugin_conf "ipmi" do
213     template "ipmi.erb"
214   end
215
216   munin_plugin "ipmi_fans" do
217     target "ipmi_"
218   end
219
220   munin_plugin "ipmi_temp" do
221     target "ipmi_"
222   end
223
224   munin_plugin "ipmi_power" do
225     target "ipmi_"
226   end
227 end
228
229 munin_plugin "irqstats"
230 munin_plugin "load"
231 munin_plugin "memory"
232 munin_plugin "netstat"
233
234 if node[:kernel][:modules].include?("nfsv3")
235   munin_plugin "nfs_client"
236 else
237   munin_plugin "nfs_client" do
238     action :delete
239   end
240 end
241
242 if node[:kernel][:modules].include?("nfsv4")
243   munin_plugin "nfs4_client"
244 else
245   munin_plugin "nfs4_client" do
246     action :delete
247   end
248 end
249
250 if node[:kernel][:modules].include?("nfsd")
251   munin_plugin "nfsd"
252   munin_plugin "nfsd4"
253 else
254   munin_plugin "nfsd" do
255     action :delete
256   end
257
258   munin_plugin "nfsd4" do
259     action :delete
260   end
261 end
262
263 munin_plugin "open_files"
264 munin_plugin "open_inodes"
265
266 munin_plugin "postfix_mailqueue" do
267   action :delete
268 end
269
270 munin_plugin "postfix_mailvolume" do
271   action :delete
272 end
273
274 munin_plugin "processes"
275 munin_plugin "proc_pri"
276
277 sensors_fan = false
278 sensors_temp = false
279 sensors_volt = false
280
281 Dir.glob("/sys/class/hwmon/hwmon*").each do |hwmon|
282   hwmon = "#{hwmon}/device" unless File.exist?("#{hwmon}/name")
283
284   sensors_fan = true unless Dir.glob("#{hwmon}/fan*_input").empty?
285   sensors_temp = true unless Dir.glob("#{hwmon}/temp*_input").empty?
286   sensors_volt = true unless Dir.glob("#{hwmon}/in*_input").empty?
287 end
288
289 package "lm-sensors" if sensors_fan || sensors_temp || sensors_volt
290
291 if sensors_fan
292   munin_plugin "sensors_fan" do
293     target "sensors_"
294   end
295 else
296   munin_plugin "sensors_fan" do
297     action :delete
298   end
299 end
300
301 if sensors_temp
302   munin_plugin "sensors_temp" do
303     target "sensors_"
304   end
305 else
306   munin_plugin "sensors_temp" do
307     action :delete
308   end
309 end
310
311 if sensors_volt
312   munin_plugin "sensors_volt" do
313     target "sensors_"
314     conf "sensors_volt.erb"
315   end
316 else
317   munin_plugin "sensors_volt" do
318     action :delete
319   end
320 end
321
322 munin_plugin "swap"
323 munin_plugin "tcp"
324 munin_plugin "threads"
325 munin_plugin "uptime"
326 munin_plugin "users"
327 munin_plugin "vmstat"