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