Permalink
Browse files

COOK-261, better search from 0.8 and additional plugins (nginx, memca…

…ched)
  • Loading branch information...
1 parent fc73418 commit 3da32522968d0a8933a5b311244b74c1d811db4f @jtimberman jtimberman committed Feb 24, 2010
View
@@ -0,0 +1,95 @@
+= DESCRIPTION:
+
+Installs and configures Nagios for a server and for clients using Chef 0.8 search capabilities.
+
+= REQUIREMENTS:
+
+Requires Chef 0.8+ for search capability of roles and data bags.
+
+The monitoring server that uses this recipe should have a role named 'monitoring'. A role named after the environment (e.g., "production") and a node attribute app_environment with a value of the same should be created for all nodes. The server uses this to search for only nodes that belong to its same environment.
+
+Because of the heavy use of search, this recipe will not work with Chef Solo, as it cannot do any searches without a server.
+
+== Platform:
+
+Tested on Ubuntu 9.04, Ubuntu 9.10 and Debian 5.
+
+== Cookbooks:
+
+Opscode cookbooks:
+
+* apache2
+
+To install perl cpan modules for munin plugins:
+
+* perl
+
+= USAGE:
+
+This document describes how to add custom munin plugins.
+
+The munin cookbook now has a definition that can be used to enable a new plugin for data gathering on a client. If an existing munin plugin is desired, call the definition:
+
+ munin_plugin "nfs_client"
+
+By default the plugin file name is the name parameter here. Specify the plugin parameter to use something else.
+
+ munin_plugin "nfs_client"
+ plugin "nfs_client_"
+ end
+
+This creates a symlink from the plugins distribution directory, `/usr/share/munin/plugins` to the enabled plugins directory, `/etc/munin/plu
+gins`, and once the server poller picks it up will have new graph data for that plugin. See the plugins distribution directory for available
+ plugins or add your own.
+
+If a custom plugin is required, add the plugin file to the munin cookbook in `site-cookbooks/munin/files/default/plugins`. Call the definition specifying that the plugin file should be downloaded from the cookbook.
+
+ munin_plugin "nfs_client_custom"
+ create_file true
+ end
+
+By default in both cases, the plugin is enabled. If a plugin should be disabled, use the `enable` parameter:
+
+ munin_plugin "nfs_client_custom"
+ enable false
+ end
+
+Some plugins may require other configuration. For example, to use the memcache plugins, you'll need the Cache::Memcache cpan module installed, and use the munin_plugin definition. The perl cookbook from opscode includes a definition to handle this easily.
+
+ cpan_module "Cache::Memcached"
+
+Then for example in your memcache recipe:
+
+ %w(
+ memcached_bytes_
+ memcached_connections_
+ memcached_hits_
+ memcached_items_
+ memcached_requests_
+ memcached_responsetime_
+ memcached_traffic_
+ ).each do |plugin_name|
+ munin_plugin plugin_name do
+ plugin "#{plugin_name}#{node[:ipaddress].gsub('.','_')}_#{node[:memcached][:port]}"
+ create_file true
+ end
+ end
+
+= LICENSE and AUTHOR:
+
+Author:: Nathan Haneysmith <nathan@opscode.com>
+Author:: Joshua Timberman <joshua@opscode.com>
+
+Copyright 2009-2010, Opscode, 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.
@@ -0,0 +1,47 @@
+#
+# Cookbook Name:: munin
+# Definition:: munin_plugin
+#
+# Copyright 2010, OpsCode, 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.
+#
+
+
+define :munin_plugin, :plugin_config => "/etc/munin/plugins", :plugin_dir => "/usr/share/munin/plugins", :create_file => false, :enable => true do
+
+ include_recipe "munin::client"
+
+ plugin = params[:plugin] ? params[:plugin] : params[:name]
+
+ if params[:create_file]
+ remote_file "#{params[:plugin_dir]}/#{params[:name]}" do
+ cookbook "munin"
+ source "plugins/#{params[:name]}"
+ owner "root"
+ group "root"
+ mode 0755
+ end
+ end
+
+ link "#{params[:plugin_config]}/#{plugin}" do
+ to "#{params[:plugin_dir]}/#{params[:name]}"
+ if params[:enable]
+ action :create
+ else
+ action :delete
+ end
+ notifies :restart, resources(:service => "munin-node")
+ end
+
+end
@@ -0,0 +1,3 @@
+# Generated by Chef.
+# Included as a placeholder, but not used in the recipes, we use OpenID
+# based login instead.
@@ -0,0 +1,9 @@
+#
+# cron-jobs for munin
+#
+
+MAILTO=root
+
+@reboot root if [ ! -d /var/run/munin ]; then /bin/bash -c 'perms=(`/usr/sbin/dpkg-statoverride --list /var/run/munin`); mkdir /var/run/munin; chown ${perms[0]:-munin}:${perms[1]:-root} /var/run/munin; chmod ${perms[2]:-0755} /var/run/munin'; fi
+*/5 * * * * munin if [ -x /usr/bin/munin-cron ]; then /usr/bin/munin-cron; fi
+14 10 * * * munin if [ -x /usr/share/munin/munin-limits ]; then /usr/share/munin/munin-limits; fi
@@ -0,0 +1 @@
+Put the custom munin plugin files here.
@@ -0,0 +1,36 @@
+#!/usr/bin/env perl
+# ex:ts=4
+
+use strict;
+use warnings;
+
+use Cache::Memcached;
+
+$0 =~ /memcached_bytes_(\d+_\d+_\d+_\d+)_(\d+)$/;
+my ($ip, $port) = ($1, $2);
+$ip =~ s/_/./g;
+my $address = "$ip:$port";
+
+my $cmd = shift || '';
+if ($cmd eq 'config') {
+ print "graph_title Memcached bytes used for $address\n";
+ print "graph_args --base 1024 -l 0\n";
+ print "graph_vlabel bytes\n";
+ print "graph_category memcached\n";
+ print "graph_info This graph monitors the size of the memcached cache.\n";
+ print "bytes.label bytes used\n";
+ print "bytes.info Number of bytes currently used\n";
+ print "bytes.min 0\n";
+ print "bytes.draw AREA\n";
+ print "maxbytes.label maximum available\n";
+ print "maxbytes.info The configured cache size\n";
+ print "maxbytes.min 0\n";
+ exit 0;
+}
+
+my $memd = new Cache::Memcached { 'servers' => [$address] };
+my $memstats = $memd->stats(['misc']);
+
+print "bytes.value " . $memstats->{hosts}->{$address}->{misc}->{bytes} . "\n";
+print "maxbytes.value " .
+ $memstats->{hosts}->{$address}->{misc}->{limit_maxbytes} . "\n";
@@ -0,0 +1,32 @@
+#!/usr/bin/env perl
+# ex:ts=4
+
+use strict;
+use warnings;
+
+use Cache::Memcached;
+
+my $cmd = shift || '';
+$0 =~ /memcached_connections_(\d+_\d+_\d+_\d+)_(\d+)$/;
+my ($ip, $port) = ($1, $2);
+$ip =~ s/_/./g;
+my $address = "$ip:$port";
+
+if ($cmd eq 'config') {
+ print "graph_title Memcached connections for $address\n";
+ print "graph_args --base 1000 -l 0\n";
+ print "graph_vlabel connections\n";
+ print "graph_category memcached\n";
+ print "graph_info This graph monitors the connections to the memcached server.\n";
+ print "connections.label connections\n";
+ print "connections.info Number of connections to memcached\n";
+ print "connections.min 0\n";
+ print "connections.draw AREA\n";
+ exit 0;
+}
+
+my $memd = new Cache::Memcached { 'servers' => [$address] };
+my $memstats = $memd->stats(['misc']);
+
+print "connections.value " .
+ $memstats->{hosts}->{$address}->{misc}->{curr_connections} . "\n";
@@ -0,0 +1,38 @@
+#!/usr/bin/env perl
+# ex:ts=4
+
+use strict;
+use warnings;
+
+use Cache::Memcached;
+
+$0 =~ /memcached_hits_(\d+_\d+_\d+_\d+)_(\d+)$/;
+my ($ip, $port) = ($1, $2);
+$ip =~ s/_/./g;
+my $address = "$ip:$port";
+
+my $cmd = shift || '';
+if ($cmd eq 'config') {
+ print "graph_title Memcached cache hits and misses for $address\n";
+ print "graph_args --base 1000 -l 0\n";
+ print "graph_vlabel requests\n";
+ print "graph_category memcached\n";
+ print "graph_info This graph monitors the number of cache hits and misses.\n";
+ print "hits.label hits\n";
+ print "hits.info Number of cache hits\n";
+ print "hits.min 0\n";
+ print "hits.type DERIVE\n";
+ print "misses.label misses\n";
+ print "misses.info Number of cache misses\n";
+ print "misses.min 0\n";
+ print "misses.type DERIVE\n";
+ print "misses.draw AREA\n";
+ exit 0;
+}
+
+my $memd = new Cache::Memcached { 'servers' => [$address] };
+my $memstats = $memd->stats(['misc']);
+
+print "hits.value " . $memstats->{hosts}->{$address}->{misc}->{get_hits} . "\n";
+print "misses.value " .
+ $memstats->{hosts}->{$address}->{misc}->{get_misses} . "\n";
@@ -0,0 +1,32 @@
+#!/usr/bin/env perl
+# ex:ts=4
+
+use strict;
+use warnings;
+
+use Cache::Memcached;
+
+my $cmd = shift || '';
+$0 =~ /memcached_items_(\d+_\d+_\d+_\d+)_(\d+)$/;
+my ($ip, $port) = ($1, $2);
+$ip =~ s/_/./g;
+my $address = "$ip:$port";
+
+if ($cmd eq 'config') {
+ print "graph_title Memcached cached items for $address\n";
+ print "graph_args --base 1000 -l 0\n";
+ print "graph_vlabel items\n";
+ print "graph_category memcached\n";
+ print "graph_info This graph monitors the number of items stored by the memcached server.\n";
+ print "items.label items\n";
+ print "items.info Number of cached items\n";
+ print "items.min 0\n";
+ print "items.draw AREA\n";
+ exit 0;
+}
+
+my $memd = new Cache::Memcached { 'servers' => [$address] };
+my $memstats = $memd->stats(['misc']);
+
+print "items.value " .
+ $memstats->{hosts}->{$address}->{misc}->{curr_items} . "\n";
@@ -0,0 +1,38 @@
+#!/usr/bin/env perl
+# ex:ts=4
+
+use strict;
+use warnings;
+
+use Cache::Memcached;
+
+my $cmd = shift || '';
+$0 =~ /memcached_requests_(\d+_\d+_\d+_\d+)_(\d+)$/;
+my ($ip, $port) = ($1, $2);
+$ip =~ s/_/./g;
+my $address = "$ip:$port";
+
+if ($cmd eq 'config') {
+ print "graph_title Memcached requests for $address\n";
+ print "graph_args --base 1000 -l 0\n";
+ print "graph_vlabel requests\n";
+ print "graph_category memcached\n";
+ print "graph_info This graph monitors the number of get and set requests.\n";
+ print "gets.label gets\n";
+ print "gets.info Number of get requests\n";
+ print "gets.min 0\n";
+ print "gets.type DERIVE\n";
+ print "gets.draw AREA\n";
+ print "sets.label sets\n";
+ print "sets.info Number of set requests\n";
+ print "sets.min 0\n";
+ print "sets.type DERIVE\n";
+ print "sets.draw STACK\n";
+ exit 0;
+}
+
+my $memd = new Cache::Memcached { 'servers' => [$address] };
+my $memstats = $memd->stats(['misc']);
+
+print "gets.value " . $memstats->{hosts}->{$address}->{misc}->{cmd_get} . "\n";
+print "sets.value " . $memstats->{hosts}->{$address}->{misc}->{cmd_set} . "\n";
@@ -0,0 +1,34 @@
+#!/usr/bin/perl
+use Cache::Memcached;
+use Time::HiRes qw(gettimeofday tv_interval);
+
+$0 =~ /memcached_responsetime_(\d+_\d+_\d+_\d+)_(\d+)$/;
+my ($ip, $port) = ($1, $2);
+$ip =~ s/_/./g;
+my $address = "$ip:$port";
+
+my $cmd = shift || '';
+if ($cmd eq 'config') {
+ print "graph_title Memcached Response Time for $address \n";
+ print "graph_args --base 1000 -l 0\n";
+ print "graph_vlabel response time\n";
+ print "graph_category memcached\n";
+ print "graph_scale yes\n";
+ print "time.label time\n";
+ print "time.info Response time in seconds\n";
+ print "time.min 0\n";
+ print "time.type GAUGE\n";
+ print "time.draw AREA\n";
+ exit 0;
+}
+
+#print "I have $address \n";
+my $cache = Cache::Memcached->new( { servers => [ $address ], debug => 1 } );
+
+my $start = [gettimeofday];
+my $stats = $cache->stats( qw[misc] );
+my $elapsed = tv_interval($start, [gettimeofday]);
+
+die "I couldn't connect to memcached and run stats misc" unless $stats;
+
+print "time.value " . $elapsed . "\n";
Oops, something went wrong.

0 comments on commit 3da3252

Please sign in to comment.