X-Git-Url: https://git.openstreetmap.org./chef.git/blobdiff_plain/4ffc2ea14e4ca0db54934cd79551446528bf3c26..b1e1a323520b711f1b9226d8eefd1e106bf74c17:/cookbooks/postgresql/resources/munin.rb diff --git a/cookbooks/postgresql/resources/munin.rb b/cookbooks/postgresql/resources/munin.rb index aa4f8c8e6..4b69d4224 100644 --- a/cookbooks/postgresql/resources/munin.rb +++ b/cookbooks/postgresql/resources/munin.rb @@ -1,14 +1,14 @@ # -# Cookbook Name:: postgresql +# Cookbook:: postgresql # Resource:: postgresql_munin # -# Copyright 2015, OpenStreetMap Foundation +# Copyright:: 2015, OpenStreetMap Foundation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, @@ -17,12 +17,49 @@ # limitations under the License. # -actions :create, :delete +unified_mode true + default_action :create -attribute :name, :kind_of => String, :name_attribute => true -attribute :cluster, :kind_of => String, :required => true -attribute :database, :kind_of => String, :required => true +property :munin, :kind_of => String, :name_property => true +property :cluster, :kind_of => String, :required => true +property :database, :kind_of => String, :required => true + +action :create do + cluster = node[:postgresql][:clusters] && node[:postgresql][:clusters][new_resource.cluster] + database = new_resource.database + + if cluster + %w[cache connections locks querylength scans size transactions tuples].each do |plugin| + munin_plugin "postgres_#{plugin}_#{database}:#{suffix}" do + target "postgres_#{plugin}_" + conf "munin.erb" + conf_cookbook "postgresql" + conf_variables :port => cluster[:port] + restart_munin false + end + end + else + Chef::Log.info "Postgres cluster #{new_resource.cluster} not found" + end +end + +action :delete do + database = new_resource.database + + %w[cache connections locks querylength scans size transactions tuples].each do |plugin| + munin_plugin "postgres_#{plugin}_#{database}:#{suffix}" do + action :delete + restart_munin false + end + end +end + +action_class do + def suffix + new_resource.cluster.tr("/", ":") + end +end def after_created notifies :restart, "service[munin-node]"