From 853d60ddfc64c28bc653fb5ad347d7b20bf2c4eb Mon Sep 17 00:00:00 2001 From: Patrick Debois Date: Mon, 24 Sep 2012 12:29:16 +0200 Subject: [PATCH 1/6] make apache webserver port reconfigurable : http_port --- README.md | 1 + attributes/default.rb | 1 + templates/default/collectd_web.conf.erb | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6c3aa79..83c9e86 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ The [collectd_plugins](#) cookbook is not required, but provides many common plu * collectd.collectd_web.path - Location to install collectd_web to. Defaults to /srv/collectd_web. * collectd.collectd_web.hostname - Server name to use for collectd_web Apache site. +* collectd.collectd_web.http_port - Port the virtualhost Apache listens on # USAGE # diff --git a/attributes/default.rb b/attributes/default.rb index 230ff77..5dfae8c 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -25,3 +25,4 @@ default[:collectd][:collectd_web][:path] = "/srv/collectd_web" default[:collectd][:collectd_web][:hostname] = "collectd" +default[:collectd][:collectd_web][:http_port] = 80 diff --git a/templates/default/collectd_web.conf.erb b/templates/default/collectd_web.conf.erb index a0757fc..d96ee7f 100644 --- a/templates/default/collectd_web.conf.erb +++ b/templates/default/collectd_web.conf.erb @@ -1,4 +1,4 @@ - +> ServerName <%= @node[:collectd][:collectd_web][:hostname] %> DocumentRoot <%= @node[:collectd][:collectd_web][:path] %> From 4eb3470f1a38550acde3d56010eb598d19fcf846 Mon Sep 17 00:00:00 2001 From: Patrick Debois Date: Mon, 24 Sep 2012 12:33:57 +0200 Subject: [PATCH 2/6] example Case Sensitive options --- README.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 83c9e86..05ef914 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,18 @@ collectd_python_plugin "redis" do end ``` +Some plugins require you to maintain the Case Sensitivity . This cookbook follows the ruby convention to do this. Note (carbon_writer does not get install, it's just an example) + +```ruby +collectd_python_plugin "carbon_writer" do + options :line_receiver_host => "127.0.0.1", + :line_receiver_port => 2003, + :differentiate_counters_over_time => true, + :lowercase_metric_names => true, + :types_db => "/usr/share/collectd/types.db" +end +``` + Options 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 or other mechanism to handle distribution. Example: @@ -71,7 +83,7 @@ end ## Web frontend ## -The `collectd::collectd_web` recipe will automatically deploy the [collectd_web](https://github.com/httpdss/collectd-web) frontend using Apache. The +The `collectd::collectd_web` recipe will automatically deploy the [collectd_web](https://github.com/httpdss/collectd-web) frontend using Apache. The [apache2](https://github.com/opscode/cookbooks/tree/master/apache2) cookbook is required for this and is *not* included automatically as this is an optional component, so be sure to configure the node with the correct recipes. From 471ca8153069b7579d5a0a08f1fc96287ea19b6e Mon Sep 17 00:00:00 2001 From: Patrick Debois Date: Mon, 24 Sep 2012 12:41:21 +0200 Subject: [PATCH 3/6] read libdir and datadir from attributes for template collection.conf.erb --- templates/default/collection.conf.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/default/collection.conf.erb b/templates/default/collection.conf.erb index a114511..dcad4e2 100644 --- a/templates/default/collection.conf.erb +++ b/templates/default/collection.conf.erb @@ -1,2 +1,2 @@ -datadir: "/var/lib/collectd/rrd/" -libdir: "/usr/lib/collectd/" +datadir: "<%= node[:collectd][:base_dir] %>" +libdir: "<%= node[:collectd][:plugin_dir] %>" From 9c5d3a3dc344dda14d559900eacba77d0d1d02e2 Mon Sep 17 00:00:00 2001 From: Patrick Debois Date: Mon, 24 Sep 2012 12:42:12 +0200 Subject: [PATCH 4/6] collectd_web requires rrdtool plugin to be configured and point to the correct rrd directory --- README.md | 1 + attributes/default.rb | 4 ++++ recipes/collectd_web.rb | 6 ++++++ 3 files changed, 11 insertions(+) diff --git a/README.md b/README.md index 05ef914..46c64e8 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ The [collectd_plugins](#) cookbook is not required, but provides many common plu * collectd.collectd_web.path - Location to install collectd_web to. Defaults to /srv/collectd_web. * collectd.collectd_web.hostname - Server name to use for collectd_web Apache site. * collectd.collectd_web.http_port - Port the virtualhost Apache listens on +* collectd.enable_rrdtool_plugin - Should this recipe enable a default rrdtool plugin? Defaults to true # USAGE # diff --git a/attributes/default.rb b/attributes/default.rb index 5dfae8c..99626ee 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -23,6 +23,10 @@ default[:collectd][:interval] = 10 default[:collectd][:read_threads] = 5 +# To make the collectd web out of the box we need to +# activate the rrdtool plugin on the server +default[:collectd][:enable_rrdtool_plugin] = true + default[:collectd][:collectd_web][:path] = "/srv/collectd_web" default[:collectd][:collectd_web][:hostname] = "collectd" default[:collectd][:collectd_web][:http_port] = 80 diff --git a/recipes/collectd_web.rb b/recipes/collectd_web.rb index f0fd1a0..b0973f2 100644 --- a/recipes/collectd_web.rb +++ b/recipes/collectd_web.rb @@ -51,3 +51,9 @@ end apache_site "collectd_web.conf" + +if node[:collectd][:enable_rrdtool_plugin] + collectd_plugin "rrdtool" do + options :DataDir => node[:collectd][:base_dir], :CacheFlush => 120 + end +end From bc69cf6acfa008a3768e541177047426a3d95f1f Mon Sep 17 00:00:00 2001 From: Patrick Debois Date: Mon, 24 Sep 2012 13:04:46 +0200 Subject: [PATCH 5/6] make it clear we don't install any plugins --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 46c64e8..ef8c798 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,8 @@ The client recipe will use the search index to automatically locate the server h ## Defines ## +This recipe does not install any plugins, if you want you had to include this recipe from your own recipe and add them there. + Several defines are provided to simplfy configuring plugins ### collectd_plugin ### From a6c81b5484f473862759085d0c6cee20234cd23f Mon Sep 17 00:00:00 2001 From: Patrick Debois Date: Mon, 24 Sep 2012 13:15:31 +0200 Subject: [PATCH 6/6] enable collectd_server to be specified via role or direct ip (chef-solo) --- README.md | 2 ++ attributes/default.rb | 2 ++ recipes/client.rb | 17 +++++++++++++++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ef8c798..d289be9 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,8 @@ The [collectd_plugins](#) cookbook is not required, but provides many common plu * collectd.plugin_dir - Base folder to find plugins. * collectd.types_db - Array of files to read graph type information from. * collectd.interval - Time period in seconds to wait between data reads. +* collectd.server_role - Name of the Chef Role to look for to identity a server. Defaults to collectd_server +* collectd.server_ip - IP address of collectd server to use * collectd.collectd_web.path - Location to install collectd_web to. Defaults to /srv/collectd_web. * collectd.collectd_web.hostname - Server name to use for collectd_web Apache site. diff --git a/attributes/default.rb b/attributes/default.rb index 99626ee..f0cc826 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -22,6 +22,8 @@ default[:collectd][:types_db] = ["/usr/share/collectd/types.db"] default[:collectd][:interval] = 10 default[:collectd][:read_threads] = 5 +default[:collectd][:server_role] = "collectd_server" +default[:collectd][:server_ip] = "127.0.0.1" # To make the collectd web out of the box we need to # activate the rrdtool plugin on the server diff --git a/recipes/client.rb b/recipes/client.rb index 5c1be7d..183f96e 100644 --- a/recipes/client.rb +++ b/recipes/client.rb @@ -20,8 +20,21 @@ include_recipe "collectd" servers = [] -search(:node, 'recipes:"collectd::server"') do |n| - servers << n['fqdn'] + +# First look for a server role +if Chef::Config[:solo] + servers << node['collectd']['server_ip'] +else + search(:node, "role:'#{node[:collectd][:server_role]}'") do |n| + servers << n['fqdn'] + end + + # Then check for servers that have the collectd::server recipe + if servers.empty? + search(:node, 'recipes:"collectd::server"') do |n| + servers << n['fqdn'] + end + end end if servers.empty?