Skip to content

Commit 662e6e7

Browse files
committed
Merge pull request #323 from t-8ch/typesdb
Typesdb
2 parents b16d0e7 + 49314f3 commit 662e6e7

6 files changed

Lines changed: 151 additions & 0 deletions

File tree

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,36 @@ class { 'collectd::plugin::zfs_arc':
11231123
}
11241124
```
11251125

1126+
types.db
1127+
--------
1128+
1129+
Collectd needs to know how to handle each collected datapoint.
1130+
For this it uses a database file called [`types.db`](https://collectd.org/documentation/manpages/types.db.5.shtml)
1131+
1132+
Those files can be created using the `collectd::typesdb` and `collectd::type`
1133+
define resources.
1134+
1135+
```puppet
1136+
$db = '/etc/collectd/types.db'
1137+
collectd::typesdb { $db: }
1138+
1139+
collectd::type { "response_size:${db}":
1140+
target => $db,
1141+
ds_type => 'ABSOLUTE',
1142+
min => 0,
1143+
max => 10000000,
1144+
ds_name => 'value',
1145+
}
1146+
1147+
class { 'collectd':
1148+
typesdb => [
1149+
'/usr/share/collectd/types.db',
1150+
$typesdb,
1151+
],
1152+
}
1153+
```
1154+
1155+
11261156
##Limitations
11271157

11281158
See metadata.json for supported platforms

manifests/type.pp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
define collectd::type (
2+
$target,
3+
$ds_type,
4+
$ds = $title,
5+
$min = 'U',
6+
$max = 'U',
7+
$ds_name = 'value',
8+
) {
9+
validate_string($ds_name)
10+
$upper_ds_type = upcase($ds_type)
11+
12+
validate_re($upper_ds_type,
13+
['^ABSOLUTE$', '^COUNTER$', '^DERIVE$', '^GAUGE$'])
14+
15+
if $min != 'U' {
16+
validate_numeric($min)
17+
}
18+
19+
if $max != 'U' {
20+
validate_numeric($max)
21+
}
22+
23+
$content = "${ds}\t${ds_name}:${upper_ds_type}:${min}:${max}"
24+
25+
concat::fragment { "${target}/${ds}":
26+
content => $content,
27+
target => $target,
28+
order => $ds,
29+
}
30+
}

manifests/typesdb.pp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
define collectd::typesdb (
2+
$path = $title,
3+
) {
4+
include collectd::params
5+
6+
7+
concat { $path:
8+
ensure => present,
9+
owner => 'root',
10+
group => $collectd::params::root_group,
11+
mode => '0640',
12+
ensure_newline => true,
13+
force => true,
14+
notify => Service['collectd'],
15+
}
16+
}

spec/defines/collectd_type_spec.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
require 'spec_helper'
2+
3+
describe 'collectd::type', :type => :define do
4+
let :facts do
5+
{
6+
:osfamily => 'Debian',
7+
:id => 'root',
8+
:concat_basedir => tmpfilename('collectd-type'),
9+
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
10+
}
11+
end
12+
13+
context 'define a type' do
14+
let(:title) { 'index' }
15+
let :params do
16+
{
17+
:target => '/etc/collectd/types.db',
18+
:ds_type => 'ABSOLUTE',
19+
:min => 4,
20+
:max => 5,
21+
:ds_name => 'some_name',
22+
}
23+
end
24+
25+
it 'creates an entry' do
26+
should contain_concat__fragment('/etc/collectd/types.db/index').with({
27+
:target => '/etc/collectd/types.db',
28+
:content => "index\tsome_name:ABSOLUTE:4:5",
29+
})
30+
end
31+
end
32+
end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
require 'spec_helper'
2+
3+
describe 'collectd::typesdb', :type => :define do
4+
let :facts do
5+
{
6+
:osfamily => 'Debian',
7+
:id => 'root',
8+
:concat_basedir => tmpfilename('collectd-typesdb'),
9+
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
10+
}
11+
end
12+
13+
context 'without any types' do
14+
let(:title) { '/etc/collectd/types.db' }
15+
16+
it 'should contain empty types.db' do
17+
should contain_concat('/etc/collectd/types.db')
18+
should contain_file('/etc/collectd/types.db')
19+
end
20+
end
21+
end

tests/typesdb.pp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
$typesdb = '/etc/collectd/types.db'
2+
3+
class { 'collectd':
4+
typesdb => [
5+
$typesdb,
6+
],
7+
}
8+
9+
collectd::typesdb { $typesdb: }
10+
collectd::type {
11+
'bytes':
12+
target => $typesdb,
13+
ds_type => 'GAUGE',
14+
min => 0;
15+
'absolute':
16+
target => $typesdb,
17+
ds => 'absolute',
18+
ds_type => 'ABSOLUTE',
19+
ds_name => 'value',
20+
min => '0',
21+
max => 'U';
22+
}

0 commit comments

Comments
 (0)