diff --git a/.kitchen.yml b/.kitchen.yml index e184fcad..c4d672e6 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -316,6 +316,32 @@ suites: - host: localhost port: 27017 +- name: datadog_mysql + run_list: + - recipe[datadog::mysql] + attributes: + datadog: + <<: *DATADOG + mysql: + instances: + - server: 1.1.1.1 + port: 3307 + user: my_username + pass: my_password + sock: /path/to/mysql.sock + tags: ['prod', 'my_app'] + options: + - 'replication: 0' + queries: + - type: gauge + field: users_count + metric: my_app.my_users.count + query: SELECT COUNT(1) AS users_count FROM users + - type: gauge + field: max_query_time + metric: mysql.performance.max_query_time + query: SELECT IFNULL(MAX(TIME), 0) AS max_query_time FROM INFORMATION_SCHEMA.PROCESSLIST WHERE COMMAND != 'Sleep' + - name: datadog_ntp run_list: - recipe[datadog::ntp] diff --git a/recipes/mysql.rb b/recipes/mysql.rb index 2883a046..70b6bdf9 100644 --- a/recipes/mysql.rb +++ b/recipes/mysql.rb @@ -17,6 +17,14 @@ # 'options' => [ # "replication: 0", # "galera_cluster: 1" +# ], +# 'queries' => [ +# { +# 'type' => 'gauge', +# 'field' => 'users_count' +# 'metric' => 'my_app.my_users.count', +# 'query' => 'SELECT COUNT(1) AS users_count FROM users' +# }, # ] # }, # ] diff --git a/templates/default/mysql.yaml.erb b/templates/default/mysql.yaml.erb index 874765da..65c779ef 100644 --- a/templates/default/mysql.yaml.erb +++ b/templates/default/mysql.yaml.erb @@ -21,6 +21,15 @@ instances: <%= o %> <% end -%> <% end -%> + <% if i.key?('queries') -%> + queries: + <% i['queries'].each do |q| -%> + - type: <%= q['type'] %> + field: <%= q['field'] %> + metric: <%= q['metric'] %> + query: <%= q['query'] %> + <% end -%> + <% end -%> <% end -%> # Nothing to configure here diff --git a/test/integration/datadog_mysql/serverspec/Gemfile b/test/integration/datadog_mysql/serverspec/Gemfile new file mode 120000 index 00000000..74f9789f --- /dev/null +++ b/test/integration/datadog_mysql/serverspec/Gemfile @@ -0,0 +1 @@ +../../helpers/serverspec/Gemfile \ No newline at end of file diff --git a/test/integration/datadog_mysql/serverspec/mysql_spec.rb b/test/integration/datadog_mysql/serverspec/mysql_spec.rb new file mode 100644 index 00000000..1d8b33d2 --- /dev/null +++ b/test/integration/datadog_mysql/serverspec/mysql_spec.rb @@ -0,0 +1,54 @@ +# Encoding: utf-8 +require 'json_spec' +require 'serverspec' +require 'yaml' + +set :backend, :exec +set :path, '/sbin:/usr/local/sbin:$PATH' + +AGENT_CONFIG = '/etc/dd-agent/conf.d/mysql.yaml' + +describe service('datadog-agent') do + it { should be_running } +end + +describe file(AGENT_CONFIG) do + it { should be_a_file } + + it 'is valid yaml matching input values' do + generated = YAML.load_file(AGENT_CONFIG) + + expected = { + 'instances' => [ + { + 'server' => '1.1.1.1', + 'port' => 3307, + 'user' => 'my_username', + 'pass' => 'my_password', + 'sock' => '/path/to/mysql.sock', + 'tags' => ['prod', 'my_app'], + 'options' => { + 'replication' => 0 + }, + 'queries' => [ + { + 'type' => 'gauge', + 'field' => 'users_count', + 'metric' => 'my_app.my_users.count', + 'query' => 'SELECT COUNT(1) AS users_count FROM users' + }, + { + 'type' => 'gauge', + 'field' => 'max_query_time', + 'metric' => 'mysql.performance.max_query_time', + 'query' => "SELECT IFNULL(MAX(TIME), 0) AS max_query_time FROM INFORMATION_SCHEMA.PROCESSLIST WHERE COMMAND != 'Sleep'" + } + ] + } + ], + 'init_config' => nil + } + + expect(generated.to_json).to be_json_eql expected.to_json + end +end