Skip to content

Commit b254918

Browse files
authored
Merge pull request #263 from DataDog/jaime/envato-disk_integration
disk integration
2 parents 5f0787c + 591d197 commit b254918

3 files changed

Lines changed: 149 additions & 0 deletions

File tree

manifests/integrations/disk.pp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Class: datadog_agent::integrations::disk
2+
#
3+
# This class will install the necessary config to hook the disk check
4+
#
5+
# Parameters:
6+
# $use_mount
7+
# The use_mount parameter will instruct the check to collect disk
8+
# and fs metrics using mount points instead of volumes.
9+
# values: yes, no (Boolean, default: no)
10+
# $excluded_filesystems
11+
# The filesystems you wish to exclude, example: tmpfs, run (string or array)
12+
# $excluded_disks
13+
# The disks you (optional) wish to exclude, example: /dev/sda (string or array)
14+
# $excluded_disk_re
15+
# Regular expression (optional) to exclude disks, eg: /dev/sde.*
16+
# $excluded_mountpoint_re
17+
# Regular expression (optional) to exclude mountpoints, eg: /mnt/somebody-elses-problem.*
18+
# $all_partitions
19+
# The (optional) all_partitions parameter will instruct the check to
20+
# get metrics for all partitions. use_mount should be set to yes (to avoid
21+
# collecting empty device names) when using this option.
22+
# $tag_by_filesystem
23+
# The (optional) tag_by_filesystem parameter will instruct the check to
24+
# tag all disks with their filesystem (for ex: filesystem:nfs)
25+
# valuse: yes, no (Boolean, default: no)
26+
#
27+
# Sample Usage:
28+
#
29+
# class { 'datadog_agent::integrations::disk' :
30+
# use_mount => 'yes',
31+
# excluded_filesystems => '/dev/tmpfs',
32+
# excluded_disk_re => '/dev/sd[e-z]*'
33+
# }
34+
class datadog_agent::integrations::disk (
35+
$use_mount = 'no',
36+
$excluded_filesystems = undef,
37+
$excluded_disks = undef,
38+
$excluded_disk_re = undef,
39+
$excluded_mountpoint_re = undef,
40+
$all_partitions = undef,
41+
$tag_by_filesystem = undef
42+
) inherits datadog_agent::params {
43+
include datadog_agent
44+
45+
validate_re($use_mount, '^(no|yes)$', "use_mount should be either 'yes' or 'no'")
46+
if $all_partitions {
47+
validate_re($all_partitions, '^(no|yes)$', "all_partitions should be either 'yes' or 'no'")
48+
}
49+
50+
file { "${datadog_agent::params::conf_dir}/disk.yaml":
51+
ensure => file,
52+
owner => $datadog_agent::params::dd_user,
53+
group => $datadog_agent::params::dd_group,
54+
mode => '0600',
55+
content => template('datadog_agent/agent-conf.d/disk.yaml.erb'),
56+
require => Package[$datadog_agent::params::package_name],
57+
notify => Service[$datadog_agent::params::service_name]
58+
}
59+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
require 'spec_helper'
2+
3+
describe 'datadog_agent::integrations::disk' do
4+
let(:facts) {{
5+
operatingsystem: 'Ubuntu',
6+
}}
7+
let(:conf_dir) { '/etc/dd-agent/conf.d' }
8+
let(:dd_user) { 'dd-agent' }
9+
let(:dd_group) { 'root' }
10+
let(:dd_package) { 'datadog-agent' }
11+
let(:dd_service) { 'datadog-agent' }
12+
let(:conf_file) { "#{conf_dir}/disk.yaml" }
13+
14+
it { is_expected.to compile.with_all_deps }
15+
it { is_expected.to contain_file(conf_file).with_content(
16+
%r{\s+use_mount:\s+no$}
17+
).with(
18+
owner: dd_user,
19+
group: dd_group,
20+
mode: '0600',
21+
)}
22+
it { is_expected.to contain_file(conf_file).that_requires("Package[#{dd_package}]") }
23+
it { is_expected.to contain_file(conf_file).that_notifies("Service[#{dd_service}]") }
24+
25+
context 'compile errors for incorrect values' do
26+
let(:params) {{ use_mount: 'heaps' }}
27+
it do
28+
expect { is_expected.to compile }.to raise_error(/error\s+during\s+compilation/)
29+
end
30+
end
31+
32+
context 'we handle strings and arrays the same' do
33+
let(:params) {{
34+
use_mount: 'yes',
35+
excluded_filesystems: [ 'tmpfs', 'dev' ],
36+
excluded_disks: '/dev/sda1',
37+
excluded_disk_re: '/dev/sdb.*',
38+
excluded_mountpoint_re: '/mnt/other.*',
39+
all_partitions: 'yes',
40+
tag_by_filesystem: 'no'
41+
}}
42+
let(:yaml_conf) {
43+
<<-HEREDOC
44+
init_config:
45+
46+
instances:
47+
- use_mount: yes
48+
excluded_filesystems:
49+
- tmpfs
50+
- dev
51+
excluded_disks:
52+
- /dev/sda1
53+
excluded_disk_re: /dev/sdb.*
54+
excluded_mountpoint_re: /mnt/other.*
55+
all_partitions: yes
56+
tag_by_filesystem: no
57+
HEREDOC
58+
}
59+
it { is_expected.to contain_file(conf_file).with_content(yaml_conf) }
60+
end
61+
62+
end
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
init_config:
2+
3+
instances:
4+
- use_mount: <%= @use_mount %>
5+
<% if @excluded_filesystems -%>
6+
excluded_filesystems:
7+
<% (Array(@excluded_filesystems)).each do |fs| -%>
8+
- <%= fs %>
9+
<%- end -%>
10+
<% end -%>
11+
<% if @excluded_disks -%>
12+
excluded_disks:
13+
<% (Array(@excluded_disks)).each do |disk| -%>
14+
- <%= disk %>
15+
<% end -%>
16+
<% end -%>
17+
<% if @excluded_disk_re -%>
18+
excluded_disk_re: <%= @excluded_disk_re %>
19+
<% end -%>
20+
<% if @excluded_mountpoint_re -%>
21+
excluded_mountpoint_re: <%= @excluded_mountpoint_re %>
22+
<% end -%>
23+
<% if @all_partitions -%>
24+
all_partitions: <%= @all_partitions %>
25+
<% end -%>
26+
<% if @tag_by_filesystem -%>
27+
tag_by_filesystem: <%= @tag_by_filesystem %>
28+
<% end -%>

0 commit comments

Comments
 (0)