]> git.openstreetmap.org Git - chef.git/blob - cookbooks/munin/recipes/default.rb
775acc095adc9aa26a838c7c23456c19de33e955
[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 # api_
89 munin_plugin "cpu"
90
91 if File.exists?("/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 File.exists?("/proc/net/ip_conntrack") or File.exists?("/proc/net/nf_conntrack")
106   munin_plugin "fw_conntrack"
107   munin_plugin "fw_forwarded_local"
108 else
109   munin_plugin "fw_conntrack" do
110     action :delete
111   end
112
113   munin_plugin "fw_forwarded_local" do
114     action :delete
115   end
116 end
117
118 if %x{sysctl -n net.ipv4.ip_forward}.chomp == "1"
119   munin_plugin "fw_packets"
120 else
121   munin_plugin "fw_packets" do
122     action :delete
123   end
124 end
125
126 # hddtemp_smartctl
127
128 if File.exists?("/sbin/hpasmcli")
129   munin_plugin "hpasmcli_temp"
130   munin_plugin "hpasmcli_fans"
131 else
132   munin_plugin "hpasmcli_temp" do
133     action :delete
134   end
135
136   munin_plugin "hpasmcli_fans" do
137     action :delete
138   end
139 end
140
141 munin_plugin "http_loadtime" do
142   action :delete
143 end
144
145 node[:network][:interfaces].each do |ifname,ifattr|
146   if ifname =~ /^eth\d+$/
147     if ifattr[:flags] and ifattr[:flags].include?("UP")
148       munin_plugin "if_err_#{ifname}" do
149         target "if_err_"
150       end
151
152       munin_plugin "if_#{ifname}" do
153         target "if_"
154       end
155     else
156       munin_plugin "if_err_#{ifname}" do
157         action :delete
158       end
159
160       munin_plugin "if_#{ifname}" do
161         action :delete
162       end
163     end
164   end
165 end
166
167 munin_plugin "interrupts"
168 munin_plugin "iostat"
169 munin_plugin "iostat_ios"
170 # ipmi_
171 munin_plugin "irqstats"
172
173 Dir.new("/sys/block").each do |device|
174   if device.match(/^sd/)
175     munin_plugin "linux_diskstat_iops_#{device}" do
176       target "linux_diskstat_"
177     end
178
179     munin_plugin "linux_diskstat_latency_#{device}" do
180       target "linux_diskstat_"
181     end
182
183     munin_plugin "linux_diskstat_throughput_#{device}" do
184       target "linux_diskstat_"
185     end
186   end
187 end
188
189 munin_plugin "load"
190 munin_plugin "memory"
191 # mod_tile_
192 # mysql_
193 munin_plugin "netstat"
194
195 if File.exists?("/proc/net/rpc/nfs")
196   munin_plugin "nfs4_client"
197 else
198   munin_plugin "nfs4_client" do
199     action :delete
200   end
201 end
202
203 if File.exists?("/proc/net/rpc/nfsd")
204   munin_plugin "nfsd"
205   munin_plugin "nfsd4"
206 else
207   munin_plugin "nfsd" do
208     action :delete
209   end
210
211   munin_plugin "nfsd4" do
212     action :delete
213   end
214 end
215
216 # nominatim_
217 munin_plugin "open_files"
218 munin_plugin "open_inodes"
219 # passenger_
220
221 munin_plugin "postfix_mailqueue" do
222   action :delete
223 end
224
225 munin_plugin "postfix_mailvolume" do
226   action :delete
227 end
228
229 # postgres_
230 munin_plugin "processes"
231 munin_plugin "proc_pri"
232 # renderd_
233 # replication_delay
234 # sensors_
235 # smart_
236 # squid_
237 munin_plugin "swap"
238 munin_plugin "threads"
239 munin_plugin "uptime"
240 munin_plugin "users"
241 munin_plugin "vmstat"