]> git.openstreetmap.org Git - chef.git/blob - cookbooks/munin/recipes/default.rb
Install lm-sensors when munin is doing sensor monitoring
[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, resources(: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, resources(: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 File.exists?("/proc/net/ip_conntrack") or File.exists?("/proc/net/nf_conntrack")
105   munin_plugin "fw_conntrack"
106   munin_plugin "fw_forwarded_local"
107 else
108   munin_plugin "fw_conntrack" do
109     action :delete
110   end
111
112   munin_plugin "fw_forwarded_local" do
113     action :delete
114   end
115 end
116
117 if %x{sysctl -n net.ipv4.ip_forward}.chomp == "1"
118   munin_plugin "fw_packets"
119 else
120   munin_plugin "fw_packets" do
121     action :delete
122   end
123 end
124
125 # hddtemp_smartctl
126
127 if File.exists?("/sbin/hpasmcli")
128   munin_plugin "hpasmcli_temp"
129   munin_plugin "hpasmcli_fans"
130 else
131   munin_plugin "hpasmcli_temp" do
132     action :delete
133   end
134
135   munin_plugin "hpasmcli_fans" do
136     action :delete
137   end
138 end
139
140 munin_plugin "http_loadtime" do
141   action :delete
142 end
143
144 node[:network][:interfaces].each do |ifname,ifattr|
145   if ifname =~ /^eth\d+$/
146     if ifattr[:flags] and ifattr[:flags].include?("UP")
147       munin_plugin "if_err_#{ifname}" do
148         target "if_err_"
149       end
150
151       munin_plugin "if_#{ifname}" do
152         target "if_"
153       end
154     else
155       munin_plugin "if_err_#{ifname}" do
156         action :delete
157       end
158
159       munin_plugin "if_#{ifname}" do
160         action :delete
161       end
162     end
163   end
164 end
165
166 munin_plugin "interrupts"
167 munin_plugin "iostat"
168 munin_plugin "iostat_ios"
169
170 if Dir.glob("/dev/ipmi*").empty?
171   munin_plugin "ipmi_fans" do
172     action :delete
173   end
174
175   munin_plugin "ipmi_temp" do
176     action :delete
177   end
178 else
179   munin_plugin "ipmi_fans" do
180     target "ipmi_"
181   end
182
183   munin_plugin "ipmi_temp" do
184     target "ipmi_"
185   end
186 end
187
188 munin_plugin "irqstats"
189
190 Dir.new("/sys/block").each do |device|
191   if device.match(/^sd/)
192     munin_plugin "linux_diskstat_iops_#{device}" do
193       target "linux_diskstat_"
194     end
195
196     munin_plugin "linux_diskstat_latency_#{device}" do
197       target "linux_diskstat_"
198     end
199
200     munin_plugin "linux_diskstat_throughput_#{device}" do
201       target "linux_diskstat_"
202     end
203   end
204 end
205
206 munin_plugin "load"
207 munin_plugin "memory"
208 munin_plugin "netstat"
209
210 if File.exists?("/proc/net/rpc/nfs")
211   munin_plugin "nfs4_client"
212 else
213   munin_plugin "nfs4_client" do
214     action :delete
215   end
216 end
217
218 if File.exists?("/proc/net/rpc/nfsd")
219   munin_plugin "nfsd"
220   munin_plugin "nfsd4"
221 else
222   munin_plugin "nfsd" do
223     action :delete
224   end
225
226   munin_plugin "nfsd4" do
227     action :delete
228   end
229 end
230
231 munin_plugin "open_files"
232 munin_plugin "open_inodes"
233
234 munin_plugin "postfix_mailqueue" do
235   action :delete
236 end
237
238 munin_plugin "postfix_mailvolume" do
239   action :delete
240 end
241
242 munin_plugin "processes"
243 munin_plugin "proc_pri"
244
245 Dir.glob("/sys/class/hwmon/hwmon*").each do |hwmon|
246   package "lm-sensors"
247
248   hwmon = "#{hwmon}/device" unless File.exists?("#{hwmon}/name")
249
250   if Dir.glob("#{hwmon}/fan*_input").empty?
251     munin_plugin "sensors_fan" do
252       action :delete
253     end
254   else
255     munin_plugin "sensors_fan" do
256       target "sensors_"
257     end
258   end
259
260   if Dir.glob("#{hwmon}/temp*_input").empty?
261     munin_plugin "sensors_temp" do
262       action :delete
263     end
264   else
265     munin_plugin "sensors_temp" do
266       target "sensors_"
267     end
268   end
269
270   if Dir.glob("#{hwmon}/in*_input").empty?
271     munin_plugin "sensors_volt" do
272       action :delete
273     end
274   else
275     munin_plugin "sensors_volt" do
276       target "sensors_"
277     end
278   end
279 end
280
281 # smart_
282 munin_plugin "swap"
283 munin_plugin "threads"
284 munin_plugin "uptime"
285 munin_plugin "users"
286 munin_plugin "vmstat"