From 21a19dd0fa9af49e3ff0002ad5dcfd70ed736a18 Mon Sep 17 00:00:00 2001 From: Chris Fordham Date: Mon, 27 Aug 2012 14:17:13 +1000 Subject: [PATCH 01/15] Add in default attributes fqdn_lookup, hostname, servers. --- attributes/default.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/attributes/default.rb b/attributes/default.rb index 230ff77..2b64cc2 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -22,6 +22,9 @@ default[:collectd][:types_db] = ["/usr/share/collectd/types.db"] default[:collectd][:interval] = 10 default[:collectd][:read_threads] = 5 +default[:collectd][:fqdn_lookup] = "true" +default[:collectd][:hostname] = node[:fqdn] +default[:collectd][:servers] = [] default[:collectd][:collectd_web][:path] = "/srv/collectd_web" -default[:collectd][:collectd_web][:hostname] = "collectd" +default[:collectd][:collectd_web][:hostname] = "collectd" \ No newline at end of file From f51fcc2c56f0b0a7dce24a60db403a14ee00315f Mon Sep 17 00:00:00 2001 From: Chris Fordham Date: Mon, 27 Aug 2012 14:18:09 +1000 Subject: [PATCH 02/15] Remove metadata.json ignore. --- .gitignore | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 5598138..a7cbee1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ -metadata.json - +/*.DS_Store From 133b8c9e8e4bf32784a67e2855604c759292ea08 Mon Sep 17 00:00:00 2001 From: Chris Fordham Date: Mon, 27 Aug 2012 14:18:57 +1000 Subject: [PATCH 03/15] Add support for chef-solo via logic. --- recipes/client.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/recipes/client.rb b/recipes/client.rb index 5c1be7d..28d296f 100644 --- a/recipes/client.rb +++ b/recipes/client.rb @@ -19,9 +19,13 @@ include_recipe "collectd" -servers = [] -search(:node, 'recipes:"collectd::server"') do |n| - servers << n['fqdn'] +if node['collectd']['servers'] or Chef::Config[:solo] + servers = node['collectd']['servers'] +else + servers = [] + search(:node, 'recipes:"collectd::server"') do |n| + servers << n['fqdn'] + end end if servers.empty? @@ -30,4 +34,4 @@ collectd_plugin "network" do options :server=>servers -end +end \ No newline at end of file From 05088e8eaed5dacb73b3ee190bac1187207b17ac Mon Sep 17 00:00:00 2001 From: Chris Fordham Date: Mon, 27 Aug 2012 14:19:44 +1000 Subject: [PATCH 04/15] Allow Hostname and FQDNLookup directives to be specified by node attribute. --- templates/default/collectd.conf.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/default/collectd.conf.erb b/templates/default/collectd.conf.erb index b1e3964..68e5d2d 100644 --- a/templates/default/collectd.conf.erb +++ b/templates/default/collectd.conf.erb @@ -6,8 +6,8 @@ # You should also read /usr/share/doc/collectd/README.Debian.plugins before # enabling any more plugins. -Hostname "<%= @node[:fqdn] %>" -FQDNLookup true +Hostname "<%= @node[:collectd][:hostname] %>" +FQDNLookup <%= @node[:collectd][:fqdn_lookup] %> BaseDir "<%= @node[:collectd][:base_dir] %>" PluginDir "<%= @node[:collectd][:plugin_dir] %>" TypesDB "<%= @node[:collectd][:types_db].join('", "') %>" From c245e6ffe166d77065dfe01a3885e156b32521cc Mon Sep 17 00:00:00 2001 From: Chris Fordham Date: Mon, 27 Aug 2012 14:20:04 +1000 Subject: [PATCH 05/15] Add metadata for recipes and attributes. --- metadata.rb | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/metadata.rb b/metadata.rb index 05ec153..b0d306c 100644 --- a/metadata.rb +++ b/metadata.rb @@ -5,3 +5,86 @@ long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) version "1.0.0" supports "ubuntu" + +depends "apache2" + +%w{ debian ubuntu centos redhat fedora }.each do |os| + supports os +end + +recipe "collectd", "Install a standalone daemon." +recipe "collectd::client", "Install collectd and configure it to send data to a server." +recipe "collectd::server", "Install collectd and configure it to recieve data from clients." +recipe "collectd::collectd_web", "Installs and configures collectd_web." + +attribute "collectd/base_dir", + :display_name => "collectd Base Directory", + :description => "The base directory for collectd.", + :required => "optional", + :default => "/var/lib/collectd", + :recipes => [ "collectd::default" ] + +attribute "collectd/plugin_dir", + :display_name => "collectd Plugin Directory", + :description => "The plugin directory for collectd.", + :required => "optional", + :default => "/usr/lib/collectd" , + :recipes => [ "collectd::default" ] + +attribute "collectd/types_db", + :display_name => "collectd Types Database", + :description => "The location of the collectd types.db file.", + :required => "optional", + :type => "array", + :default => [ "/usr/share/collectd/types.db" ], + :recipes => [ "collectd::default" ] + +attribute "collectd/interval", + :display_name => "collectd Polling Interval", + :description => "The collectd interval setting value.", + :required => "optional", + :default => "20", + :recipes => [ "collectd::default" ] + +attribute "collectd/read_threads", + :display_name => "collectd Read Threads", + :description => "The collectd read threads setting value.", + :required => "optional", + :default => "5", + :recipes => [ "collectd::default" ] + +#attribute "collectd/servers", +# :display_name => "collectd Servers", +# :description => "The collectd servers to send to as a client.", +# :required => "optional", +# :default => nil, +# :type => "array", +# :recipes => [ "collectd::client" ] + +attribute "collectd/hostname", + :display_name => "collectd Hostname", + :description => "The collectd Hostname setting value.", + :required => "optional", + :recipes => [ "collectd::default" ] + +attribute "collectd/fqdn_lookup", + :display_name => "collectd FQDNLookup", + :description => "The collectd FQDNLookup setting value.", + :required => "optional", + :recipes => [ "collectd::default" ], + :choice => [ "true", "false" ], + :default => "true" + +attribute "collectd/collectd_web/path", + :display_name => "collectd_web path", + :description => "The collectd_web install path.", + :required => "optional", + :default => "/srv/collectd_web", + :recipes => [ "collectd::collectd_web" ] + +attribute "collectd/collectd_web/hostname", + :display_name => "collectd_web hostname", + :description => "The collectd_web hostname.", + :required => "optional", + :default => "collectd", + :recipes => [ "collectd::collectd_web" ] \ No newline at end of file From c3365623f7cb2beaddc9de296a62c42680260298 Mon Sep 17 00:00:00 2001 From: Chris Fordham Date: Mon, 27 Aug 2012 14:20:20 +1000 Subject: [PATCH 06/15] Add metadata.json for RightScale support (required). --- metadata.json | 167 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 metadata.json diff --git a/metadata.json b/metadata.json new file mode 100644 index 0000000..7b05f3f --- /dev/null +++ b/metadata.json @@ -0,0 +1,167 @@ +{ + "conflicting": { + }, + "recommendations": { + }, + "platforms": { + "fedora": ">= 0.0.0", + "redhat": ">= 0.0.0", + "ubuntu": ">= 0.0.0", + "centos": ">= 0.0.0", + "debian": ">= 0.0.0" + }, + "maintainer_email": "noah@coderanger.net", + "maintainer": "Noan Kantrowitz", + "attributes": { + "collectd/types_db": { + "default": [ + "/usr/share/collectd/types.db" + ], + "required": "optional", + "description": "The location of the collectd types.db file.", + "calculated": false, + "display_name": "collectd Types Database", + "type": "array", + "recipes": [ + "collectd::default" + ], + "choice": [ + + ] + }, + "collectd/collectd_web/path": { + "default": "/srv/collectd_web", + "required": "optional", + "description": "The collectd_web install path.", + "calculated": false, + "display_name": "collectd_web path", + "type": "string", + "recipes": [ + "collectd::collectd_web" + ], + "choice": [ + + ] + }, + "collectd/fqdn_lookup": { + "default": "true", + "required": "optional", + "description": "The collectd FQDNLookup setting value.", + "calculated": false, + "display_name": "collectd FQDNLookup", + "type": "string", + "recipes": [ + "collectd::default" + ], + "choice": [ + "true", + "false" + ] + }, + "collectd/plugin_dir": { + "default": "/usr/lib/collectd", + "required": "optional", + "description": "The plugin directory for collectd.", + "calculated": false, + "display_name": "collectd Plugin Directory", + "type": "string", + "recipes": [ + "collectd::default" + ], + "choice": [ + + ] + }, + "collectd/base_dir": { + "default": "/var/lib/collectd", + "required": "optional", + "description": "The base directory for collectd.", + "calculated": false, + "display_name": "collectd Base Directory", + "type": "string", + "recipes": [ + "collectd::default" + ], + "choice": [ + + ] + }, + "collectd/interval": { + "default": "20", + "required": "optional", + "description": "The collectd interval setting value.", + "calculated": false, + "display_name": "collectd Polling Interval", + "type": "string", + "recipes": [ + "collectd::default" + ], + "choice": [ + + ] + }, + "collectd/hostname": { + "required": "optional", + "description": "The collectd Hostname setting value.", + "calculated": false, + "display_name": "collectd Hostname", + "type": "string", + "recipes": [ + "collectd::default" + ], + "choice": [ + + ] + }, + "collectd/collectd_web/hostname": { + "default": "collectd", + "required": "optional", + "description": "The collectd_web hostname.", + "calculated": false, + "display_name": "collectd_web hostname", + "type": "string", + "recipes": [ + "collectd::collectd_web" + ], + "choice": [ + + ] + }, + "collectd/read_threads": { + "default": "5", + "required": "optional", + "description": "The collectd read threads setting value.", + "calculated": false, + "display_name": "collectd Read Threads", + "type": "string", + "recipes": [ + "collectd::default" + ], + "choice": [ + + ] + } + }, + "license": "Apache 2.0", + "suggestions": { + }, + "description": "Install and configure the collectd monitoring daemon", + "providing": { + }, + "groupings": { + }, + "name": "chef-collectd", + "version": "1.0.0", + "long_description": "# DESCRIPTION #\n\nConfigure and install the [collectd](http://collectd.org/) monitoring daemon.\n\n# REQUIREMENTS #\n\nThis cookbook has only been tested on Ubuntu 10.04.\n\nTo use the `collectd::collectd_web` recipe you need the [apache2](https://github.com/opscode/cookbooks/tree/master/apache2) cookbook.\n\nThe [collectd_plugins](#) cookbook is not required, but provides many common plugin definitions for easy reuse.\n\n# ATTRIBUTES #\n\n* collectd.basedir - Base folder for collectd output data.\n* collectd.plugin_dir - Base folder to find plugins.\n* collectd.types_db - Array of files to read graph type information from.\n* collectd.interval - Time period in seconds to wait between data reads.\n\n* collectd.collectd_web.path - Location to install collectd_web to. Defaults to /srv/collectd_web.\n* collectd.collectd_web.hostname - Server name to use for collectd_web Apache site.\n\n# USAGE #\n\nThree main recipes are provided:\n\n* collectd - Install a standalone daemon.\n* collectd::client - Install collectd and configure it to send data to a server.\n* collectd::server - Install collectd and configure it to recieve data from clients.\n\nThe client recipe will use the search index to automatically locate the server hosts, so no manual configuration is required.\n\n## Defines ##\n\nSeveral defines are provided to simplfy configuring plugins\n\n### collectd_plugin ###\n\nThe `collectd_plugin` define configures and enables standard collect plugins. Example:\n\n```ruby\ncollectd_plugin \"interface\" do\n options :interface=>\"lo\", :ignore_selected=>true\nend\n```\n\nThe options hash is converted to collectd-style settings automatically. Any symbol key will be converted to camel-case. In the above example :ignore_selected will be output as the\nkey \"IgnoreSelected\". If the key is already a string, this conversion is skipped. If the value is an array, it will be output as a separate line for each element.\n\n### collectd_python_plugin ###\n\nThe `collectd_python_plugin` define configures and enables Python plugins using the collectd-python plugin. Example:\n\n```ruby\ncollectd_python_plugin \"redis\" do\n options :host=>servers, :verbose=>true\nend\n```\n\nOptions are interpreted in the same way as with `collectd_plugin`. This define will not deploy the plugin script as well, so be sure to setup a cookbook_file resource\nor other mechanism to handle distribution. Example:\n\n```ruby\ncookbook_file File.join(node[:collectd][:plugin_dir], \"redis.py\") do\n owner \"root\"\n group \"root\"\n mode \"644\"\nend\n```\n\n## Web frontend ##\n\nThe `collectd::collectd_web` recipe will automatically deploy the [collectd_web](https://github.com/httpdss/collectd-web) frontend using Apache. The \n[apache2](https://github.com/opscode/cookbooks/tree/master/apache2) cookbook is required for this and is *not* included automatically as this is an optional\ncomponent, so be sure to configure the node with the correct recipes.\n\n# LICENSE & AUTHOR #\n\nAuthor:: Noah Kantrowitz ()\nCopyright:: 2010, Atari, Inc\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n", + "dependencies": { + "apache2": ">= 0.0.0" + }, + "recipes": { + "collectd::collectd_web": "Installs and configures collectd_web.", + "collectd::client": "Install collectd and configure it to send data to a server.", + "collectd::server": "Install collectd and configure it to recieve data from clients.", + "collectd": "Install a standalone daemon." + }, + "replacing": { + } +} \ No newline at end of file From e227ec4095e83a1f4dfe58d92a5abff34b0a8267 Mon Sep 17 00:00:00 2001 From: Chris Fordham Date: Mon, 3 Sep 2012 11:05:35 +1000 Subject: [PATCH 07/15] Revert "Remove metadata.json ignore." This reverts commit f51fcc2c56f0b0a7dce24a60db403a14ee00315f. --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index a7cbee1..5598138 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -/*.DS_Store +metadata.json + From 5d951bbe4e046c0cc4b175e9785ffa784794e130 Mon Sep 17 00:00:00 2001 From: Chris Fordham Date: Mon, 3 Sep 2012 11:19:08 +1000 Subject: [PATCH 08/15] Remove metadata.json. --- metadata.json | 167 -------------------------------------------------- 1 file changed, 167 deletions(-) delete mode 100644 metadata.json diff --git a/metadata.json b/metadata.json deleted file mode 100644 index 7b05f3f..0000000 --- a/metadata.json +++ /dev/null @@ -1,167 +0,0 @@ -{ - "conflicting": { - }, - "recommendations": { - }, - "platforms": { - "fedora": ">= 0.0.0", - "redhat": ">= 0.0.0", - "ubuntu": ">= 0.0.0", - "centos": ">= 0.0.0", - "debian": ">= 0.0.0" - }, - "maintainer_email": "noah@coderanger.net", - "maintainer": "Noan Kantrowitz", - "attributes": { - "collectd/types_db": { - "default": [ - "/usr/share/collectd/types.db" - ], - "required": "optional", - "description": "The location of the collectd types.db file.", - "calculated": false, - "display_name": "collectd Types Database", - "type": "array", - "recipes": [ - "collectd::default" - ], - "choice": [ - - ] - }, - "collectd/collectd_web/path": { - "default": "/srv/collectd_web", - "required": "optional", - "description": "The collectd_web install path.", - "calculated": false, - "display_name": "collectd_web path", - "type": "string", - "recipes": [ - "collectd::collectd_web" - ], - "choice": [ - - ] - }, - "collectd/fqdn_lookup": { - "default": "true", - "required": "optional", - "description": "The collectd FQDNLookup setting value.", - "calculated": false, - "display_name": "collectd FQDNLookup", - "type": "string", - "recipes": [ - "collectd::default" - ], - "choice": [ - "true", - "false" - ] - }, - "collectd/plugin_dir": { - "default": "/usr/lib/collectd", - "required": "optional", - "description": "The plugin directory for collectd.", - "calculated": false, - "display_name": "collectd Plugin Directory", - "type": "string", - "recipes": [ - "collectd::default" - ], - "choice": [ - - ] - }, - "collectd/base_dir": { - "default": "/var/lib/collectd", - "required": "optional", - "description": "The base directory for collectd.", - "calculated": false, - "display_name": "collectd Base Directory", - "type": "string", - "recipes": [ - "collectd::default" - ], - "choice": [ - - ] - }, - "collectd/interval": { - "default": "20", - "required": "optional", - "description": "The collectd interval setting value.", - "calculated": false, - "display_name": "collectd Polling Interval", - "type": "string", - "recipes": [ - "collectd::default" - ], - "choice": [ - - ] - }, - "collectd/hostname": { - "required": "optional", - "description": "The collectd Hostname setting value.", - "calculated": false, - "display_name": "collectd Hostname", - "type": "string", - "recipes": [ - "collectd::default" - ], - "choice": [ - - ] - }, - "collectd/collectd_web/hostname": { - "default": "collectd", - "required": "optional", - "description": "The collectd_web hostname.", - "calculated": false, - "display_name": "collectd_web hostname", - "type": "string", - "recipes": [ - "collectd::collectd_web" - ], - "choice": [ - - ] - }, - "collectd/read_threads": { - "default": "5", - "required": "optional", - "description": "The collectd read threads setting value.", - "calculated": false, - "display_name": "collectd Read Threads", - "type": "string", - "recipes": [ - "collectd::default" - ], - "choice": [ - - ] - } - }, - "license": "Apache 2.0", - "suggestions": { - }, - "description": "Install and configure the collectd monitoring daemon", - "providing": { - }, - "groupings": { - }, - "name": "chef-collectd", - "version": "1.0.0", - "long_description": "# DESCRIPTION #\n\nConfigure and install the [collectd](http://collectd.org/) monitoring daemon.\n\n# REQUIREMENTS #\n\nThis cookbook has only been tested on Ubuntu 10.04.\n\nTo use the `collectd::collectd_web` recipe you need the [apache2](https://github.com/opscode/cookbooks/tree/master/apache2) cookbook.\n\nThe [collectd_plugins](#) cookbook is not required, but provides many common plugin definitions for easy reuse.\n\n# ATTRIBUTES #\n\n* collectd.basedir - Base folder for collectd output data.\n* collectd.plugin_dir - Base folder to find plugins.\n* collectd.types_db - Array of files to read graph type information from.\n* collectd.interval - Time period in seconds to wait between data reads.\n\n* collectd.collectd_web.path - Location to install collectd_web to. Defaults to /srv/collectd_web.\n* collectd.collectd_web.hostname - Server name to use for collectd_web Apache site.\n\n# USAGE #\n\nThree main recipes are provided:\n\n* collectd - Install a standalone daemon.\n* collectd::client - Install collectd and configure it to send data to a server.\n* collectd::server - Install collectd and configure it to recieve data from clients.\n\nThe client recipe will use the search index to automatically locate the server hosts, so no manual configuration is required.\n\n## Defines ##\n\nSeveral defines are provided to simplfy configuring plugins\n\n### collectd_plugin ###\n\nThe `collectd_plugin` define configures and enables standard collect plugins. Example:\n\n```ruby\ncollectd_plugin \"interface\" do\n options :interface=>\"lo\", :ignore_selected=>true\nend\n```\n\nThe options hash is converted to collectd-style settings automatically. Any symbol key will be converted to camel-case. In the above example :ignore_selected will be output as the\nkey \"IgnoreSelected\". If the key is already a string, this conversion is skipped. If the value is an array, it will be output as a separate line for each element.\n\n### collectd_python_plugin ###\n\nThe `collectd_python_plugin` define configures and enables Python plugins using the collectd-python plugin. Example:\n\n```ruby\ncollectd_python_plugin \"redis\" do\n options :host=>servers, :verbose=>true\nend\n```\n\nOptions are interpreted in the same way as with `collectd_plugin`. This define will not deploy the plugin script as well, so be sure to setup a cookbook_file resource\nor other mechanism to handle distribution. Example:\n\n```ruby\ncookbook_file File.join(node[:collectd][:plugin_dir], \"redis.py\") do\n owner \"root\"\n group \"root\"\n mode \"644\"\nend\n```\n\n## Web frontend ##\n\nThe `collectd::collectd_web` recipe will automatically deploy the [collectd_web](https://github.com/httpdss/collectd-web) frontend using Apache. The \n[apache2](https://github.com/opscode/cookbooks/tree/master/apache2) cookbook is required for this and is *not* included automatically as this is an optional\ncomponent, so be sure to configure the node with the correct recipes.\n\n# LICENSE & AUTHOR #\n\nAuthor:: Noah Kantrowitz ()\nCopyright:: 2010, Atari, Inc\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n", - "dependencies": { - "apache2": ">= 0.0.0" - }, - "recipes": { - "collectd::collectd_web": "Installs and configures collectd_web.", - "collectd::client": "Install collectd and configure it to send data to a server.", - "collectd::server": "Install collectd and configure it to recieve data from clients.", - "collectd": "Install a standalone daemon." - }, - "replacing": { - } -} \ No newline at end of file From 31ab29ebd4134813fd8e485c03498e6a203e46d1 Mon Sep 17 00:00:00 2001 From: Chris Fordham Date: Fri, 22 Mar 2013 09:36:29 +1100 Subject: [PATCH 09/15] Add support for more platforms with the collectd package name. --- recipes/default.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/recipes/default.rb b/recipes/default.rb index cf5277e..877b35b 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -17,9 +17,16 @@ # limitations under the License. # -package "collectd" do - package_name "collectd-core" -end +package = value_for_platform( + ["centos", "redhat", "suse", "fedora" ] => { + "default" => "collectd" + }, + ["ubuntu", "debian"] => { + "default" => "collectd-core" + }, + "default" => "collectd" +) +package package service "collectd" do supports :restart => true, :status => true From b0784d959e254b0b52715eb94909297b661a31ab Mon Sep 17 00:00:00 2001 From: Chris Fordham Date: Fri, 22 Mar 2013 11:05:48 +1100 Subject: [PATCH 10/15] Add in attribute support for more platforms (mainly redhat-like ones). --- attributes/default.rb | 17 ++++++++++++++++- recipes/default.rb | 8 +------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/attributes/default.rb b/attributes/default.rb index 2b64cc2..c3a01c2 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -18,7 +18,22 @@ # default[:collectd][:base_dir] = "/var/lib/collectd" -default[:collectd][:plugin_dir] = "/usr/lib/collectd" + +case node['platform'] +when "debian","ubuntu" + default[:collectd][:plugin_dir] = "/usr/lib/collectd" + default[:collectd][:config_dir] = "/etc/collectd" + default[:collectd][:config_file] = "/etc/collectd/collectd.conf" +when "redhat","centos","scientific","fedora","suse" + default[:collectd][:plugin_dir] = "/usr/lib64/collectd" + default[:collectd][:config_dir] = "/etc/collectd.d" + default[:collectd][:config_file] = "/etc/collectd.conf" +else + default[:collectd][:plugin_dir] = "/usr/lib/collectd" + default[:collectd][:config_dir] = "/etc/collectd.d" + default[:collectd][:config_file] = "/etc/collectd.conf" +end + default[:collectd][:types_db] = ["/usr/share/collectd/types.db"] default[:collectd][:interval] = 10 default[:collectd][:read_threads] = 5 diff --git a/recipes/default.rb b/recipes/default.rb index 877b35b..e75c29f 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -32,13 +32,7 @@ supports :restart => true, :status => true end -directory "/etc/collectd" do - owner "root" - group "root" - mode "755" -end - -directory "/etc/collectd/plugins" do +directory node[:collectd][:config_dir] do owner "root" group "root" mode "755" From 7956367a5ad0553f6b1150f27c2d657d49c3618c Mon Sep 17 00:00:00 2001 From: Chris Fordham Date: Fri, 22 Mar 2013 17:46:47 +1100 Subject: [PATCH 11/15] Update to use node/collectd/config_dir for plugin configurations. --- definitions/collectd_plugin.rb | 4 ++-- recipes/default.rb | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/definitions/collectd_plugin.rb b/definitions/collectd_plugin.rb index f4a4e89..f1f8d9f 100644 --- a/definitions/collectd_plugin.rb +++ b/definitions/collectd_plugin.rb @@ -18,7 +18,7 @@ # define :collectd_plugin, :options => {}, :template => nil, :cookbook => nil do - template "/etc/collectd/plugins/#{params[:name]}.conf" do + template "#{node[:collectd][:config_dir]}/plugins/#{params[:name]}.conf" do owner "root" group "root" mode "644" @@ -36,7 +36,7 @@ define :collectd_python_plugin, :options => {}, :module => nil, :path => nil do begin - t = resources(:template => "/etc/collectd/plugins/python.conf") + t = resources(:template => "#{node[:collectd][:config_dir]}/plugins/python.conf") rescue ArgumentError collectd_plugin "python" do options :paths=>[node[:collectd][:plugin_dir]], :modules=>{} diff --git a/recipes/default.rb b/recipes/default.rb index e75c29f..f880cc7 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -38,6 +38,12 @@ mode "755" end +directory "#{node[:collectd][:config_dir]}/plugins" do + owner "root" + group "root" + mode "755" +end + directory node[:collectd][:base_dir] do owner "root" group "root" @@ -53,7 +59,7 @@ end %w(collectd collection thresholds).each do |file| - template "/etc/collectd/#{file}.conf" do + template "#{node[:collectd][:config_dir]}/#{file}.conf" do source "#{file}.conf.erb" owner "root" group "root" @@ -64,7 +70,7 @@ ruby_block "delete_old_plugins" do block do - Dir['/etc/collectd/plugins/*.conf'].each do |path| + Dir["#{node[:collectd][:config_dir]}/plugins/*.conf"].each do |path| autogen = false File.open(path).each_line do |line| if line.start_with?('#') and line.include?('autogenerated') From 4af9da1cf24b0ebd934f4cb27f6cb61ce8830e40 Mon Sep 17 00:00:00 2001 From: Chris Fordham Date: Mon, 21 Oct 2013 18:00:44 +1100 Subject: [PATCH 12/15] Use boolean not string for default attribute value of collectd/fqdn_lookup. --- attributes/default.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/attributes/default.rb b/attributes/default.rb index c3a01c2..395c7e2 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -37,7 +37,7 @@ default[:collectd][:types_db] = ["/usr/share/collectd/types.db"] default[:collectd][:interval] = 10 default[:collectd][:read_threads] = 5 -default[:collectd][:fqdn_lookup] = "true" +default[:collectd][:fqdn_lookup] = true default[:collectd][:hostname] = node[:fqdn] default[:collectd][:servers] = [] From f38bd22956f2390ce7e3cdd573727b1d6308176e Mon Sep 17 00:00:00 2001 From: Chris Fordham Date: Mon, 21 Oct 2013 18:05:31 +1100 Subject: [PATCH 13/15] Raise an error per Chef (server||solo) intelligiently when no collectd servers are found or provided. --- recipes/client.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/recipes/client.rb b/recipes/client.rb index 28d296f..63f0722 100644 --- a/recipes/client.rb +++ b/recipes/client.rb @@ -19,6 +19,19 @@ include_recipe "collectd" +servers = + if !node[:collectd][:servers].empty? + node[:collectd][:servers] + elsif !Chef::Config[:solo] + search(:node, 'recipes:"collectd::server"').map {|n| n['fqdn'] } + end +if servers.empty? + if Chef::Config[:solo] + raise "No collectd servers found. Please configure at least one server in Chef Solo with collectd['servers']." + else + raise "No collectd servers found. Please configure at least one server node using collectd::server." +end + if node['collectd']['servers'] or Chef::Config[:solo] servers = node['collectd']['servers'] else From 053af26d83659a357889651d1bf0bcd6a476678a Mon Sep 17 00:00:00 2001 From: Chris Fordham Date: Mon, 21 Oct 2013 18:15:22 +1100 Subject: [PATCH 14/15] Add missing end and remove old code accidentally pasted before previous commit. --- recipes/client.rb | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/recipes/client.rb b/recipes/client.rb index 63f0722..72cc42d 100644 --- a/recipes/client.rb +++ b/recipes/client.rb @@ -29,22 +29,10 @@ if Chef::Config[:solo] raise "No collectd servers found. Please configure at least one server in Chef Solo with collectd['servers']." else - raise "No collectd servers found. Please configure at least one server node using collectd::server." -end - -if node['collectd']['servers'] or Chef::Config[:solo] - servers = node['collectd']['servers'] -else - servers = [] - search(:node, 'recipes:"collectd::server"') do |n| - servers << n['fqdn'] + raise "No collectd servers found. Please configure at least one server node using collectd::server." end end -if servers.empty? - raise "No servers found. Please configure at least one node with collectd::server." -end - collectd_plugin "network" do options :server=>servers end \ No newline at end of file From 675091f68cec114bee3bdd1f033a390234eaccdf Mon Sep 17 00:00:00 2001 From: Chris Fordham Date: Mon, 21 Oct 2013 18:27:36 +1100 Subject: [PATCH 15/15] Add name attribute to metadata and remove old/duplicate supports attribute. --- metadata.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/metadata.rb b/metadata.rb index b0d306c..05a691c 100644 --- a/metadata.rb +++ b/metadata.rb @@ -1,10 +1,10 @@ -maintainer "Noan Kantrowitz" -maintainer_email "noah@coderanger.net" -license "Apache 2.0" -description "Install and configure the collectd monitoring daemon" -long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version "1.0.0" -supports "ubuntu" +name "collectd" +maintainer "Noan Kantrowitz" +maintainer_email "noah@coderanger.net" +license "Apache 2.0" +description "Install and configure the collectd monitoring daemon" +long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) +version "1.0.0" depends "apache2"