]> git.openstreetmap.org Git - chef.git/blob - cookbooks/postgresql/providers/munin.rb
Modernise more LWRPs
[chef.git] / cookbooks / postgresql / providers / munin.rb
1 #
2 # Cookbook Name:: postgresql
3 # Provider:: postgresql_munin
4 #
5 # Copyright 2015, 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 def whyrun_supported?
21   true
22 end
23
24 use_inline_resources
25
26 action :create do
27   cluster = node[:postgresql][:clusters] && node[:postgresql][:clusters][new_resource.cluster]
28   database = new_resource.database
29
30   if cluster
31     %w[cache connections locks querylength scans size transactions tuples].each do |plugin|
32       munin_plugin "postgres_#{plugin}_#{database}:#{suffix}" do
33         target "postgres_#{plugin}_"
34         conf "munin.erb"
35         conf_cookbook "postgresql"
36         conf_variables :port => cluster[:port]
37         restart_munin false
38       end
39     end
40   else
41     Chef::Log.info "Postgres cluster #{new_resource.cluster} not found"
42   end
43 end
44
45 action :delete do
46   database = new_resource.database
47
48   %w[cache connections locks querylength scans size transactions tuples].each do |plugin|
49     munin_plugin "postgres_#{plugin}_#{database}:#{suffix}" do
50       action :delete
51       restart_munin false
52     end
53   end
54 end
55
56 def suffix
57   new_resource.cluster.tr("/", ":")
58 end