Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add recipe for wmi_check #499

Merged
merged 3 commits into from Feb 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
111 changes: 111 additions & 0 deletions recipes/wmi_check.rb
@@ -0,0 +1,111 @@
include_recipe 'datadog::dd-agent'

# see example configuration file here:
# https://github.com/DataDog/integrations-core/blob/master/wmi_check/conf.yaml.example

# node['datadog']['wmi_check'] =
# {
# "instances": [
# {
# "class": "Win32_OperatingSystem",
# "metrics": [
# [
# "NumberOfProcesses",
# "system.proc.count",
# "gauge"
# ],
# [
# "NumberOfUsers",
# "system.users.count",
# "gauge"
# ]
# ]
# },
# {
# "class": "Win32_PerfFormattedData_PerfProc_Process",
# "metrics": [
# [
# "ThreadCount",
# "my_app.threads.count",
# "gauge"
# ],
# [
# "VirtualBytes",
# "my_app.mem.virtual",
# "gauge"
# ]
# ],
# "filters": [
# {
# "Name": "myapp"
# }
# ],
# "constant_tags": [
# "role:test"
# ]
# },
# {
# "class": "Win32_PerfFormattedData_PerfProc_Process",
# "metrics": [
# [
# "ThreadCount",
# "proc.threads.count",
# "gauge"
# ],
# [
# "VirtualBytes",
# "proc.mem.virtual",
# "gauge"
# ],
# [
# "PercentProcessorTime",
# "proc.cpu_pct",
# "gauge"
# ]
# ],
# "filters": [
# {
# "Name": "app1"
# },
# {
# "Name": "app2"
# },
# {
# "Name": "app3"
# }
# ],
# "tag_by": "Name"
# },
# {
# "class": "Win32_PerfFormattedData_PerfProc_Process",
# "metrics": [
# [
# "IOReadBytesPerSec",
# "proc.io.bytes_read",
# "gauge"
# ]
# ],
# "filters": [
# {
# "Name": "app%"
# }
# ],
# "tag_by": "Name",
# "tag_queries": [
# [
# "IDProcess",
# "Win32_Process",
# "Handle",
# "CommandLine"
# ]
# ]
# }
# ],
# "logs": null
# }

datadog_monitor 'wmi_check' do
init_config node['datadog']['wmi_check']['init_config']
instances node['datadog']['wmi_check']['instances']
logs node['datadog']['wmi_check']['logs']
end
160 changes: 160 additions & 0 deletions spec/integrations/wmi_check_spec.rb
@@ -0,0 +1,160 @@
describe 'datadog::wmi_check' do
context 'config wmi_check' do
expected_yaml = <<-EOF
init_config:
instances:
- class: Win32_OperatingSystem
metrics:
- [NumberOfProcesses, system.proc.count, gauge]
- [NumberOfUsers, system.users.count, gauge]
- class: Win32_PerfFormattedData_PerfProc_Process
metrics:
- [ThreadCount, my_app.threads.count, gauge]
- [VirtualBytes, my_app.mem.virtual, gauge]
filters:
- Name: myapp
constant_tags:
- 'role:test'
- class: Win32_PerfFormattedData_PerfProc_Process
metrics:
- [ThreadCount, proc.threads.count, gauge]
- [VirtualBytes, proc.mem.virtual, gauge]
- [PercentProcessorTime, proc.cpu_pct, gauge]
filters:
- Name: app1
- Name: app2
- Name: app3
tag_by: Name
- class: Win32_PerfFormattedData_PerfProc_Process
metrics:
- [IOReadBytesPerSec, proc.io.bytes_read, gauge]
filters:
- Name: 'app%'
tag_by: Name
tag_queries:
- [IDProcess, Win32_Process, Handle, CommandLine]
logs: ~
EOF

cached(:chef_run) do
ChefSpec::SoloRunner.new(step_into: ['datadog_monitor']) do |node|
node.automatic['languages'] = { 'python' => { 'version' => '2.7.2' } }
node.set['datadog'] = {
api_key: 'someapikey',
wmi_check: {
instances: [
{
class: 'Win32_OperatingSystem',
metrics: [
[
'NumberOfProcesses',
'system.proc.count',
'gauge'
],
[
'NumberOfUsers',
'system.users.count',
'gauge'
]
]
},
{
class: 'Win32_PerfFormattedData_PerfProc_Process',
metrics: [
[
'ThreadCount',
'my_app.threads.count',
'gauge'
],
[
'VirtualBytes',
'my_app.mem.virtual',
'gauge'
]
],
filters: [
{
Name: 'myapp'
}
],
constant_tags: [
'role:test'
]
},
{
class: 'Win32_PerfFormattedData_PerfProc_Process',
metrics: [
[
'ThreadCount',
'proc.threads.count',
'gauge'
],
[
'VirtualBytes',
'proc.mem.virtual',
'gauge'
],
[
'PercentProcessorTime',
'proc.cpu_pct',
'gauge'
]
],
filters: [
{
Name: 'app1'
},
{
Name: 'app2'
},
{
Name: 'app3'
}
],
tag_by: 'Name'
},
{
class: 'Win32_PerfFormattedData_PerfProc_Process',
metrics: [
[
'IOReadBytesPerSec',
'proc.io.bytes_read',
'gauge'
]
],
filters: [
{
Name: 'app%'
}
],
tag_by: 'Name',
tag_queries: [
[
'IDProcess',
'Win32_Process',
'Handle',
'CommandLine'
]
]
}
]
}
}
end.converge(described_recipe)
end

subject { chef_run }

it_behaves_like 'datadog-agent'

it { is_expected.to include_recipe('datadog::dd-agent') }

it { is_expected.to add_datadog_monitor('wmi_check') }

it 'renders expected YAML config file' do
expect(chef_run).to(render_file('/etc/dd-agent/conf.d/wmi_check.yaml').with_content { |content|
expect(YAML.safe_load(content).to_json).to be_json_eql(YAML.safe_load(expected_yaml).to_json)
})
end
end
end
77 changes: 4 additions & 73 deletions templates/default/wmi_check.yaml.erb
@@ -1,75 +1,6 @@
<%= JSON.parse(({'logs' => @logs }).to_json).to_yaml %>

init_config:

instances:
# Each WMI query has 2 required options, `class` and `metrics` and two
# optional options, `filters` and `tag_by`.
#
# `class` is the name of the WMI class, for example Win32_OperatingSystem
# or Win32_PerfFormattedData_PerfProc_Process. You can find many of the
# standard class names on the MSDN docs at
# http://msdn.microsoft.com/en-us/library/windows/desktop/aa394084.aspx.
# The Win32_FormattedData_* classes provide many useful performance counters
# by default.
#
#
# `metrics` is a list of metrics you want to capture, with each item in the
# list being a set of [WMI property name, metric name, metric type].
#
# - The property name is something like `NumberOfUsers` or `ThreadCount`.
# The standard properties are also available on the MSDN docs for each
# class.
#
# - The metric name is the name you want to show up in Datadog.
#
# - The metric type is from the standard choices for all agent checks, such
# as gauge, rate, histogram or counter.
#
#
# `filters` is a list of filters on the WMI query you may want. For example,
# for a process-based WMI class you may want metrics for only certain
# processes running on your machine, so you could add a filter for each
# process name. See below for an example of this case.
#
#
# `tag_by` optionally lets you tag each metric with a property from the
# WMI class you're using. This is only useful when you will have multiple
# values for your WMI query. The examples below show how you can tag your
# process metrics with the process name (giving a tag of "name:app_name").


# Fetch the number of processes and users
- class: Win32_OperatingSystem
metrics:
- [NumberOfProcesses, system.proc.count, gauge]
- [NumberOfUsers, system.users.count, gauge]

# Fetch metrics for a single running application, called myapp
- class: Win32_PerfFormattedData_PerfProc_Process
metrics:
- [ThreadCount, my_app.threads.count, gauge]
- [VirtualBytes, my_app.mem.virtual, gauge]
filters:
- Name: myapp

# Fetch process metrics for a set of processes, tagging by app name.
- class: Win32_PerfFormattedData_PerfProc_Process
metrics:
- [ThreadCount, proc.threads.count, gauge]
- [VirtualBytes, proc.mem.virtual, gauge]
- [PercentProcessorTime, proc.cpu_pct, gauge]
filters:
- Name: app1
- Name: app2
- Name: app3
tag_by: Name

# Fetch process metrics for every available process, tagging by app name.
- class: Win32_PerfFormattedData_PerfProc_Process
metrics:
- [IOReadBytesPerSec, proc.io.bytes_read, gauge]
- [IOWriteBytesPerSec, proc.io.bytes_written, gauge]
tag_by: Name
# Generated by Chef, local modifications will be overwritten

<%= JSON.parse(({ 'instances' => @instances, 'logs' => @logs }).to_json).to_yaml %>

# Nothing to configure here
init_config: