]> git.openstreetmap.org Git - chef.git/blob - cookbooks/munin/recipes/plugins.rb
Merge remote-tracking branch 'github/pull/528'
[chef.git] / cookbooks / munin / recipes / plugins.rb
1 #
2 # Cookbook:: 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 #     https://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 "munin"
21
22 remote_directory "/usr/local/share/munin/plugins" do
23   source "plugins"
24   owner "root"
25   group "root"
26   mode "755"
27   files_owner "root"
28   files_group "root"
29   files_mode "755"
30   purge true
31 end
32
33 remote_directory "/etc/munin/plugin-conf.d" do
34   source "plugin-conf.d"
35   owner "root"
36   group "munin"
37   mode "750"
38   files_owner "root"
39   files_group "root"
40   files_mode "644"
41   purge false
42   notifies :restart, "service[munin-node]"
43 end
44
45 if Dir.glob("/proc/acpi/thermal_zone/*/temperature").empty?
46   munin_plugin "acpi" do
47     action :delete
48   end
49 else
50   munin_plugin "acpi"
51 end
52
53 # apcpdu_
54 munin_plugin "cpu"
55
56 if File.exist?("/sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state")
57   munin_plugin "cpuspeed"
58 else
59   munin_plugin "cpuspeed" do
60     action :delete
61   end
62 end
63
64 munin_plugin_conf "df" do
65   template "df.erb"
66 end
67
68 munin_plugin "df"
69 munin_plugin "df_inode"
70
71 munin_plugin_conf "diskstats" do
72   template "diskstats.erb"
73 end
74
75 munin_plugin "diskstats"
76 munin_plugin "entropy"
77 munin_plugin "forks"
78
79 if node[:kernel][:modules].include?("nf_conntrack")
80   package "conntrack"
81
82   munin_plugin "fw_conntrack"
83   munin_plugin "fw_forwarded_local"
84 else
85   munin_plugin "fw_conntrack" do
86     action :delete
87   end
88
89   munin_plugin "fw_forwarded_local" do
90     action :delete
91   end
92 end
93
94 if File.read("/proc/sys/net/ipv4/ip_forward").chomp == "1"
95   munin_plugin "fw_packets"
96 else
97   munin_plugin "fw_packets" do
98     action :delete
99   end
100 end
101
102 if File.exist?("/sbin/hpasmcli")
103   munin_plugin "hpasmcli2_temp" do
104     target "hpasmcli2_"
105   end
106
107   munin_plugin "hpasmcli2_fans" do
108     target "hpasmcli2_"
109   end
110 else
111   munin_plugin "hpasmcli2_temp" do
112     action :delete
113   end
114
115   munin_plugin "hpasmcli2_fans" do
116     action :delete
117   end
118 end
119
120 node[:network][:interfaces].each do |ifname, ifattr|
121   if ifattr[:flags]&.include?("UP") && !ifattr[:flags].include?("LOOPBACK")
122     if node[:hardware] &&
123        node[:hardware][:network] &&
124        node[:hardware][:network][ifname][:device] =~ /^virtio/
125       munin_plugin_conf "if_#{ifname}" do
126         template "if.erb"
127         variables :ifname => ifname
128       end
129     else
130       munin_plugin_conf "if_#{ifname}" do
131         action :delete
132       end
133     end
134
135     munin_plugin "if_err_#{ifname}" do
136       target "if_err_"
137     end
138
139     munin_plugin "if_#{ifname}" do
140       target "if_"
141     end
142   else
143     munin_plugin "if_err_#{ifname}" do
144       action :delete
145     end
146
147     munin_plugin "if_#{ifname}" do
148       action :delete
149     end
150   end
151 end
152
153 munin_plugin "interrupts"
154 munin_plugin "iostat"
155 munin_plugin "iostat_ios"
156
157 if Dir.glob("/dev/ipmi*").empty?
158   munin_plugin_conf "ipmi" do
159     action :delete
160   end
161
162   munin_plugin "ipmi_fans" do
163     action :delete
164   end
165
166   munin_plugin "ipmi_temp" do
167     action :delete
168   end
169
170   munin_plugin "ipmi_power" do
171     action :delete
172   end
173 else
174   munin_plugin_conf "ipmi" do
175     template "ipmi.erb"
176   end
177
178   munin_plugin "ipmi_fans" do
179     target "ipmi_"
180   end
181
182   munin_plugin "ipmi_temp" do
183     target "ipmi_"
184   end
185
186   munin_plugin "ipmi_power" do
187     target "ipmi_"
188   end
189 end
190
191 munin_plugin "irqstats"
192 munin_plugin "load"
193 munin_plugin "memory"
194 munin_plugin "netstat"
195
196 munin_plugin "nfs_client" do
197   action :delete
198 end
199
200 munin_plugin "nfs4_client" do
201   action :delete
202 end
203
204 munin_plugin "nfsd" do
205   action :delete
206 end
207
208 munin_plugin "nfsd4" do
209   action :delete
210 end
211
212 munin_plugin "open_files"
213 munin_plugin "open_inodes"
214
215 munin_plugin "postfix_mailqueue" do
216   action :delete
217 end
218
219 munin_plugin "postfix_mailvolume" do
220   action :delete
221 end
222
223 munin_plugin "processes"
224 munin_plugin "proc_pri"
225
226 sensors_fan = false
227 sensors_temp = false
228 sensors_volt = false
229
230 Dir.glob("/sys/class/hwmon/hwmon*").each do |hwmon|
231   hwmon = "#{hwmon}/device" unless File.exist?("#{hwmon}/name")
232
233   sensors_fan = true unless Dir.glob("#{hwmon}/fan*_input").empty?
234   sensors_temp = true unless Dir.glob("#{hwmon}/temp*_input").empty?
235   sensors_volt = true unless Dir.glob("#{hwmon}/in*_input").empty?
236 end
237
238 package "lm-sensors" if sensors_fan || sensors_temp || sensors_volt
239
240 if sensors_fan
241   munin_plugin "sensors_fan" do
242     target "sensors_"
243   end
244 else
245   munin_plugin "sensors_fan" do
246     action :delete
247   end
248 end
249
250 if sensors_temp
251   munin_plugin "sensors_temp" do
252     target "sensors_"
253   end
254 else
255   munin_plugin "sensors_temp" do
256     action :delete
257   end
258 end
259
260 if sensors_volt
261   munin_plugin "sensors_volt" do
262     target "sensors_"
263     conf "sensors_volt.erb"
264   end
265 else
266   munin_plugin "sensors_volt" do
267     action :delete
268   end
269 end
270
271 munin_plugin "swap"
272 munin_plugin "tcp"
273 munin_plugin "threads"
274 munin_plugin "uptime"
275 munin_plugin "users"
276 munin_plugin "vmstat"