Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

First commit. Includes an apache vhost monitor and a mysql plugin to …

…monitor the key cache
  • Loading branch information...
commit e7909b41fa67eae069fba936c62e27b8a628a313 0 parents
Aaron Parecki authored October 11, 2010
32  README.md
Source Rendered
... ...
@@ -0,0 +1,32 @@
  1
+
  2
+ABOUT
  3
+=====
  4
+
  5
+This project provides several munin plugins to monitor various aspects of a web server. Most
  6
+of these work by linking a script in this folder to /etc/munin/plugins/plugin_name. They have
  7
+instructions at the top of the file indicating the name to link the script as.
  8
+
  9
+
  10
+LICENSE
  11
+=======
  12
+
  13
+Copyright (c) 2010 Aaron Parecki
  14
+
  15
+Permission is hereby granted, free of charge, to any person obtaining a copy
  16
+of this software and associated documentation files (the "Software"), to deal
  17
+in the Software without restriction, including without limitation the rights
  18
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  19
+copies of the Software, and to permit persons to whom the Software is
  20
+furnished to do so, subject to the following conditions:
  21
+
  22
+The above copyright notice and this permission notice shall be included in
  23
+all copies or substantial portions of the Software.
  24
+
  25
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  26
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  27
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  28
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  29
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  30
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  31
+THE SOFTWARE.
  32
+
60  apache_vhosts.php
... ...
@@ -0,0 +1,60 @@
  1
+#!/usr/bin/php
  2
+<?php
  3
+/**
  4
+ * README
  5
+ * 
  6
+ * Add an additional line to each vhost you want to track with the domain name of the host
  7
+ * This will write a period for every hit to the vhost
  8
+ * CustomLog /web/logs/munin/example.com "."
  9
+ */
  10
+
  11
+$basedir = '/web/logs/munin';
  12
+
  13
+$files = scandir($basedir);
  14
+
  15
+// arg1 is blank or 'config' when munin runs it
  16
+$mode = array_key_exists(1, $argv) ? $argv[1] : '';
  17
+
  18
+
  19
+if($mode == 'config')
  20
+{
  21
+	echo 'graph_title Apache vhosts' . "\n";
  22
+		
  23
+	echo 'graph_info Shows the requests per second for each vhost.' . "\n";
  24
+	echo 'graph_vlabel requests / ${graph_period}' . "\n";
  25
+	echo 'graph_category apache' . "\n";
  26
+	echo 'graph_args --lower-limit 0' . "\n";
  27
+	echo 'graph_scale yes' . "\n";
  28
+	
  29
+	$first = TRUE;
  30
+	foreach($files as $domain)
  31
+	{
  32
+		if(substr($domain, 0, 1) != '.')
  33
+		{
  34
+			$key = generate_munin_key($domain);
  35
+			echo $key . '.label ' . $domain . "\n";
  36
+			echo $key . '.min 0' . "\n";
  37
+			echo $key . '.type DERIVE' . "\n";
  38
+			echo $key . '.draw ' . ($first ? 'AREA' : 'STACK') . "\n";
  39
+			$first = FALSE;
  40
+		}
  41
+	}
  42
+}
  43
+else
  44
+{
  45
+	foreach($files as $domain)
  46
+	{
  47
+		if(substr($domain, 0, 1) != '.')
  48
+		{
  49
+			$key = generate_munin_key($domain);
  50
+			$value = filesize($basedir . '/' . $domain) / 2;
  51
+			echo $key . '.value ' . $value . "\n";
  52
+		}
  53
+	}
  54
+}
  55
+
  56
+function generate_munin_key($domain)
  57
+{
  58
+	return preg_replace(array('/\./', '/[^a-z0-9_]/'), array('_', ''), $domain);	
  59
+}
  60
+?>
85  mysql_keycache.php
... ...
@@ -0,0 +1,85 @@
  1
+#!/usr/bin/php
  2
+<?php
  3
+/**
  4
+ * README
  5
+ * 
  6
+ * Link this file as mysql_keycache_ratae and mysql_keycache in the plugins folder.
  7
+ * Define your database settings in the PDO variables.
  8
+ */
  9
+
  10
+define('PDO_DSN', 'mysql:dbname=information_schema;host=localhost');
  11
+define('PDO_USER', 'munin');
  12
+define('PDO_PASS', 'munin');
  13
+
  14
+
  15
+// config or blank
  16
+$mode = array_key_exists(1, $argv) ? $argv[1] : '';
  17
+
  18
+$section = explode('_', $argv[0]);
  19
+$section = array_key_exists(2, $section) ? $section[2] : '';
  20
+
  21
+$variables = array(
  22
+	'key_reads' => 'The number of physical reads of a key block from disk.',
  23
+	'key_read_requests' => 'The number of requests to read a key block from the cache.',
  24
+	'key_writes' => 'The number of physical writes of a key block to disk.',
  25
+	'key_write_requests' => 'The number of requests to write a key block to the cache.'
  26
+);
  27
+
  28
+$status = d()->query('SHOW STATUS');
  29
+$status->execute();
  30
+$info = array();
  31
+while($s = $status->fetch())
  32
+	if(in_array(strtolower($s['Variable_name']), array_keys($variables)))
  33
+		$info[strtolower($s['Variable_name'])] = $s['Value'];
  34
+
  35
+if($section == 'rate')
  36
+{
  37
+	if($mode == 'config')
  38
+	{
  39
+		echo 'graph_title MySQL Key Read and Request Rate' . "\n";
  40
+		echo 'graph_vlabel per ${graph_period}' . "\n";
  41
+		echo 'graph_category mysql' . "\n";
  42
+		echo 'graph_period minute' . "\n";
  43
+		foreach($info as $k=>$n)
  44
+		{
  45
+			echo $k . '.label ' . $k . "\n";
  46
+			echo $k . '.type DERIVE' . "\n";
  47
+			echo $k . '.min 0' . "\n";
  48
+			echo $k . '.info ' . $variables[$k] . "\n";
  49
+		}
  50
+	}
  51
+	else
  52
+	{	
  53
+		foreach($info as $k=>$n)
  54
+			echo $k . '.value ' . $n . "\n";
  55
+	}
  56
+}
  57
+else
  58
+{
  59
+	if($mode == 'config')
  60
+	{
  61
+		echo 'graph_title MySQL Key Cache Effectiveness' . "\n";
  62
+		echo 'graph_category mysql' . "\n";
  63
+		echo 'graph_period minute' . "\n";
  64
+		echo 'key_read_cache.label Key Read Cache Miss %' . "\n";
  65
+		echo 'key_read_cache.info The number of physical key reads over the number of requests. Less than 1% is ideal.' . "\n";
  66
+		echo 'key_write_cache.label Key Write Cache Miss %' . "\n";
  67
+		echo 'key_write_cache.info The number of physical key writes over the number of requests.' . "\n";
  68
+	}
  69
+	else
  70
+	{
  71
+		echo 'key_read_cache.value ' . round(($info['key_reads'] * 100) / $info['key_read_requests'], 3) . "\n";
  72
+		echo 'key_write_cache.value ' . round(($info['key_writes'] * 100) / $info['key_write_requests'], 3) . "\n";
  73
+	}
  74
+}			
  75
+				
  76
+
  77
+function d()
  78
+{
  79
+	static $DB;
  80
+	if(!isset($DB))
  81
+		$DB = new PDO(PDO_DSN, PDO_USER, PDO_PASS);
  82
+	return $DB;
  83
+}
  84
+
  85
+?>

0 notes on commit e7909b4

Please sign in to comment.
Something went wrong with that request. Please try again.