]> git.openstreetmap.org Git - chef.git/blob - cookbooks/munin/recipes/default.rb
Add munin backup script
[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")
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 "ipmi_fans" do
184     action :delete
185   end
186
187   munin_plugin "ipmi_temp" do
188     action :delete
189   end
190
191   munin_plugin "ipmi_power" do
192     action :delete
193     only_if { node[:lsb][:release].to_f >= 14.04 }
194   end
195 else
196   munin_plugin "ipmi_fans" do
197     target "ipmi_"
198   end
199
200   munin_plugin "ipmi_temp" do
201     target "ipmi_"
202   end
203
204   munin_plugin "ipmi_power" do
205     target "ipmi_"
206     only_if { node[:lsb][:release].to_f >= 14.04 }
207   end
208 end
209
210 munin_plugin "irqstats"
211 munin_plugin "load"
212 munin_plugin "memory"
213 munin_plugin "netstat"
214
215 if node[:kernel][:modules].include?("nfsv3")
216   munin_plugin "nfs_client"
217 else
218   munin_plugin "nfs_client" do
219     action :delete
220   end
221 end
222
223 if node[:kernel][:modules].include?("nfsv4")
224   munin_plugin "nfs4_client"
225 else
226   munin_plugin "nfs4_client" do
227     action :delete
228   end
229 end
230
231 if node[:kernel][:modules].include?("nfsd")
232   munin_plugin "nfsd"
233   munin_plugin "nfsd4"
234 else
235   munin_plugin "nfsd" do
236     action :delete
237   end
238
239   munin_plugin "nfsd4" do
240     action :delete
241   end
242 end
243
244 munin_plugin "open_files"
245 munin_plugin "open_inodes"
246
247 munin_plugin "postfix_mailqueue" do
248   action :delete
249 end
250
251 munin_plugin "postfix_mailvolume" do
252   action :delete
253 end
254
255 munin_plugin "processes"
256 munin_plugin "proc_pri"
257
258 sensors_fan = false
259 sensors_temp = false
260 sensors_volt = false
261
262 Dir.glob("/sys/class/hwmon/hwmon*").each do |hwmon|
263   hwmon = "#{hwmon}/device" unless File.exist?("#{hwmon}/name")
264
265   sensors_fan = true unless Dir.glob("#{hwmon}/fan*_input").empty?
266   sensors_temp = true unless Dir.glob("#{hwmon}/temp*_input").empty?
267   sensors_volt = true unless Dir.glob("#{hwmon}/in*_input").empty?
268 end
269
270 if sensors_fan || sensors_temp || sensors_volt
271   package "lm-sensors"
272 end
273
274 if sensors_fan
275   munin_plugin "sensors_fan" do
276     target "sensors_"
277   end
278 else
279   munin_plugin "sensors_fan" do
280     action :delete
281   end
282 end
283
284 if sensors_temp
285   munin_plugin "sensors_temp" do
286     target "sensors_"
287   end
288 else
289   munin_plugin "sensors_temp" do
290     action :delete
291   end
292 end
293
294 if sensors_volt
295   munin_plugin "sensors_volt" do
296     target "sensors_"
297     conf "sensors_volt.erb"
298   end
299 else
300   munin_plugin "sensors_volt" do
301     action :delete
302   end
303 end
304
305 munin_plugin "swap"
306 munin_plugin "tcp"
307 munin_plugin "threads"
308 munin_plugin "uptime"
309 munin_plugin "users"
310 munin_plugin "vmstat"