Add recipe for sqlserver
ADD
recipes/sqlserver.rb
+include_recipe 'datadog::dd-agent'
+
+# see example configuration file here:
+# https://github.com/DataDog/integrations-core/blob/master/sqlserver/conf.yaml.example
+
+# Example 1 - Optionally, custom Metrics have been configured under init_config
+# node['datadog']['sqlserver'] =
+# {
+# "instances": [
+# {
+# "host": "fakehostname,1433",
+# "connector": "odbc",
+# "driver": "SQL Server",
+# "username": "fake_user",
+# "password": "bogus_pw",
+# "command_timeout": 30,
+# "database": "fake_db_name",
+# "tags": [
+# "test_tag_name"
+# ]
+# }
+# ],
+# "init_config": {
+# "custom_metrics": [
+# {
+# "name": "sqlserver.clr.execution",
+# "counter_name": "CLR execution"
+# },
+# {
+# "name": "sqlserver.exec.in_progress",
+# "counter_name": "OLEDB calls",
+# "instance_name": "Cumulative execution time (ms) per second"
+# },
+# {
+# "name": "sqlserver.db.commit_table_entries",
+# "counter_name": "Log Flushes/sec",
+# "instance_name": "ALL",
+# "tag_by": "db"
+# }
+# ]
+# }
+# }
+
+# Example 2 - Optionally, custom Metrics have not been configured
+# node['datadog']['sqlserver'] =
+# {
+# "instances": [
+# {
+# "host": "fakehostname,1433",
+# "connector": "odbc",
+# "driver": "SQL Server",
+# "username": "fake_user",
+# "password": "bogus_pw",
+# "command_timeout": 30,
+# "database": "fake_db_name",
+# "tags": [
+# "test_tag_name"
+# ]
+# }
+# ]
+# }
+
+datadog_monitor 'sqlserver' do
+ init_config node['datadog']['sqlserver']['init_config']
+ instances node['datadog']['sqlserver']['instances']
+end

ADD
spec/integrations/sqlserver_spec.rb
+describe 'datadog::sqlserver' do
+ context 'config 1' do
+ expected_yaml = <<-EOF
+ init_config:
+ custom_metrics:
+ - name: sqlserver.clr.execution
+ counter_name: CLR execution
+ - name: sqlserver.exec.in_progress
+ counter_name: OLEDB calls
+ instance_name: Cumulative execution time (ms) per second
+ - name: sqlserver.db.commit_table_entries
+ counter_name: Log Flushes/sec
+ instance_name: ALL
+ tag_by: db
+ instances:
+ - host: fakehostname,1433
+ connector: odbc
+ driver: SQL Server
+ username: fake_user
+ password: bogus_pw
+ command_timeout: 30
+ database: fake_db_name
+ tags:
+ - test_tag_name
+ 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',
+ sqlserver: {
+ instances: [
+ {
+ host: 'fakehostname,1433',
+ connector: 'odbc',
+ driver: 'SQL Server',
+ username: 'fake_user',
+ password: 'bogus_pw',
+ command_timeout: 30,
+ database: 'fake_db_name',
+ tags: ['test_tag_name']
+ }
+ ],
+ init_config: {
+ custom_metrics: [
+ {
+ name: 'sqlserver.clr.execution',
+ counter_name: 'CLR execution'
+ },
+ {
+ name: 'sqlserver.exec.in_progress',
+ counter_name: 'OLEDB calls',
+ instance_name: 'Cumulative execution time (ms) per second'
+ },
+ {
+ name: 'sqlserver.db.commit_table_entries',
+ counter_name: 'Log Flushes/sec',
+ instance_name: 'ALL',
+ tag_by: 'db'
+ }
+ ]
+ }
+ }
+ }
+ 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('sqlserver') }
+
+ it 'renders expected YAML config file' do
+ expect(chef_run).to render_file('/etc/dd-agent/conf.d/sqlserver.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
+
+describe 'datadog::sqlserver' do
+ context 'config 2' do
+ expected_yaml = <<-EOF
+ init_config: {}
+
+ instances:
+ - host: fakehostname,1433
+ connector: odbc
+ driver: SQL Server
+ username: fake_user
+ password: bogus_pw
+ command_timeout: 30
+ database: fake_db_name
+ tags:
+ - test_tag_name
+ 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',
+ sqlserver: {
+ instances: [
+ {
+ host: 'fakehostname,1433',
+ connector: 'odbc',
+ driver: 'SQL Server',
+ username: 'fake_user',
+ password: 'bogus_pw',
+ command_timeout: 30,
+ database: 'fake_db_name',
+ tags: ['test_tag_name']
+ }
+ ]
+ }
+ }
+ 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('sqlserver') }
+
+ it 'renders expected YAML config file' do
+ expect(chef_run).to render_file('/etc/dd-agent/conf.d/sqlserver.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

MODIFY
templates/default/sqlserver.yaml.erb
templates/default/sqlserver.yaml.erb
-init_config:
- #
- # By default, we only capture *some* of the metrics available in the
- # `sys.dm_os_performance_counters` table. You can easily add additional
- # metrics by following the custom_metrics structure shown below.
- #
- #custom_metrics:
- #
- # This is a basic custom metric. There is not instance assicated with
- # this counter.
- # Options for type are: gauge, rate, histogram
- #
- # - name: sqlserver.clr.execution
- # type: gauge
- # counter_name: CLR Execution
- #
- # This counter has multiple instances assocaited with it and we're
- # choosing to only fetch the '_Total' instance.
- #
- # - name: sqlserver.exec.in_progress
- # type: gauge
- # counter_name: OLEDB calls
- # instance_name: Cumulative execution time (ms) per second
- #
- # This counter has multiple instances assocaited with it and we want
- # every instance available. We'll use the special case ALL instance
- # which *requires* a value for "tag_by". In this case, we'll get metrics
- # tagged as "db:mydb1", "db:mydb2".
- #
- # - name: sqlserver.db.commit_table_entries
- # type: gauge
- # counter_name: Log Flushes/sec
- # instance_name: ALL
- # tag_by: db
+# Generated by Chef, local modifications will be overwritten
-instances:
- - host: HOST,PORT
- username: my_username
- password: my_password
+<%= JSON.parse(({'init_config' => @init_config, 'instances' => @instances}).to_json).to_yaml %>

Add recipe for sqlserver (#425)