Skip to content

Commit

Permalink
Merge pull request #323 from t-8ch/typesdb
Browse files Browse the repository at this point in the history
Typesdb
  • Loading branch information
blkperl committed Sep 4, 2015
2 parents b16d0e7 + 49314f3 commit 662e6e7
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 0 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions manifests/type.pp
Original file line number Diff line number Diff line change
@@ -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,
}
}
16 changes: 16 additions & 0 deletions manifests/typesdb.pp
Original file line number Diff line number Diff line change
@@ -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'],
}
}
32 changes: 32 additions & 0 deletions spec/defines/collectd_type_spec.rb
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions spec/defines/collectd_typesdb_spec.rb
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions tests/typesdb.pp
Original file line number Diff line number Diff line change
@@ -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';
}

0 comments on commit 662e6e7

Please sign in to comment.