Add swap_percent_used metric

Change-Id: I1ac8dc82ecfd9c52ceaa58fbe06edfcea9576a05
This commit is contained in:
Igor Degtiarov 2016-08-17 12:59:37 +03:00 committed by Simon Pasquier
parent 55f62d4f9c
commit a0bd5a76d8
4 changed files with 16 additions and 3 deletions

View File

@ -34,6 +34,7 @@ local processes_map = {
-- this is needed for the libvirt metrics because in that case, collectd sends
-- the instance's ID instead of the hostname in the 'host' attribute
local hostname = read_config('hostname') or error('hostname must be specified')
local swap_size = (read_config('swap_size') or 0) + 0
function replace_dot_by_sep (str)
return string.gsub(str, '%.', sep)
@ -375,6 +376,14 @@ function process_message ()
if not skip_it then
utils.inject_tags(msg)
utils.safe_inject_message(msg)
if metric_source == 'swap' and metric_name == 'swap_used' and swap_size > 0 then
-- collectd 5.4.0 doesn't report the used swap in
-- percentage, this is why the metric is computed and
-- injected by this plugin.
msg['Fields']['name'] = 'swap_percent_used'
msg['Fields']['value'] = value / swap_size
utils.safe_inject_message(msg)
end
end
end
end

View File

@ -133,7 +133,8 @@ class lma_collector::collectd::base (
config_dir => $lma_collector::params::metric_config_dir,
filename => "${lma_collector::params::plugins_dir}/decoders/collectd.lua" ,
config => {
hostname => $real_hostname
hostname => $real_hostname,
swap_size => $::swapsize_mb * 1024 * 1024,
},
module_directory => $lua_modules_dir,
notify => Class['lma_collector::service::metric'],

View File

@ -16,7 +16,8 @@ require 'spec_helper'
describe 'lma_collector::collectd::base' do
let(:facts) do
{:kernel => 'Linux', :operatingsystem => 'Ubuntu',
:osfamily => 'Debian', :concat_basedir => '/foo'}
:osfamily => 'Debian', :concat_basedir => '/foo',
:swapsize_mb => 1024}
end
describe 'with defaults' do
@ -27,7 +28,7 @@ describe 'lma_collector::collectd::base' do
let(:facts) do
{:kernel => 'Linux', :operatingsystem => 'Ubuntu',
:osfamily => 'Debian', :concat_basedir => '/foo',
:interfaces => 'br-mgmt,en0,bond0,lo'}
:interfaces => 'br-mgmt,en0,bond0,lo', :swapsize_mb => 1024}
end
it { is_expected.to contain_class('collectd').with_purge(false) }

View File

@ -133,6 +133,8 @@ Swap
* ``swap_io_in``, the number of swap bytes written per second.
* ``swap_io_out``, the number of swap bytes read per second.
* ``swap_used``, the amount of used memory (in bytes) that is in the swap.
* ``swap_percent_used``, the amount of used memory (in percentages) that is in
the swap.
Users
^^^^^