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

Add Mac OS X support #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
metadata.json

*~
*#
.#*
\#*#
.*.sw[a-z]
*.un~
pkg/

# Berkshelf
.vagrant
/cookbooks
Berksfile.lock

# Bundler
Gemfile.lock
bin/*
.bundle/*

.kitchen/
.kitchen.local.yml
21 changes: 21 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
driver:
name: vagrant

provisioner:
name: chef_zero

platforms:
- name: ubuntu-10.04
- name: ubuntu-12.04

suites:
- name: default
run_list:
- "recipe[apt]"
- "recipe[collectd]"
attributes:
- name: server
run_list:
- "recipe[apt]"
- "recipe[collectd::server]"
3 changes: 3 additions & 0 deletions Berksfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source "https://api.berkshelf.com"

metadata
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ Configure and install the [collectd](http://collectd.org/) monitoring daemon.

# REQUIREMENTS #

This cookbook has only been tested on Ubuntu 10.04.
This cookbook has only been tested on Ubuntu 10.04 and Mac OS X 10.8. The homebrew cookbook is required to install the collectd package on Mac OS X.

To use the `collectd::collectd_web` recipe you need the [apache2](https://github.com/opscode/cookbooks/tree/master/apache2) cookbook.

To use this cookbook on Mac OS X, you need to include the [homebrew](https://github.com/opscode-cookbooks/homebrew) cookbook in your node's run list before including this cookbook.

The [collectd_plugins](https://github.com/coderanger/chef-collectd_plugins) cookbook is not required, but provides many common plugin definitions for easy reuse.

# ATTRIBUTES #

* collectd.basedir - Base folder for collectd output data.
* collectd.cfg_dir - Base folder for collectd configuration files.
* 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.
Expand Down
23 changes: 19 additions & 4 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,27 @@
# limitations under the License.
#

default[:collectd][:base_dir] = "/var/lib/collectd"
default[:collectd][:plugin_dir] = "/usr/lib/collectd"
default[:collectd][:types_db] = ["/usr/share/collectd/types.db"]
default[:collectd][:interval] = 10
default[:collectd][:read_threads] = 5
default[:collectd][:pkg_name] = "collectd-core"

case node[:platform_family]
when "mac_os_x"
default[:collectd][:base_dir] = "/usr/local/var/lib/collectd"
default[:collectd][:cfg_dir] = "/usr/local/etc/collectd"
default[:collectd][:cfg_group] = "wheel"
default[:collectd][:plugin_dir] = "/usr/local/lib/collectd"
default[:collectd][:types_db] = ["/usr/local/share/collectd/types.db"]
default[:collectd][:pkg_name] = "collectd"
default[:collectd][:svc_name] = "homebrew.mxcl.collectd"
else
default[:collectd][:base_dir] = "/var/lib/collectd"
default[:collectd][:cfg_dir] = "/etc/collectd"
default[:collectd][:cfg_group] = "root"
default[:collectd][:plugin_dir] = "/usr/lib/collectd"
default[:collectd][:types_db] = ["/usr/share/collectd/types.db"]
default[:collectd][:pkg_name] = "collectd-core"
default[:collectd][:svc_name] = "collectd"
end

default[:collectd][:collectd_web][:path] = "/srv/collectd_web"
default[:collectd][:collectd_web][:hostname] = "collectd"
6 changes: 3 additions & 3 deletions definitions/collectd_plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
#

define :collectd_plugin, :options => {}, :template => nil, :cookbook => nil do
template "/etc/collectd/plugins/#{params[:name]}.conf" do
template "#{node[:collectd][:cfg_dir]}/plugins/#{params[:name]}.conf" do
owner "root"
group "root"
group node[:collectd][:cfg_group]
mode "644"
if params[:template].nil?
source "plugin.conf.erb"
Expand All @@ -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][:cfg_dir]}/plugins/python.conf")
rescue ArgumentError,Chef::Exceptions::ResourceNotFound
collectd_plugin "python" do
options :paths=>[node[:collectd][:plugin_dir]], :modules=>{}
Expand Down
23 changes: 23 additions & 0 deletions files/default/service/homebrew.mxcl.collectd.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>homebrew.mxcl.collectd</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/Cellar/collectd/5.4.1/sbin/collectd</string>
<string>-f</string>
<string>-C</string>
<string>/usr/local/etc/collectd.conf</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/usr/local/var/log/collectd.log</string>
<key>StandardOutPath</key>
<string>/usr/local/var/log/collectd.log</string>
</dict>
</plist>
5 changes: 5 additions & 0 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@
description "Install and configure the collectd monitoring daemon"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "1.0.0"
supports "mac_os_x"
supports "ubuntu"
suggests "homebrew"

# Testing dependencies
depends "apt", ">= 2.4.0"
34 changes: 17 additions & 17 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,49 +21,51 @@
package_name node[:collectd][:pkg_name]
end

service "collectd" do
supports :restart => true, :status => true
end

directory "/etc/collectd" do
directory node[:collectd][:cfg_dir] do
owner "root"
group "root"
group node[:collectd][:cfg_group]
mode "755"
end

directory "/etc/collectd/plugins" do
directory "#{node[:collectd][:cfg_dir]}/plugins" do
owner "root"
group "root"
group node[:collectd][:cfg_group]
mode "755"
end

directory node[:collectd][:base_dir] do
owner "root"
group "root"
group node[:collectd][:cfg_group]
mode "755"
recursive true
end

directory node[:collectd][:plugin_dir] do
owner "root"
group "root"
group node[:collectd][:cfg_group]
mode "755"
recursive true
end

%w(collectd collection thresholds).each do |file|
template "/etc/collectd/#{file}.conf" do
template "#{node[:collectd][:cfg_dir]}/#{file}.conf" do
source "#{file}.conf.erb"
owner "root"
group "root"
group node[:collectd][:cfg_group]
mode "644"
notifies :restart, resources(:service => "collectd")
notifies :restart, "service[collectd]"
end
end

if node[:platform_family] == "mac_os_x"
link "/usr/local/etc/collectd.conf" do
to "/usr/local/etc/collectd/collectd.conf"
end
end

ruby_block "delete_old_plugins" do
block do
Dir['/etc/collectd/plugins/*.conf'].each do |path|
Dir["#{node[:collectd][:cfg_dir]}/plugins/*.conf"].each do |path|
autogen = false
File.open(path).each_line do |line|
if line.start_with?('#') and line.include?('autogenerated')
Expand All @@ -84,6 +86,4 @@
end
end

service "collectd" do
action [:enable, :start]
end
include_recipe "collectd::service"
33 changes: 33 additions & 0 deletions recipes/service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#
# Cookbook Name:: collectd
# Recipe:: service
#
# Copyright 2010, Atari, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

if node[:platform_family] == "mac_os_x"
cookbook_file "/System/Library/LaunchDaemons/homebrew.mxcl.collectd.plist" do
source "service/homebrew.mxcl.collectd.plist"
owner "root"
group "wheel"
mode 00644
end
end

service "collectd" do
service_name node[:collectd][:svc_name]
supports :restart => true, :status => true
action [:enable, :start]
end
6 changes: 3 additions & 3 deletions templates/default/collectd.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
# You should also read /usr/share/doc/collectd/README.Debian.plugins before
# enabling any more plugins.

Hostname "<%= @node[:fqdn] %>"
Hostname "<%= @node[:fqdn] || @node[:hostname] %>"
FQDNLookup true
BaseDir "<%= @node[:collectd][:base_dir] %>"
PluginDir "<%= @node[:collectd][:plugin_dir] %>"
TypesDB "<%= @node[:collectd][:types_db].join('", "') %>"
Interval <%= @node[:collectd][:interval] %>
ReadThreads <%= @node[:collectd][:read_threads] %>

Include "/etc/collectd/plugins/*.conf"
Include "/etc/collectd/thresholds.conf"
Include "<%= @node[:collectd][:cfg_dir] %>/plugins/*.conf"
Include "<%= @node[:collectd][:cfg_dir] %>/thresholds.conf"