diff --git a/README.md b/README.md index 3ae238916..aa88642d9 100644 --- a/README.md +++ b/README.md @@ -1123,6 +1123,36 @@ class { 'collectd::plugin::zfs_arc': } ``` +types.db +-------- + +Collectd needs to know how to handle each collected datapoint. +For this it uses a database file called [`types.db`](https://collectd.org/documentation/manpages/types.db.5.shtml) + +Those files can be created using the `collectd::typesdb` and `collectd::type` +define resources. + +```puppet +$db = '/etc/collectd/types.db' +collectd::typesdb { $db: } + +collectd::type { "response_size:${db}": + target => $db, + ds_type => 'ABSOLUTE', + min => 0, + max => 10000000, + ds_name => 'value', +} + +class { 'collectd': + typesdb => [ + '/usr/share/collectd/types.db', + $typesdb, + ], +} +``` + + ##Limitations See metadata.json for supported platforms diff --git a/manifests/type.pp b/manifests/type.pp new file mode 100644 index 000000000..c81e4a196 --- /dev/null +++ b/manifests/type.pp @@ -0,0 +1,30 @@ +define collectd::type ( + $target, + $ds_type, + $ds = $title, + $min = 'U', + $max = 'U', + $ds_name = 'value', +) { + validate_string($ds_name) + $upper_ds_type = upcase($ds_type) + + validate_re($upper_ds_type, + ['^ABSOLUTE$', '^COUNTER$', '^DERIVE$', '^GAUGE$']) + + if $min != 'U' { + validate_numeric($min) + } + + if $max != 'U' { + validate_numeric($max) + } + + $content = "${ds}\t${ds_name}:${upper_ds_type}:${min}:${max}" + + concat::fragment { "${target}/${ds}": + content => $content, + target => $target, + order => $ds, + } +} diff --git a/manifests/typesdb.pp b/manifests/typesdb.pp new file mode 100644 index 000000000..7022c2eb9 --- /dev/null +++ b/manifests/typesdb.pp @@ -0,0 +1,16 @@ +define collectd::typesdb ( + $path = $title, +) { + include collectd::params + + + concat { $path: + ensure => present, + owner => 'root', + group => $collectd::params::root_group, + mode => '0640', + ensure_newline => true, + force => true, + notify => Service['collectd'], + } +} diff --git a/spec/defines/collectd_type_spec.rb b/spec/defines/collectd_type_spec.rb new file mode 100644 index 000000000..ec9813122 --- /dev/null +++ b/spec/defines/collectd_type_spec.rb @@ -0,0 +1,32 @@ +require 'spec_helper' + +describe 'collectd::type', :type => :define do + let :facts do + { + :osfamily => 'Debian', + :id => 'root', + :concat_basedir => tmpfilename('collectd-type'), + :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', + } + end + + context 'define a type' do + let(:title) { 'index' } + let :params do + { + :target => '/etc/collectd/types.db', + :ds_type => 'ABSOLUTE', + :min => 4, + :max => 5, + :ds_name => 'some_name', + } + end + + it 'creates an entry' do + should contain_concat__fragment('/etc/collectd/types.db/index').with({ + :target => '/etc/collectd/types.db', + :content => "index\tsome_name:ABSOLUTE:4:5", + }) + end + end +end diff --git a/spec/defines/collectd_typesdb_spec.rb b/spec/defines/collectd_typesdb_spec.rb new file mode 100644 index 000000000..33b8a5e7a --- /dev/null +++ b/spec/defines/collectd_typesdb_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +describe 'collectd::typesdb', :type => :define do + let :facts do + { + :osfamily => 'Debian', + :id => 'root', + :concat_basedir => tmpfilename('collectd-typesdb'), + :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', + } + end + + context 'without any types' do + let(:title) { '/etc/collectd/types.db' } + + it 'should contain empty types.db' do + should contain_concat('/etc/collectd/types.db') + should contain_file('/etc/collectd/types.db') + end + end +end diff --git a/tests/typesdb.pp b/tests/typesdb.pp new file mode 100644 index 000000000..278ae7505 --- /dev/null +++ b/tests/typesdb.pp @@ -0,0 +1,22 @@ +$typesdb = '/etc/collectd/types.db' + +class { 'collectd': + typesdb => [ + $typesdb, + ], +} + +collectd::typesdb { $typesdb: } +collectd::type { + 'bytes': + target => $typesdb, + ds_type => 'GAUGE', + min => 0; + 'absolute': + target => $typesdb, + ds => 'absolute', + ds_type => 'ABSOLUTE', + ds_name => 'value', + min => '0', + max => 'U'; +}