]> git.openstreetmap.org Git - chef.git/blob - cookbooks/munin/recipes/default.rb
0f6c67d86b4bc55659e5036ae889f11698f09f5b
[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 File.exists?("/proc/net/rpc/nfs")
209   munin_plugin "nfs4_client"
210 else
211   munin_plugin "nfs4_client" do
212     action :delete
213   end
214 end
215
216 if File.exists?("/proc/net/rpc/nfsd")
217   munin_plugin "nfsd"
218   munin_plugin "nfsd4"
219 else
220   munin_plugin "nfsd" do
221     action :delete
222   end
223
224   munin_plugin "nfsd4" do
225     action :delete
226   end
227 end
228
229 munin_plugin "open_files"
230 munin_plugin "open_inodes"
231
232 munin_plugin "postfix_mailqueue" do
233   action :delete
234 end
235
236 munin_plugin "postfix_mailvolume" do
237   action :delete
238 end
239
240 munin_plugin "processes"
241 munin_plugin "proc_pri"
242
243 sensors_fan = false
244 sensors_temp = false
245 sensors_volt = false
246
247 Dir.glob("/sys/class/hwmon/hwmon*").each do |hwmon|
248   package "lm-sensors"
249
250   hwmon = "#{hwmon}/device" unless File.exists?("#{hwmon}/name")
251
252   sensors_fan = true unless Dir.glob("#{hwmon}/fan*_input").empty?
253   sensors_temp = true unless Dir.glob("#{hwmon}/temp*_input").empty?
254   sensors_volt = true unless Dir.glob("#{hwmon}/in*_input").empty?
255 end
256
257 if sensors_fan
258   munin_plugin "sensors_fan" do
259     target "sensors_"
260   end
261 else
262   munin_plugin "sensors_fan" do
263     action :delete
264   end
265 end
266
267 if sensors_temp
268   munin_plugin "sensors_temp" do
269     target "sensors_"
270   end
271 else
272   munin_plugin "sensors_temp" do
273     action :delete
274   end
275 end
276
277 if sensors_volt
278   munin_plugin "sensors_volt" do
279     target "sensors_"
280   end
281 else
282   munin_plugin "sensors_volt" do
283     action :delete
284   end
285 end
286
287 node[:block_device].each do |name,attributes|
288   if attributes[:vendor] == "ATA"
289     munin_plugin "smart_#{name}" do
290       target "smart_"
291     end
292   else
293     munin_plugin "smart_#{name}" do
294       action :delete
295     end
296   end
297 end
298
299 munin_plugin "swap"
300 munin_plugin "threads"
301 munin_plugin "uptime"
302 munin_plugin "users"
303 munin_plugin "vmstat"