diff --git a/manifests/profile/base/metrics/collectd.pp b/manifests/profile/base/metrics/collectd.pp index 8aaf98b91..282e90e29 100644 --- a/manifests/profile/base/metrics/collectd.pp +++ b/manifests/profile/base/metrics/collectd.pp @@ -214,6 +214,11 @@ # (Optional) Boolean. Set to true if sensubility should be executed by exec plugin. # Defaults to false. # +# [*enable_libpodstats*] +# (Optional) Boolean. Set to true if the collectd libpodstats plugin should be +# loaded +# Defaults to false. +# class tripleo::profile::base::metrics::collectd ( $step = Integer(hiera('step')), $enable_file_logging = false, @@ -259,10 +264,20 @@ class tripleo::profile::base::metrics::collectd ( $collectd_manage_repo = false, $python_read_plugins = [], $enable_sensubility = false, + $enable_libpodstats = false, ) { + if $step >= 3 { + if $enable_libpodstats { + $typesdb = ['/usr/share/collectd/types.db', '/usr/share/collectd/types.db.libpodstats'] + include ::tripleo::profile::base::metrics::collectd::libpodstats + } else { + $typesdb = ['/usr/share/collectd/types.db'] + } + class {'::collectd': - manage_repo => $collectd_manage_repo + manage_repo => $collectd_manage_repo, + typesdb => $typesdb, } class { '::collectd::plugin::python': diff --git a/manifests/profile/base/metrics/collectd/libpodstats.pp b/manifests/profile/base/metrics/collectd/libpodstats.pp new file mode 100644 index 000000000..95a9fc84e --- /dev/null +++ b/manifests/profile/base/metrics/collectd/libpodstats.pp @@ -0,0 +1,70 @@ +# Copyright 2018 Red Hat, Inc. +# +# 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 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# == Define: tripleo::profile::base::metrics::collectd::sensubility +# +# This is used to create configuration file for collectd-sensubility plugin +# +# === Parameters +# +# [*ensure*] +# (Optional) String. Action to perform with sensubility plugin +# configuration file. +# Defaults to 'present' +# +# [*config_path*] +# (Optional) String. Path to configuration file. +# Defaults to /etc/collectd.d/libpodstats.conf +class tripleo::profile::base::metrics::collectd::libpodstats ( + $ensure = 'present', + $config_path = '/etc/collectd.d/libpodstats.conf' +) { + + $db = '/usr/share/collectd/types.db.libpodstats' + + package { 'collectd-libpod-stats': + ensure => $ensure + } + + ::collectd::type { 'pod_cpu': + target => $db, + types => [{ + ds_type => 'GAUGE', + min => 0, + max => 100.1, + ds_name => 'percent', + }, + { + ds_type => 'DERIVE', + min => 0, + max => 'U', + ds_name => 'time', + } + ] + } + + ::collectd::type { 'pod_memory': + target => $db, + ds_type => 'GAUGE', + min => 0, + max => 281474976710656, + ds_name => 'value', + } + + file { $config_path: + ensure => $ensure, + mode => '0644', + content => template('tripleo/metrics/libpodstats.conf.epp'), + } +} diff --git a/spec/classes/tripleo_profile_base_metrics_collectd_spec.rb b/spec/classes/tripleo_profile_base_metrics_collectd_spec.rb index dae3c3bdd..bbc3eaaa9 100644 --- a/spec/classes/tripleo_profile_base_metrics_collectd_spec.rb +++ b/spec/classes/tripleo_profile_base_metrics_collectd_spec.rb @@ -1,3 +1,4 @@ + # # Copyright (C) 2017 Red Hat, Inc. # @@ -26,6 +27,15 @@ checks={\"standalone_check\":{\"command\":\"echo 'foobar'\",\"interval\":5}} [amqp1] " + +libpodstats_typesdb = '/usr/share/collectd/types.db.libpodstats' + +libpodstats_conf = ' +LoadPlugin libpodstats + + +' + exec_cmd = <<-EOS Exec \"collectd:collectd\" \"collectd-sensubility\" EOS @@ -116,6 +126,46 @@ describe 'tripleo::profile::base::metrics::collectd' do is_expected.to contain_file('/etc/collectd-sensubility.conf').with_content(sensubility_conf) end end + + context 'with defaults and enabled libpodstats' do + let(:params) do + { :step => 3, + :enable_libpodstats => true } + end + it '' do + is_expected.to compile.with_all_deps + is_expected.to contain_package('collectd-libpod-stats').with(:ensure => 'present') + is_expected.to contain_class('collectd').with({ + :typesdb => [ + '/usr/share/collectd/types.db', + libpodstats_typesdb, + ], + }) + is_expected.to contain_collectd__type('pod_memory').with({ + :target => libpodstats_typesdb, + :ds_type => 'GAUGE', + :min => 0, + :max => 281474976710656, + :ds_name => 'value', + }) + is_expected.to contain_collectd__type('pod_cpu').with({ + :target => libpodstats_typesdb, + :types => [{ + 'ds_type' => 'GAUGE', + 'min' => 0, + 'max' => 100.1, + 'ds_name' => 'percent', + }, + { + 'ds_type' => 'DERIVE', + 'min' => 0, + 'max' => 'U', + 'ds_name' => 'time', + }, + ], + }) + end + end end on_supported_os.each do |os, facts| diff --git a/templates/metrics/libpodstats.conf.epp b/templates/metrics/libpodstats.conf.epp new file mode 100644 index 000000000..6a2a39592 --- /dev/null +++ b/templates/metrics/libpodstats.conf.epp @@ -0,0 +1,4 @@ + +LoadPlugin libpodstats + +