]> git.openstreetmap.org Git - chef.git/blob - cookbooks/munin/recipes/default.rb
51020994c8fcff0f3a52d2134ea1fb60cf895717
[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 # ipmi_
170 munin_plugin "irqstats"
171
172 Dir.new("/sys/block").each do |device|
173   if device.match(/^sd/)
174     munin_plugin "linux_diskstat_iops_#{device}" do
175       target "linux_diskstat_"
176     end
177
178     munin_plugin "linux_diskstat_latency_#{device}" do
179       target "linux_diskstat_"
180     end
181
182     munin_plugin "linux_diskstat_throughput_#{device}" do
183       target "linux_diskstat_"
184     end
185   end
186 end
187
188 munin_plugin "load"
189 munin_plugin "memory"
190 munin_plugin "netstat"
191
192 if File.exists?("/proc/net/rpc/nfs")
193   munin_plugin "nfs4_client"
194 else
195   munin_plugin "nfs4_client" do
196     action :delete
197   end
198 end
199
200 if File.exists?("/proc/net/rpc/nfsd")
201   munin_plugin "nfsd"
202   munin_plugin "nfsd4"
203 else
204   munin_plugin "nfsd" do
205     action :delete
206   end
207
208   munin_plugin "nfsd4" do
209     action :delete
210   end
211 end
212
213 munin_plugin "open_files"
214 munin_plugin "open_inodes"
215
216 munin_plugin "postfix_mailqueue" do
217   action :delete
218 end
219
220 munin_plugin "postfix_mailvolume" do
221   action :delete
222 end
223
224 munin_plugin "processes"
225 munin_plugin "proc_pri"
226
227 Dir.glob("/sys/class/hwmon/hwmon*").each do |hwmon|
228   hwmon = "#{hwmon}/device" unless File.exists?("#{hwmon}/name")
229
230   if Dir.glob("#{hwmon}/fan*_input").empty?
231     munin_plugin "sensors_fan" do
232       action :delete
233     end
234   else
235     munin_plugin "sensors_fan" do
236       target "sensors_"
237     end
238   end
239
240   if Dir.glob("#{hwmon}/temp*_input").empty?
241     munin_plugin "sensors_temp" do
242       action :delete
243     end
244   else
245     munin_plugin "sensors_temp" do
246       target "sensors_"
247     end
248   end
249
250   if Dir.glob("#{hwmon}/in*_input").empty?
251     munin_plugin "sensors_volt" do
252       action :delete
253     end
254   else
255     munin_plugin "sensors_volt" do
256       target "sensors_"
257     end
258   end
259 end
260
261 # smart_
262 munin_plugin "swap"
263 munin_plugin "threads"
264 munin_plugin "uptime"
265 munin_plugin "users"
266 munin_plugin "vmstat"