summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--files/munin/mysql_size_all179
-rw-r--r--manifests/client/perl.pp7
-rw-r--r--manifests/client/perl/debian.pp6
-rw-r--r--manifests/server/base.pp2
-rw-r--r--manifests/server/munin/base.pp20
-rw-r--r--manifests/server/munin/debian.pp17
-rw-r--r--manifests/server/munin/default.pp65
7 files changed, 259 insertions, 37 deletions
diff --git a/files/munin/mysql_size_all b/files/munin/mysql_size_all
new file mode 100644
index 0000000..f5954ad
--- /dev/null
+++ b/files/munin/mysql_size_all
@@ -0,0 +1,179 @@
+#!/usr/bin/perl
+#
+# Copyright (C) 2007 - Rodolphe Quiedeville <rodolphe@quiedeville.org>
+# Copyright (C) 2003-2004 - Andreas Buer
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; version 2 dated June,
+# 1991.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# $Log$
+# Revision 1.1 2007/01/17 10:41:01 rodo
+# Change incorrect family
+#
+# Revision 1.0 2007/01/16 15:57:01 rodo
+# Created by Rodolphe Quiedeville
+#
+# Parameters:
+#
+# config
+# autoconf
+#
+# Configuration variables
+#
+# mysqlopts - Options to pass to mysql
+# mysqladmin - Override location of mysqladmin
+#
+#%# family=manual
+#%# capabilities=autoconf
+
+use strict;
+
+# unless ($0 =~ /mysql_size(?:_([^_]+)|)_(.+)\s*$/)
+# {
+# die "Could not parse name $0.\n";
+# }
+# my $db = $2;
+
+my $COMMAND;
+my $MYSQLADMIN = $ENV{mysqladmin} || "mysql";
+
+my %WANTED = ( "Index" => "index",
+ "Datas" => "datas",
+ );
+
+my $arg = shift();
+
+if ($arg eq 'config') {
+ print_config();
+ exit();
+} elsif ($arg eq 'autoconf') {
+ unless (test_service() ) {
+ print "yes\n";
+ } else {
+ print "no\n";
+ }
+ exit;
+}
+
+sub getDBList;
+foreach my $db (getDBList()) {
+
+ my $datas = 0;
+ my $indexes = 0;
+ my (@infos,$info,$i_data,$i_index);
+
+ $COMMAND = "$MYSQLADMIN $ENV{mysqlopts} $db -e 'show table status;' | head -n 1";
+
+ open(SERVICE, "$COMMAND |")
+ or die("Coult not execute '$COMMAND': $!");
+
+ while (<SERVICE>) {
+ (@infos) = split;
+ }
+ close(SERVICE);
+
+ my $i = 0;
+ foreach $info (@infos) {
+ $i++;
+ if ($info eq 'Data_length') {
+ $i_data = $i;
+ next;
+ }
+ if ($info eq 'Index_length') {
+ $i_index = $i;
+ last;
+ }
+ }
+ my $total_size = 0;
+ if ($i_data>0 && $i_index>0) {
+ $COMMAND = "$MYSQLADMIN $ENV{mysqlopts} $db -e 'show table status;' | cut -f $i_data,$i_index | grep -v leng";
+
+ open(SERVICE, "$COMMAND |")
+ or die("Coult not execute '$COMMAND': $!");
+
+ while (<SERVICE>) {
+ (m/(\d+).*?(\d+(?:\.\d+)?)/);
+ $datas += $1;
+ $indexes += $2;
+ }
+ close(SERVICE);
+
+ $total_size = $datas+$indexes;
+ }
+ print("$db.value $total_size\n");
+# print("datas.value $datas\n");
+# print("index.value $indexes\n");
+}
+
+
+sub print_config {
+
+ my $num = 0;
+
+ my @dbs = getDBList;
+
+ print("graph_title MySQL databases size\n");
+ print ('graph_args --base 1024 -l 0
+graph_vlabel bytes
+graph_category mysql
+graph_info Plugin available at <a href="http://rodolphe.quiedeville.org/hack/munin/">http://rodolphe.quiedeville.org/hack/munin/</a>
+');
+
+ for my $db (@dbs) {
+ my $title = "$db";
+ print("$title.label ${title}\n",
+ "$title.min 0\n",
+ "$title.type GAUGE\n",
+ "$title.draw ", ($num) ? "STACK" : "AREA" , "\n",
+ );
+ $num++;
+ }
+}
+
+
+sub test_service {
+
+ my $return = 1;
+
+ system ("$MYSQLADMIN --version >/dev/null 2>/dev/null");
+ if ($? == 0)
+ {
+ system ("$COMMAND >/dev/null 2>/dev/null");
+ if ($? == 0)
+ {
+ print "yes\n";
+ $return = 0;
+ }
+ else
+ {
+ print "no (could not connect to mysql)\n";
+ }
+ }
+ else
+ {
+ print "no (mysqladmin not found)\n";
+ }
+ exit $return;
+}
+
+sub getDBList {
+ my @dbs;
+ foreach my $f (glob("/var/lib/mysql/*")) {
+ if (-d $f) {
+ $f =~ s!.*/!!;
+ @dbs[$#dbs+1]=$f };
+ }
+ return @dbs;
+}
+
diff --git a/manifests/client/perl.pp b/manifests/client/perl.pp
new file mode 100644
index 0000000..09a790b
--- /dev/null
+++ b/manifests/client/perl.pp
@@ -0,0 +1,7 @@
+class mysql::client::perl {
+
+ case $operatingsystem {
+ debian: { include mysql::client::perl::debian }
+ }
+
+}
diff --git a/manifests/client/perl/debian.pp b/manifests/client/perl/debian.pp
new file mode 100644
index 0000000..790eaff
--- /dev/null
+++ b/manifests/client/perl/debian.pp
@@ -0,0 +1,6 @@
+class mysql::client::perl::debian {
+
+ package { 'libdbd-mysql-perl':
+ ensure => present,
+ }
+}
diff --git a/manifests/server/base.pp b/manifests/server/base.pp
index 5031876..07b26b8 100644
--- a/manifests/server/base.pp
+++ b/manifests/server/base.pp
@@ -56,7 +56,7 @@ class mysql::server::base {
exec { 'mysql_set_rootpw':
command => '/usr/local/sbin/setmysqlpass.sh',
- unless => "mysqladmin -uroot status > /dev/null",
+ unless => '/usr/bin/mysqladmin -uroot status > /dev/null',
require => [ File['mysql_setmysqlpass.sh'], Package['mysql-server'] ],
refreshonly => true,
}
diff --git a/manifests/server/munin/base.pp b/manifests/server/munin/base.pp
new file mode 100644
index 0000000..ad4bb8a
--- /dev/null
+++ b/manifests/server/munin/base.pp
@@ -0,0 +1,20 @@
+class mysql::server::munin::base {
+
+ file {
+ "/usr/local/share/munin-plugins/mysql_connections":
+ source => "puppet:///modules/mysql/munin/mysql_connections",
+ mode => 0755, owner => root, group => root;
+
+ "/usr/local/share/munin-plugins/mysql_qcache":
+ source => "puppet:///modules/mysql/munin/mysql_qcache",
+ mode => 0755, owner => root, group => root;
+
+ "/usr/local/share/munin-plugins/mysql_qcache_mem":
+ source => "puppet:///modules/mysql/munin/mysql_qcache_mem",
+ mode => 0755, owner => root, group => root;
+
+ "/usr/local/share/munin-plugins/mysql_size_all":
+ source => "puppet:///modules/mysql/munin/mysql_size_all",
+ mode => 0755, owner => root, group => root;
+ }
+}
diff --git a/manifests/server/munin/debian.pp b/manifests/server/munin/debian.pp
index 2b2acb4..d1636d5 100644
--- a/manifests/server/munin/debian.pp
+++ b/manifests/server/munin/debian.pp
@@ -1,9 +1,14 @@
# manifests/server/munin/debian.pp
-class mysql::server::munin::debian {
- munin::plugin {
- [mysql_bytes, mysql_queries, mysql_slowqueries, mysql_threads]:
- config => "user root\nenv.mysqlopts --defaults-file=/etc/mysql/debian.cnf",
- require => Package['mysql'],
- }
+class mysql::server::munin::debian inherits mysql::server::munin::base {
+ munin::plugin {
+ [ mysql_bytes, mysql_queries, mysql_slowqueries, mysql_threads ]:
+ config => "user root\nenv.mysqlopts --defaults-file=/etc/mysql/debian.cnf",
+ require => Package['mysql'];
+
+ [ mysql_connections, mysql_qcache, mysql_cache_mem, mysql_size_all ]:
+ config => "user root\nenv.mysqlopts --defaults-file=/etc/mysql/debian.cnf",
+ script_path_in => "/usr/local/share/munin-plugins",
+ require => Package['mysql'];
+ }
}
diff --git a/manifests/server/munin/default.pp b/manifests/server/munin/default.pp
index 424f8b2..130f3dc 100644
--- a/manifests/server/munin/default.pp
+++ b/manifests/server/munin/default.pp
@@ -1,39 +1,44 @@
# manifests/server/munin/default.pp
-class mysql::server::munin::default {
- case $munin_mysql_password {
- '': { fail("please specify \$munin_mysql_password to enable mysql munin plugin")}
- }
+class mysql::server::munin::default inherits mysql::server::munin::base {
+ case $munin_mysql_password {
+ '': { fail("please specify \$munin_mysql_password to enable mysql munin plugin")}
+ }
- mysql_user{'munin@localhost':
- password_hash => mysql_password("$munin_mysql_password"),
- require => Package['mysql'],
- }
+ mysql_user{'munin@localhost':
+ password_hash => mysql_password("$munin_mysql_password"),
+ require => Package['mysql'],
+ }
- mysql_grant{'munin@localhost':
- privileges => 'select_priv',
- require => [ Mysql_user['munin@localhost'], Package['mysql'] ],
- }
+ mysql_grant{'munin@localhost':
+ privileges => 'select_priv',
+ require => [ Mysql_user['munin@localhost'], Package['mysql'] ],
+ }
- munin::plugin {
- [mysql_bytes, mysql_queries, mysql_slowqueries, mysql_threads]:
- config => "env.mysqlopts --user=munin --password=${munin_mysql_password} -h localhost",
- require => [ Mysql_grant['munin@localhost'], Mysql_user['munin@localhost'], Package['mysql'] ]
- }
+ munin::plugin {
+ [ mysql_bytes, mysql_queries, mysql_slowqueries, mysql_threads ]:
+ config => "env.mysqlopts --user=munin --password=${munin_mysql_password} -h localhost",
+ require => [ Mysql_grant['munin@localhost'], Mysql_user['munin@localhost'], Package['mysql'] ];
- Munin::Plugin::Deploy{
+ [ mysql_connections, mysql_qcache, mysql_cache_mem, mysql_size_all ]:
+ script_path_in => "/usr/local/share/munin-plugins",
+ config => "env.mysqlopts --user=munin --password=${munin_mysql_password} -h localhost",
+ require => [ Mysql_grant['munin@localhost'], Mysql_user['munin@localhost'], Package['mysql'] ];
+ }
+
+ Munin::Plugin::Deploy {
config => "env.mysqlopts --user=munin --password=$munin_mysql_password -h localhost",
require =>
- [ Mysql_grant['munin@localhost'],
- Mysql_user['munin@localhost'],
- Package['mysql'] ]
- }
- munin::plugin::deploy{
- 'mysql_connections':
- source => 'mysql/munin/mysql_connections';
- 'mysql_qcache':
- source => 'mysql/munin/mysql_qcache';
- 'mysql_qcache_mem':
- source => 'mysql/munin/mysql_qcache_mem';
- }
+ [ Mysql_grant['munin@localhost'],
+ Mysql_user['munin@localhost'],
+ Package['mysql'] ]
+ }
+ munin::plugin::deploy{
+ 'mysql_connections':
+ source => 'mysql/munin/mysql_connections';
+ 'mysql_qcache':
+ source => 'mysql/munin/mysql_qcache';
+ 'mysql_qcache_mem':
+ source => 'mysql/munin/mysql_qcache_mem';
+ }
}