Skip to content
This repository was archived by the owner on Dec 31, 2021. It is now read-only.

Commit 6b666ca

Browse files
committed
Initial commit of collectd cookbook.
0 parents  commit 6b666ca

File tree

15 files changed

+544
-0
lines changed

15 files changed

+544
-0
lines changed

README.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# DESCRIPTION #
2+
3+
Configure and install the [collectd](http://collectd.org/) monitoring daemon.
4+
5+
# REQUIREMENTS #
6+
7+
This cookbook has only been tested on Ubuntu 10.04.
8+
9+
To use the `collectd::collectd_web` recipe you need the [apache2](https://github.com/opscode/cookbooks/tree/master/apache2) cookbook.
10+
11+
The [collectd_plugins](#) cookbook is not required, but provides many common plugin definitions for easy reuse.
12+
13+
# ATTRIBUTES #
14+
15+
* collectd.basedir - Base folder for collectd output data.
16+
* collectd.plugin_dir - Base folder to find plugins.
17+
* collectd.types_db - Array of files to read graph type information from.
18+
* collectd.interval - Time period in seconds to wait between data reads.
19+
20+
* collectd.collectd_web.path - Location to install collectd_web to. Defaults to /srv/collectd_web.
21+
* collectd.collectd_web.hostname - Server name to use for collectd_web Apache site.
22+
23+
# USAGE #
24+
25+
Three main recipes are provided:
26+
27+
* collectd - Install a standalone daemon.
28+
* collectd::client - Install collectd and configure it to send data to a server.
29+
* collectd::server - Install collectd and configure it to recieve data from clients.
30+
31+
The client recipe will use the search index to automatically locate the server hosts, so no manual configuration is required.
32+
33+
## Defines ##
34+
35+
Several defines are provided to simplfy configuring plugins
36+
37+
### collectd_plugin ###
38+
39+
The `collectd_plugin` define configures and enables standard collect plugins. Example:
40+
41+
```ruby
42+
collectd_plugin "interface" do
43+
options :interface=>"lo", :ignore_selected=>true
44+
end
45+
```
46+
47+
The 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
48+
key "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.
49+
50+
### collectd_python_plugin ###
51+
52+
The `collectd_python_plugin` define configures and enables Python plugins using the collectd-python plugin. Example:
53+
54+
```ruby
55+
collectd_python_plugin "redis" do
56+
options :host=>servers, :verbose=>true
57+
end
58+
```
59+
60+
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
61+
or other mechanism to handle distribution. Example:
62+
63+
```ruby
64+
cookbook_file File.join(node[:collectd][:plugin_dir], "redis.py") do
65+
owner "root"
66+
group "root"
67+
mode "644"
68+
end
69+
```
70+
71+
## Web frontend ##
72+
73+
The `collectd::collectd_web` recipe will automatically deploy the [collectd_web](https://github.com/httpdss/collectd-web) frontend using Apache. The
74+
[apache2](https://github.com/opscode/cookbooks/tree/master/apache2) cookbook is required for this and is *not* included automatically as this is an optional
75+
component, so be sure to configure the node with the correct recipes.
76+
77+
# LICENSE & AUTHOR #
78+
79+
Author:: Noah Kantrowitz (<[email protected]>)
80+
Copyright:: 2010, Atari, Inc
81+
82+
Licensed under the Apache License, Version 2.0 (the "License");
83+
you may not use this file except in compliance with the License.
84+
You may obtain a copy of the License at
85+
86+
http://www.apache.org/licenses/LICENSE-2.0
87+
88+
Unless required by applicable law or agreed to in writing, software
89+
distributed under the License is distributed on an "AS IS" BASIS,
90+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
91+
See the License for the specific language governing permissions and
92+
limitations under the License.

attributes/default.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#
2+
# Cookbook Name:: collectd
3+
# Attributes:: default
4+
#
5+
# Copyright 2010, Atari, Inc
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
20+
default[:collectd][:base_dir] = "/var/lib/collectd"
21+
default[:collectd][:plugin_dir] = "/usr/lib/collectd"
22+
default[:collectd][:types_db] = ["/usr/share/collectd/types.db"]
23+
default[:collectd][:interval] = 10
24+
default[:collectd][:read_threads] = 5
25+
26+
default[:collectd][:collectd_web][:path] = "/srv/collectd_web"
27+
default[:collectd][:collectd_web][:hostname] = "collectd"

definitions/collectd_plugin.rb

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#
2+
# Cookbook Name:: collectd
3+
# Definition:: collectd_plugin
4+
#
5+
# Copyright 2010, Atari, Inc
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
20+
define :collectd_plugin, :options => {}, :template => nil, :cookbook => nil do
21+
template "/etc/collectd/plugins/#{params[:name]}.conf" do
22+
owner "root"
23+
group "root"
24+
mode "644"
25+
if params[:template].blank?
26+
source "plugin.conf.erb"
27+
cookbook params[:cookbook] || "collectd"
28+
else
29+
source params[:template]
30+
cookbook params[:cookbook]
31+
end
32+
variables :name=>params[:name], :options=>params[:options]
33+
notifies :restart, resources(:service => "collectd")
34+
end
35+
end
36+
37+
define :collectd_python_plugin, :options => {}, :module => nil, :path => nil do
38+
begin
39+
t = resources(:template => "/etc/collectd/plugins/python.conf")
40+
rescue ArgumentError
41+
collectd_plugin "python" do
42+
options :paths=>[node[:collectd][:plugin_dir]], :modules=>{}
43+
template "python_plugin.conf.erb"
44+
cookbook "collectd"
45+
end
46+
retry
47+
end
48+
if not params[:path].blank?
49+
t.variables[:options][:paths] << params[:path]
50+
end
51+
t.variables[:options][:modules][params[:module] || params[:name]] = params[:options]
52+
end

libraries/default.rb

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#
2+
# Cookbook Name:: collectd
3+
# Library:: default
4+
#
5+
# Copyright 2010, Atari, Inc
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
20+
def collectd_key(option)
21+
return option.to_s.split('_').map{|x| x.capitalize}.join() if option.instance_of?(Symbol)
22+
"#{option}"
23+
end
24+
25+
def collectd_option(option)
26+
return option if option.instance_of?(Fixnum) || option == true || option == false
27+
"\"#{option}\""
28+
end
29+
30+
def collectd_settings(options, level=0)
31+
indent = ' ' * level
32+
output = []
33+
options.each_pair do |key, value|
34+
if value.is_a? Array
35+
value.each do |subvalue|
36+
output << "#{indent}#{collectd_key(key)} #{collectd_option(subvalue)}"
37+
end
38+
elsif value.is_a? Hash
39+
value.each_pair do |name, suboptions|
40+
output << "#{indent}<#{key} \"#{name}\">\n#{collectd_settings(suboptions, level+1)}\n#{indent}</#{key}>"
41+
end
42+
else
43+
output << "#{indent}#{collectd_key(key)} #{collectd_option(value)}"
44+
end
45+
end
46+
output.join("\n")
47+
end

metadata.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
maintainer "Noan Kantrowitz"
2+
maintainer_email "[email protected]"
3+
license "Apache 2.0"
4+
description "Install and configure the collectd monitoring daemon"
5+
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
6+
version "1.0.0"
7+
supports "ubuntu"

recipes/client.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#
2+
# Cookbook Name:: collectd
3+
# Recipe:: client
4+
#
5+
# Copyright 2010, Atari, Inc
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
20+
include_recipe "collectd"
21+
22+
servers = []
23+
search(:node, 'recipes:"collectd::server"') do |n|
24+
servers << n['fqdn']
25+
end
26+
27+
if servers.empty?
28+
raise "No servers found. Please configure at least one node with collectd::server."
29+
end
30+
31+
collectd_plugin "network" do
32+
options :server=>servers
33+
end

recipes/collectd_web.rb

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#
2+
# Cookbook Name:: collectd
3+
# Recipe:: collectd_web
4+
#
5+
# Copyright 2010, Atari, Inc
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
20+
include_recipe "collectd"
21+
include_recipe "apache2"
22+
23+
directory node[:collectd][:collectd_web][:path] do
24+
owner "root"
25+
group "root"
26+
mode "755"
27+
end
28+
29+
bash "install_collectd_web" do
30+
user "root"
31+
cwd node[:collectd][:collectd_web][:path]
32+
not_if do
33+
File.exists?(File.join(node[:collectd][:collectd_web][:path], "index.html"))
34+
end
35+
code <<-EOH
36+
wget --no-check-certificate -O collectd-web.tar.gz https://github.com/httpdss/collectd-web/tarball/master
37+
tar --strip-components=1 -xzf collectd-web.tar.gz
38+
rm collectd-web.tar.gz
39+
EOH
40+
end
41+
42+
template "/etc/apache2/sites-available/collectd_web.conf" do
43+
source "collectd_web.conf.erb"
44+
owner "root"
45+
group "root"
46+
mode "644"
47+
end
48+
49+
apache_site "collectd_web.conf"

0 commit comments

Comments
 (0)