<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Shell Tips ! &#187; Tips</title>
	<atom:link href="http://www.shell-tips.com/category/tips/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.shell-tips.com</link>
	<description>Some useful tips about CLI tools, Shell scripts and batch files... GNU Bash, Windows XP, SQL, Help Sheets / Cheat Sheets, etc.</description>
	<lastBuildDate>Mon, 14 Jun 2010 08:56:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Performing Math calculation in Bash</title>
		<link>http://www.shell-tips.com/2010/06/14/performing-math-calculation-in-bash/</link>
		<comments>http://www.shell-tips.com/2010/06/14/performing-math-calculation-in-bash/#comments</comments>
		<pubDate>Mon, 14 Jun 2010 08:56:44 +0000</pubDate>
		<dc:creator>Nicolas Brousse</dc:creator>
				<category><![CDATA[Bash - GNU Shell]]></category>
		<category><![CDATA[Common CLI]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[bc]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://www.shell-tips.com/?p=184</guid>
		<description><![CDATA[I use math in bash scripts a lot, from simple crontab reports to Nagios monitoring plugins&#8230; Here is few small examples on how to do some maths in Bash with integers or float. Integer Math First way to do math with integer (and only integer) is to use the command &#8220;expr &#8212; evaluate expression&#8220;. Mac-n-Cheese:~ [...]]]></description>
			<content:encoded><![CDATA[<p>I use math in bash scripts a lot, from simple crontab reports to Nagios monitoring plugins&#8230; Here is few small examples on how to do some maths in Bash with integers or float.</p>
<p><span id="more-184"></span><strong>Integer Math<br />
</strong></p>
<p>First way to do math with integer (and only integer) is to use the command &#8220;<em>expr &#8212; evaluate expression</em>&#8220;.</p>
<pre class="brush:shell">Mac-n-Cheese:~ nicolas$ expr 1 + 1
2
Mac-n-Cheese:~ nicolas$ myvar=$(expr 1 + 1)
Mac-n-Cheese:~ nicolas$ echo $myvar
2
Mac-n-Cheese:~ nicolas$ expr $myvar + 1
3
Mac-n-Cheese:~ nicolas$ expr $myvar / 3
1
Mac-n-Cheese:~ nicolas$ expr $myvar \* 3
9
</pre>
<p>When doing a &#8220;multiply by&#8221; make sure to backslash the &#8220;asterisk&#8221;  as it&#8217;s a wildcard in Bash used for expansion.</p>
<p>Another alternative to <em>expr</em>, is to use the bash builtin command <em>let</em>.</p>
<pre class="brush:shell">Mac-n-Cheese:~ nicolas$ echo $myvar
6
Mac-n-Cheese:~ nicolas$ let myvar+=1
Mac-n-Cheese:~ nicolas$ echo $myvar
7
Mac-n-Cheese:~ nicolas$ let myvar+1
Mac-n-Cheese:~ nicolas$ echo $myvar
7
Mac-n-Cheese:~ nicolas$ let myvar2=myvar+1
Mac-n-Cheese:~ nicolas$ echo $myvar2
8
</pre>
<p>Also, you can simply use the parentheses or square brackets :</p>
<pre class="brush:shell">Mac-n-Cheese:~ nicolas$ echo $myvar
3
Mac-n-Cheese:~ nicolas$ echo $((myvar+2))
5
Mac-n-Cheese:~ nicolas$ echo $[myvar+2]
5
Mac-n-Cheese:~ nicolas$ myvar=$((myvar+3))
</pre>
<p>This allow you to use C-style programming :</p>
<pre class="brush:shell">Mac-n-Cheese:~ nicolas$ echo $myvar
3
Mac-n-Cheese:~ nicolas$ echo $((myvar++))
3
Mac-n-Cheese:~ nicolas$ echo $myvar
4
Mac-n-Cheese:~ nicolas$ echo $((++myvar))
5
Mac-n-Cheese:~ nicolas$ echo $myvar
5
</pre>
<p><strong>Floating point arithmetic</strong></p>
<p>If you need to do floating point arithmetic, you will have to use a command line tool, the most common one is &#8220;<em>bc &#8211; An arbitrary precision calculator language</em>&#8220;.</p>
<pre class="brush:shell">Mac-n-Cheese:~ nicolas$ bc
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
3*5.2+7/8
15.6
15.6+299.33*2.3/7.4
108.6
</pre>
<p>Of course you can use the STDIN to send your formula to &#8220;<em>bc</em>&#8221; then get the output on STDOUT.</p>
<pre class="brush:shell">Mac-n-Cheese:~ nicolas$ echo "3.4+7/8-(5.94*3.14)" | bc
-15.25
</pre>
<p>I encourage you too take a look at the man pages to get more detail on how it works (<em>man bc</em>).</p>
<blockquote><p>There are four special variables, scale, ibase, obase, and last.  scale defines how some operations use digits after the decimal point.  The default value of scale is 0. ibase and obase define the conver-<br />
sion base for input and output numbers.  The default for both input and output is base 10.  last (an extension) is a variable that has the value of the last printed number.</p></blockquote>
<p>The &#8220;scale&#8221; variable is really important for the precision of your results, especially when using integers only (Note: you can also use &#8220;bc -l&#8221; to use mathlib and see the result at max scale) .</p>
<pre class="brush:shell">Mac-n-Cheese:~ nicolas$ echo "2/3" | bc
0
Mac-n-Cheese:~ nicolas$ echo "scale=2; 2/3" | bc
.66
Mac-n-Cheese:~ nicolas$ echo "(2/3)+(7/8)" | bc
0
Mac-n-Cheese:~ nicolas$ echo "scale=2;(2/3)+(7/8)" | bc
1.53
Mac-n-Cheese:~ nicolas$ echo "scale=4;(2/3)+(7/8)" | bc
1.5416
Mac-n-Cheese:~ nicolas$ echo "scale=6;(2/3)+(7/8)" | bc
1.541666
Mac-n-Cheese:~ nicolas$ echo "(2/3)+(7/8)" | bc -l
1.54166666666666666666
</pre>
<p>You can also use the here-doc notation to pass your formula to bc :</p>
<pre class="brush:shell">Mac-n-Cheese:~ nicolas$ bc -l &lt;&lt;&lt; "(2/3)+(7/8)"
1.54166666666666666666
</pre>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fwww.shell-tips.com%2F2010%2F06%2F14%2Fperforming-math-calculation-in-bash%2F&amp;title=Performing+Math+calculation+in+Bash" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fwww.shell-tips.com%2F2010%2F06%2F14%2Fperforming-math-calculation-in-bash%2F&amp;title=Performing+Math+calculation+in+Bash" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.shell-tips.com%2F2010%2F06%2F14%2Fperforming-math-calculation-in-bash%2F&amp;title=Performing+Math+calculation+in+Bash" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fwww.shell-tips.com%2F2010%2F06%2F14%2Fperforming-math-calculation-in-bash%2F&amp;headline=Performing+Math+calculation+in+Bash" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Performing+Math+calculation+in+Bash&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2010%2F06%2F14%2Fperforming-math-calculation-in-bash%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Performing+Math+calculation+in+Bash&amp;u=http%3A%2F%2Fwww.shell-tips.com%2F2010%2F06%2F14%2Fperforming-math-calculation-in-bash%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Performing+Math+calculation+in+Bash&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2010%2F06%2F14%2Fperforming-math-calculation-in-bash%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Performing+Math+calculation+in+Bash&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2010%2F06%2F14%2Fperforming-math-calculation-in-bash%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Performing+Math+calculation+in+Bash&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2010%2F06%2F14%2Fperforming-math-calculation-in-bash%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2010%2F06%2F14%2Fperforming-math-calculation-in-bash%2F&amp;title=Performing+Math+calculation+in+Bash&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.shell-tips.com%2F2010%2F06%2F14%2Fperforming-math-calculation-in-bash%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fwww.shell-tips.com%2F2010%2F06%2F14%2Fperforming-math-calculation-in-bash%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fwww.shell-tips.com%2F2010%2F06%2F14%2Fperforming-math-calculation-in-bash%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.shell-tips.com/2010/06/14/performing-math-calculation-in-bash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Graphing Java JMX Object values with Ganglia and Python using JPype</title>
		<link>http://www.shell-tips.com/2010/05/31/graphing-java-jmx-object-values-with-ganglia-and-python-using-jpype/</link>
		<comments>http://www.shell-tips.com/2010/05/31/graphing-java-jmx-object-values-with-ganglia-and-python-using-jpype/#comments</comments>
		<pubDate>Mon, 31 May 2010 10:00:54 +0000</pubDate>
		<dc:creator>Nicolas Brousse</dc:creator>
				<category><![CDATA[Case Study]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Ganglia]]></category>
		<category><![CDATA[graphing]]></category>
		<category><![CDATA[JMX]]></category>
		<category><![CDATA[JPype]]></category>
		<category><![CDATA[monitoring]]></category>

		<guid isPermaLink="false">http://www.shell-tips.com/?p=157</guid>
		<description><![CDATA[With Ganglia, graphing a large number of servers has never been so easy&#8230; Ganglia is a scalable distributed monitoring system for high-performance computing systems such as clusters and Grids. Ganglia let you create any kind of module in C/C++ or Python. You can also use the command line tool Gmetric and then the scripting language [...]]]></description>
			<content:encoded><![CDATA[<p>With <a title="Ganglia SF.net" href="http://ganglia.sourceforge.net" target="_self">Ganglia</a>, graphing a large number of servers has never been so easy&#8230; <em>Ganglia is a scalable distributed monitoring system for high-performance  computing systems such as clusters and Grids.</em> Ganglia let you create any kind of module in C/C++ or Python. You can also use the command line tool <a title="Gmetric Scripts" href="http://ganglia.sourceforge.net/gmetric" target="_self">Gmetric</a> and then the scripting language of your choice. The problem with Gmetrics is that you can&#8217;t keep your data organized by group and it&#8217;s getting harder to poll values in an efficient way. Few months ago I needed to monitor some <a title="JMX on Wikipedia" href="http://en.wikipedia.org/wiki/Java_Management_Extensions" target="_self">JMX</a> values returned by a Java daemon.</p>
<p><span id="more-157"></span></p>
<p>This post is quite succinct as I consider you already know Ganglia, Python and Java.</p>
<p>To monitor Java JMX values with Ganglia, I used <a title="JPype on SF.net" href="http://jpype.sourceforge.net" target="_self">JPype</a>. <em>JPype is an effort to allow python programs full access to java class libraries.</em> This allowed me to port easily the JMX <a title="Munin Project" href="http://munin-monitoring.org" target="_self">Munin</a> plugin, you can get this plugin on <a title="Munin Exchange" href="http://su.pr/2BxAab" target="_self">Munin Exchange</a>. The port, is really basic as I just converted few method to make sure I can publicly access them from the Python module. You can take a look at the <a href="http://www.shell-tips.com/wp-content/uploads/jmxquery.patch.txt">jmxquery.patch</a> or download <a href="http://www.shell-tips.com/wp-content/uploads/jmxquery.jar_.tar.gz">jmxquery.jar</a>.</p>
<pre class="brush:diff">diff -urBN jmxquery.a/src/jmxquery/src/org/munin/JMXQuery.java jmxquery.b/src/jmxquery/src/org/munin/JMXQuery.java
--- jmxquery.a/src/jmxquery/src/org/munin/JMXQuery.java	2007-05-14 01:07:44.000000000 -0700
+++ jmxquery.b/src/jmxquery/src/org/munin/JMXQuery.java	2010-01-15 15:40:00.000000000 -0800
@@ -61,7 +61,7 @@
 		this.password = password;
 	}

-	private void connect() throws IOException
+	public void connect() throws IOException
 	{
 		Map environment = null;
 		if (username != null &amp;&amp; password != null)
@@ -78,7 +78,18 @@
 		connection = connector.getMBeanServerConnection();
 	}

-	private void list() throws IOException, InstanceNotFoundException, IntrospectionException, ReflectionException
+	public void ping() throws IOException
+	{
+	  try {
+	    MBeanServerConnection testConnection = connector.getMBeanServerConnection();
+	    if (testConnection == null)
+	       this.connect();
+	  } catch (IOException e) {
+	    this.connect();
+	  }
+	}
+
+	public void list() throws IOException, InstanceNotFoundException, IntrospectionException, ReflectionException
 	{
 		if (config == null)
 		{
@@ -90,7 +101,7 @@
 		}
 	}

-	private void listConfig()
+	public void listConfig()
 	{
 		for (FieldProperties field : config.getFields())
 		{
@@ -107,7 +118,22 @@
 		}
 	}

-	private void output(String name, Object attr, String key)
+	public String output(String name, String JmxObjectName, String JmxAttributeName, String Key)
+	{
+    try
+    {
+      Object value = connection.getAttribute(new ObjectName(JmxObjectName), JmxAttributeName);
+      return output(name, value, Key);
+    }
+    catch (Exception e)
+    {
+      System.err.println("Fail to output " + name);
+      e.printStackTrace();
+    }
+    return null;
+	}
+
+	public String output(String name, Object attr, String key)
 	{
 		if (attr instanceof CompositeDataSupport)
 		{
@@ -116,15 +142,17 @@
 			{
 				throw new IllegalArgumentException("Key is null for composed data " + name);
 			}
-			System.out.println(name + ".value " + format(cds.get(key)));
+			//System.out.println(name + ".value " + format(cds.get(key)));
+			return format(cds.get(key));
 		}
 		else
 		{
-			System.out.println(name + ".value " + format(attr));
+			//System.out.println(name + ".value " + format(attr));
+		  return format(attr);
 		}
 	}

-	private void output(String name, Object attr)
+	public void output(String name, Object attr)
 	{
 		if (attr instanceof CompositeDataSupport)
 		{
@@ -142,7 +170,7 @@
 	}

 	@SuppressWarnings("unchecked")
-	private void listAll() throws IOException, InstanceNotFoundException, IntrospectionException, ReflectionException
+	public void listAll() throws IOException, InstanceNotFoundException, IntrospectionException, ReflectionException
 	{
 		Set<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="100" height="100" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><embed type="application/x-shockwave-flash" width="100" height="100"></embed></object></pre>
<p>Once JPype is installed, make sure your Ganglia is configured with the python module.</p>
<pre class="brush:text"># The modules section describes the module
#  that should be loaded.
#   name - module name
#   path - load path of the .so
#   params - path to the directory where mod_python
#             should look for python metric modules
modules {
  module {
    name = "python_module"
    path = "modpython.so"
    params = "/opt/ganglia/python_modules"
  }
}

include ('/opt/ganglia/etc/conf.d/*.pyconf')
</pre>
<p>Then you can use this basic <a href="http://www.shell-tips.com/wp-content/uploads/jmx.py_.txt">jmx python</a> module:</p>
<pre class="brush:python">"""
Ganglia Module to graph JMX values using JPype
Author: Nicolas Brousse
"""
from jpype import *

import os, platform, sys, time

debug = 0

_jmx = None
_jmx_cur_status = {}
_jmx_pre_status = {}
_jmx_pre_time = {}
_eta = 0
_jmx_params = {'User': '',
              'Password': '',
              'Host': '127.0.0.1',
              'Port': '8989',
              'JMXWrapper': '/opt/ganglia/jmxquery.jar'}

descriptors = []

gauge_metrics = {}

def Metric_Handler(name):
    global _jmx

    if _jmx is None:
        _jmx = initJVM()

    pre = None
    cur = 0
    eta = 0

    if debug:
        print "[ DEBUG ] _jmx_cur_status length: %d" % len(_jmx_cur_status)
        print "[ DEBUG ] _jmx_pre_status length: %d" % len(_jmx_pre_status)

    if _jmx is None:
        raise TypeError("No valid JMX Object !")

    if name in _jmx_cur_status:
        _jmx_pre_status[name] = _jmx_cur_status[name]

    for d in descriptors:
        if d['name'] == name:
            break

    try:
        if "jmxKeyName" in d:
            key = d['jmxKeyName']
        else:
            key = None

        if debug:
            print "[ DEBUG ] _jmx.output(%s, %s, %s, %s)" % \
                (d['name'], d['jmxObjectName'], d['jmxAttributeName'], key)

        _jmx.ping()
        result = _jmx.output(d['name'], d['jmxObjectName'], d['jmxAttributeName'], key)
    except:
        print "Error: ", sys.exc_info()[1]
        raise

    if result.isdigit():
        if debug: print "[ DEBUG ] %s: %s" % (name, result)
        _jmx_cur_status[name] = result

        cur_time = time.time()
        if name in _jmx_pre_time:
            eta = cur_time - _jmx_pre_time[name]
            if debug:
                print '[ DEBUG ] ETA: %d, Last time: %d, Cur time: %d' % (eta, _jmx_pre_time[name], cur_time)

        _jmx_pre_time[name] = cur_time

    if name in _jmx_cur_status:
        cur = _jmx_cur_status[name]
    else:
        cur = 0
    if len(_jmx_pre_status) &gt; 0 and name in _jmx_pre_status:
        pre = _jmx_pre_status[name]
    else:
        pre = 0
    eta = int(eta)

    if name in gauge_metrics:
        if pre is not None and eta &gt; 0:
            ret = (long(cur) - long(pre)) / eta
        else:
            ret = 0
    else:
        ret = cur

    if debug:
        print "[ DEBUG ] Metric_Handler(%s): %s (eta: %s, cur: %s, pre: %s)" % (name, ret, eta, cur, pre)

    return long(ret)

def Init_Metric (name, jmxObjectName, jmxAttributeName, jmxKeyName, tmax, type, slope, units, fmt, handler):
    '''Create a metric definition dictionary object.'''
    d = {'name': name.lower(),
        'jmxObjectName': jmxObjectName,
        'jmxAttributeName': jmxAttributeName,
        'jmxKeyName': jmxKeyName,
        'call_back': handler,
        'time_max': tmax,
        'value_type': type,
        'units': units,
        'slope': slope,
        'format': fmt,
        'description': 'JMX '+name.replace("_"," "),
	    'groups': 'jmx'}
    return d

def metric_init(params):
    global _jmx, _jmx_params

    if debug: print "[ DEBUG ] metric_init()"

    if 'User' in params:
        _jmx_params['User'] = params['User']

    if 'Password' in params:
        _jmx_params['Password'] = params['Password']

    if 'Host' in params:
        _jmx_params['Host'] = params['Host']

    if 'Port' in params:
        _jmx_params['Port'] = int(params['Port'])

    if 'JMXWrapper' in params:
        _jmx_params['JMXWrapper'] = params['JMXWrapper']

    return descriptors

def initJVM():
    if debug: print "[ DEBUG ] initJVM()"

    if platform.architecture()[0] == "32bit":
        arch="i386"
    else:
        arch="amd64"

    jvm="/usr/java/jdk/jre/lib/%s/client/libjvm.so" % arch
    if not os.path.isfile(jvm):
        jvm="/usr/java/jdk/jre/lib/%s/server/libjvm.so" % arch
        if not os.path.isfile(jvm):
            raise IOError("Can't find the libjvm.so (%s)" % jvm)

    if not os.path.isfile(_jmx_params['JMXWrapper']):
        raise IOError("Can't find the JMX Wrapper at'%s'" % \
            _jmx_params['JMXWrapper'])

    try:
        startJVM(jvm, "-Djava.class.path=%s" % _jmx_params['JMXWrapper'])

        url = "service:jmx:rmi:///jndi/rmi://%s:%d/jmxrmi" % \
               (_jmx_params['Host'], int(_jmx_params['Port']))

        JMXQuery = JClass("org.munin.JMXQuery")

        if _jmx_params['Password'] is not '':
            _jmx = JMXQuery(url, username, password)
        else:
            _jmx = JMXQuery(url)

        _jmx.connect()
    except:
        print "Error: ", sys.exc_info()[1]
        raise

    return _jmx

def metric_cleanup():
    '''Clean up the metric module.'''
    #shutdownJVM()

def Build_Conf():
    print "modules {\n module {\n  name = \"jmx\"\n  language = \"python\"\n }\n}\n"
    print "collection_group {\n collect_every = 30\n time_threshold = 60"
    for d in descriptors:
        print " metric {\n  name = \""+d['name']+"\"\n  title = \""+d['description']+"\"\n  value_threshold = 1.0\n }"
    print "}\n"

descriptors.append(
    Init_Metric("java_cpu_time", "java.lang:type=Threading", "CurrentThreadCpuTime", "",
        int(300), 'uint', 'both', '', '%u', Metric_Handler))
descriptors.append(
    Init_Metric("java_cpu_user_time", "java.lang:type=Threading", "CurrentThreadUserTime", "",
        int(300), 'uint', 'both', '', '%u', Metric_Handler))
descriptors.append(
    Init_Metric("java_memory_nonheap_committed", "java.lang:type=Memory", "NonHeapMemoryUsage", "committed",
        int(300), 'uint', 'both', '', '%u', Metric_Handler))
descriptors.append(
    Init_Metric("java_memory_nonheap_max", "java.lang:type=Memory", "NonHeapMemoryUsage", "max",
        int(300), 'uint', 'both', '', '%u', Metric_Handler))
descriptors.append(
    Init_Metric("java_memory_nonheap_used", "java.lang:type=Memory", "NonHeapMemoryUsage", "used",
        int(300), 'uint', 'both', '', '%u', Metric_Handler))
descriptors.append(
    Init_Metric("java_memory_heap_committed", "java.lang:type=Memory", "HeapMemoryUsage", "committed",
        int(300), 'uint', 'both', '', '%u', Metric_Handler))
descriptors.append(
    Init_Metric("java_memory_heap_used", "java.lang:type=Memory", "HeapMemoryUsage", "used",
        int(300), 'uint', 'both', '', '%u', Metric_Handler))
descriptors.append(
    Init_Metric("java_memory_heap_max", "java.lang:type=Memory", "HeapMemoryUsage", "max",
        int(300), 'uint', 'both', '', '%u', Metric_Handler))
descriptors.append(
    Init_Metric("os_memory_physical", "java.lang:type=OperatingSystem", "FreePhysicalMemorySize", "",
        int(300), 'uint', 'both', '', '%u', Metric_Handler))
descriptors.append(
    Init_Metric("os_memory_vm", "java.lang:type=OperatingSystem", "CommittedVirtualMemorySize", "",
        int(300), 'uint', 'both', '', '%u', Metric_Handler))
descriptors.append(
    Init_Metric("java_thread_count", "java.lang:type=Threading", "ThreadCount", "",
        int(300), 'uint', 'both', '', '%u', Metric_Handler))
descriptors.append(
    Init_Metric("java_thread_count_peak", "java.lang:type=Threading", "PeakThreadCount", "",
        int(300), 'uint', 'both', '', '%u', Metric_Handler))

#This code is for debugging and unit testing
if __name__ == '__main__':
    try:
        if len(sys.argv) &lt;= 1:
            debug = 1

        metric_init(_jmx_params)

        if len(sys.argv) &lt;= 1:
            while True:
                for d in descriptors:
                    v = d['call_back'](d['name'])
                time.sleep(5)
        elif sys.argv[1] == "config":
            Build_Conf()
            metric_cleanup()

    except KeyboardInterrupt:
        print "Process interrupted."
        if _JMX_WorkerThread.running and not _JMX_WorkerThread.shuttingdown:
            _JMX_WorkerThread.shutdown()
        time.sleep(0.2)
        sys.exit(1)
</pre>
<p>You can simply run &#8220;<em>python jmx.py config</em>&#8221; to generate the jmx.pyconf file. Also, you&#8217;d probably need to edit the plugin to check for your own JMX values. A lot of improvement could be done to this plugin, but all the basics are there and it can give you some awesome graph to monitor your Java application.</p>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fwww.shell-tips.com%2F2010%2F05%2F31%2Fgraphing-java-jmx-object-values-with-ganglia-and-python-using-jpype%2F&amp;title=Graphing+Java+JMX+Object+values+with+Ganglia+and+Python+using+JPype" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fwww.shell-tips.com%2F2010%2F05%2F31%2Fgraphing-java-jmx-object-values-with-ganglia-and-python-using-jpype%2F&amp;title=Graphing+Java+JMX+Object+values+with+Ganglia+and+Python+using+JPype" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.shell-tips.com%2F2010%2F05%2F31%2Fgraphing-java-jmx-object-values-with-ganglia-and-python-using-jpype%2F&amp;title=Graphing+Java+JMX+Object+values+with+Ganglia+and+Python+using+JPype" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fwww.shell-tips.com%2F2010%2F05%2F31%2Fgraphing-java-jmx-object-values-with-ganglia-and-python-using-jpype%2F&amp;headline=Graphing+Java+JMX+Object+values+with+Ganglia+and+Python+using+JPype" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Graphing+Java+JMX+Object+values+with+Ganglia+and+Python+using+JPype&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2010%2F05%2F31%2Fgraphing-java-jmx-object-values-with-ganglia-and-python-using-jpype%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Graphing+Java+JMX+Object+values+with+Ganglia+and+Python+using+JPype&amp;u=http%3A%2F%2Fwww.shell-tips.com%2F2010%2F05%2F31%2Fgraphing-java-jmx-object-values-with-ganglia-and-python-using-jpype%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Graphing+Java+JMX+Object+values+with+Ganglia+and+Python+using+JPype&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2010%2F05%2F31%2Fgraphing-java-jmx-object-values-with-ganglia-and-python-using-jpype%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Graphing+Java+JMX+Object+values+with+Ganglia+and+Python+using+JPype&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2010%2F05%2F31%2Fgraphing-java-jmx-object-values-with-ganglia-and-python-using-jpype%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Graphing+Java+JMX+Object+values+with+Ganglia+and+Python+using+JPype&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2010%2F05%2F31%2Fgraphing-java-jmx-object-values-with-ganglia-and-python-using-jpype%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2010%2F05%2F31%2Fgraphing-java-jmx-object-values-with-ganglia-and-python-using-jpype%2F&amp;title=Graphing+Java+JMX+Object+values+with+Ganglia+and+Python+using+JPype&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.shell-tips.com%2F2010%2F05%2F31%2Fgraphing-java-jmx-object-values-with-ganglia-and-python-using-jpype%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fwww.shell-tips.com%2F2010%2F05%2F31%2Fgraphing-java-jmx-object-values-with-ganglia-and-python-using-jpype%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fwww.shell-tips.com%2F2010%2F05%2F31%2Fgraphing-java-jmx-object-values-with-ganglia-and-python-using-jpype%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.shell-tips.com/2010/05/31/graphing-java-jmx-object-values-with-ganglia-and-python-using-jpype/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash &#8211; How to fix the &#8220;Security sandbox violation: BitmapData.draw&#8221;</title>
		<link>http://www.shell-tips.com/2009/08/30/flash-how-to-fix-the-security-sandbox-violation-bitmapdata-draw/</link>
		<comments>http://www.shell-tips.com/2009/08/30/flash-how-to-fix-the-security-sandbox-violation-bitmapdata-draw/#comments</comments>
		<pubDate>Sun, 30 Aug 2009 01:49:39 +0000</pubDate>
		<dc:creator>Nicolas Brousse</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[BitmapData.draw]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[fms]]></category>
		<category><![CDATA[red5]]></category>
		<category><![CDATA[rtmp]]></category>
		<category><![CDATA[sandbox]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[violation]]></category>
		<category><![CDATA[wowza]]></category>

		<guid isPermaLink="false">http://www.shell-tips.com/?p=85</guid>
		<description><![CDATA[The &#8220;Security sandbox violation&#8221; message is a common problem for any Flash developer who try to do a Snapshot of an RTMP Stream. There was a couple of workaround but they stopped working since Flash Player 9.0.115 as it was considered as a possible bug. So, now how to do a proper snapshot of an [...]]]></description>
			<content:encoded><![CDATA[<p>The &#8220;Security sandbox violation&#8221; message is a common problem for any Flash developer who try to do a Snapshot of an RTMP Stream. There was a couple of workaround but they stopped working since Flash Player 9.0.115 as it was considered as a possible bug. So, now how to do a proper snapshot of an RTMP stream ? The answer is simple but you&#8217;ll need to have the control on the streaming server, whatever it is FMS or Red5.<br />
<span id="more-85"></span><br />
Flash use a non documented part of the <a title="Real-Time Messaging Protocol (RTMP) specification" href="http://www.adobe.com/devnet/rtmp/">RTMP protocol</a>. When the client connect to an RTMP stream, the server send a packet that will indicate to the client if it can allow access to the bitmap data (pixels) or/and the raw audio data.</p>
<div id="attachment_86" class="wp-caption alignnone" style="width: 630px"><a href="http://www.shell-tips.com/wp-content/uploads/10184_screenshot+wireshark.jpg"><img class="size-full wp-image-86 " title="Wireshark - Packet capture RtmpSampleAccess" src="http://www.shell-tips.com/wp-content/uploads/10184_screenshot+wireshark.jpg" alt="Wireshark - Packet capture RtmpSampleAccess" width="620" height="390" /></a><p class="wp-caption-text">Wireshark - Packet capture RtmpSampleAccess</p></div>
<p><strong>Fix with FMS</strong></p>
<p>I think what is working here for FMS is also working for Wowza servers but I never tried. To fix your problem with Flash Media Server, you can add this two simple line of code inside the application.onConnect function :</p>
<pre class="brush:javascript">appClient.audioSampleAccess = "/";
appClient.videoSampleAccess = "/";</pre>
<p>It seem that you can also just edit your application.xml file to add the following inside the Application node :</p>
<pre class="brush:xml">&lt;AudioSampleAccess enabled=”true”&gt;/&lt;/AudioSampleAccess&gt;
&lt;VideoSampleAccess enabled=”true”&gt;/&lt;/VideoSampleAccess&gt;</pre>
<p>Beaware that using &#8220;/&#8221; will allow snapshot on all your streams, you can restrict it accordingly to your needs.</p>
<p><strong>Fix with Red5</strong></p>
<p>On last April I posted a patch to Red5 community that let you handle the problem in the same way that FMS does (Ticket <span style="text-decoration: line-through;"><a title="[Red5] Jira APPSERVER-315" href="http://jira.red5.org/browse/APPSERVER-315">#APPSERVER-315</a></span> <a title="Ticket #498 : Security sandbox violation: BitmapData.draw" href="http://www.red5.org/ticket/498" target="_self">#498</a>). So, to let your client access the stream, you will need to edit the red5-web.xml of your application :</p>
<pre class="brush:xml">&lt;bean id="rtmpSampleAccess" class="org.red5.server.stream.RtmpSampleAccess"&gt;
    &lt;property name="audioAllowed" value="true"/&gt;
    &lt;property name="videoAllowed" value="true"/&gt;
&lt;/bean&gt;</pre>
<p>All the Red5 project is designed to use beans which make this application quite flexible. So, in the same way, you can implement your own class and add every security check you want before allowing the access to your RTMP streams. All you need to do is implementing a new class with the IRtmpSampleAccess interface and create a bean using your class.</p>
<p>Even with those changes, you could still get the error message if the stream buffer is empty. So be sure to use a proper try/catch in your client application and also to listen for the &#8220;NetStatusEvent.NET_STATUS&#8221; event. You can start capturing data when the NET_STATUS event return an event.info.code as &#8220;NetStream.Buffer.Full&#8221; and stop capturing data on &#8220;NetStream.Buffer.Empty&#8221;.</p>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fwww.shell-tips.com%2F2009%2F08%2F30%2Fflash-how-to-fix-the-security-sandbox-violation-bitmapdata-draw%2F&amp;title=Flash+-+How+to+fix+the+%22Security+sandbox+violation%3A+BitmapData.draw%22" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fwww.shell-tips.com%2F2009%2F08%2F30%2Fflash-how-to-fix-the-security-sandbox-violation-bitmapdata-draw%2F&amp;title=Flash+-+How+to+fix+the+%22Security+sandbox+violation%3A+BitmapData.draw%22" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.shell-tips.com%2F2009%2F08%2F30%2Fflash-how-to-fix-the-security-sandbox-violation-bitmapdata-draw%2F&amp;title=Flash+-+How+to+fix+the+%22Security+sandbox+violation%3A+BitmapData.draw%22" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fwww.shell-tips.com%2F2009%2F08%2F30%2Fflash-how-to-fix-the-security-sandbox-violation-bitmapdata-draw%2F&amp;headline=Flash+-+How+to+fix+the+%22Security+sandbox+violation%3A+BitmapData.draw%22" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Flash+-+How+to+fix+the+%22Security+sandbox+violation%3A+BitmapData.draw%22&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2009%2F08%2F30%2Fflash-how-to-fix-the-security-sandbox-violation-bitmapdata-draw%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Flash+-+How+to+fix+the+%22Security+sandbox+violation%3A+BitmapData.draw%22&amp;u=http%3A%2F%2Fwww.shell-tips.com%2F2009%2F08%2F30%2Fflash-how-to-fix-the-security-sandbox-violation-bitmapdata-draw%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Flash+-+How+to+fix+the+%22Security+sandbox+violation%3A+BitmapData.draw%22&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2009%2F08%2F30%2Fflash-how-to-fix-the-security-sandbox-violation-bitmapdata-draw%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Flash+-+How+to+fix+the+%22Security+sandbox+violation%3A+BitmapData.draw%22&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2009%2F08%2F30%2Fflash-how-to-fix-the-security-sandbox-violation-bitmapdata-draw%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Flash+-+How+to+fix+the+%22Security+sandbox+violation%3A+BitmapData.draw%22&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2009%2F08%2F30%2Fflash-how-to-fix-the-security-sandbox-violation-bitmapdata-draw%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2009%2F08%2F30%2Fflash-how-to-fix-the-security-sandbox-violation-bitmapdata-draw%2F&amp;title=Flash+-+How+to+fix+the+%22Security+sandbox+violation%3A+BitmapData.draw%22&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.shell-tips.com%2F2009%2F08%2F30%2Fflash-how-to-fix-the-security-sandbox-violation-bitmapdata-draw%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fwww.shell-tips.com%2F2009%2F08%2F30%2Fflash-how-to-fix-the-security-sandbox-violation-bitmapdata-draw%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fwww.shell-tips.com%2F2009%2F08%2F30%2Fflash-how-to-fix-the-security-sandbox-violation-bitmapdata-draw%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.shell-tips.com/2009/08/30/flash-how-to-fix-the-security-sandbox-violation-bitmapdata-draw/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>MySQL &#8211; Impact of multiple column indexes misuse</title>
		<link>http://www.shell-tips.com/2008/02/13/mysql-impact-of-multiple-column-indexes-misuse/</link>
		<comments>http://www.shell-tips.com/2008/02/13/mysql-impact-of-multiple-column-indexes-misuse/#comments</comments>
		<pubDate>Wed, 13 Feb 2008 11:27:44 +0000</pubDate>
		<dc:creator>Nicolas Brousse</dc:creator>
				<category><![CDATA[Benchmarks]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[full-text search]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.shell-tips.com/2008/02/13/mysql-impact-of-multiple-column-indexes-misuse/</guid>
		<description><![CDATA[Here is a quick picture about the impact of MySQL indexes misuse. At work, our developers made a new release of their search engine using MySQL fulltext indexes, unfortunately they didn&#8217;t implement it correctly. The impact was a huge load on all our database servers. To find the trouble, I had to redirect the SQL [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a quick picture about the impact of MySQL indexes misuse. At work, our developers made a new release of their search engine using <a title="MySQL Fulltext Search" href="http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html">MySQL fulltext indexes</a>, unfortunately they didn&#8217;t implement it correctly. The impact was a huge load on all our database servers. To find the trouble, I had to redirect the SQL search flow to a specific server and check for the slow queries then reproduce it with <a title="MySQL - Optimize query with EXPLAIN" href="http://dev.mysql.com/doc/refman/5.0/en/explain.html">EXPLAIN</a>. Don&#8217;t need a long time to find that the search query did an invalid usage of the fulltext index and the &#8220;Match / Against&#8221; syntax. In fact, the fulltext index was a multiple column fulltext index, in such case you have to specify <strong>ALL</strong> the column present in your index, else the index won&#8217;t be used by MySQL&#8230;</p>
<p align="center"><img title="MySQL - Fulltext Indexes (MATH / AGAINST)" src="/dl/match_against.png" border="0" alt="MySQL - Fulltext Indexes (MATH / AGAINST)" width="738" height="370" /></p>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fwww.shell-tips.com%2F2008%2F02%2F13%2Fmysql-impact-of-multiple-column-indexes-misuse%2F&amp;title=MySQL+-+Impact+of+multiple+column+indexes+misuse" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fwww.shell-tips.com%2F2008%2F02%2F13%2Fmysql-impact-of-multiple-column-indexes-misuse%2F&amp;title=MySQL+-+Impact+of+multiple+column+indexes+misuse" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.shell-tips.com%2F2008%2F02%2F13%2Fmysql-impact-of-multiple-column-indexes-misuse%2F&amp;title=MySQL+-+Impact+of+multiple+column+indexes+misuse" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fwww.shell-tips.com%2F2008%2F02%2F13%2Fmysql-impact-of-multiple-column-indexes-misuse%2F&amp;headline=MySQL+-+Impact+of+multiple+column+indexes+misuse" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=MySQL+-+Impact+of+multiple+column+indexes+misuse&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2008%2F02%2F13%2Fmysql-impact-of-multiple-column-indexes-misuse%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=MySQL+-+Impact+of+multiple+column+indexes+misuse&amp;u=http%3A%2F%2Fwww.shell-tips.com%2F2008%2F02%2F13%2Fmysql-impact-of-multiple-column-indexes-misuse%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=MySQL+-+Impact+of+multiple+column+indexes+misuse&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2008%2F02%2F13%2Fmysql-impact-of-multiple-column-indexes-misuse%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=MySQL+-+Impact+of+multiple+column+indexes+misuse&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2008%2F02%2F13%2Fmysql-impact-of-multiple-column-indexes-misuse%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=MySQL+-+Impact+of+multiple+column+indexes+misuse&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2008%2F02%2F13%2Fmysql-impact-of-multiple-column-indexes-misuse%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2008%2F02%2F13%2Fmysql-impact-of-multiple-column-indexes-misuse%2F&amp;title=MySQL+-+Impact+of+multiple+column+indexes+misuse&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.shell-tips.com%2F2008%2F02%2F13%2Fmysql-impact-of-multiple-column-indexes-misuse%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fwww.shell-tips.com%2F2008%2F02%2F13%2Fmysql-impact-of-multiple-column-indexes-misuse%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fwww.shell-tips.com%2F2008%2F02%2F13%2Fmysql-impact-of-multiple-column-indexes-misuse%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.shell-tips.com/2008/02/13/mysql-impact-of-multiple-column-indexes-misuse/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Printing a sequence of letters or numbers</title>
		<link>http://www.shell-tips.com/2008/01/14/printing-a-sequence-of-letters-or-numbers/</link>
		<comments>http://www.shell-tips.com/2008/01/14/printing-a-sequence-of-letters-or-numbers/#comments</comments>
		<pubDate>Mon, 14 Jan 2008 14:50:07 +0000</pubDate>
		<dc:creator>Nicolas Brousse</dc:creator>
				<category><![CDATA[Bash - GNU Shell]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[number]]></category>
		<category><![CDATA[sequence]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://www.shell-tips.com/2008/01/14/printing-a-sequence-of-letter-or-number/</guid>
		<description><![CDATA[Some times, while scripting in your favorite shell (I mean Bash !! :) you need to print a sequence of letters or numbers. Don&#8217;t write it yourself ! Script it using seq or curly braces ! Print a sequence of number nicolas@macvin:~$ seq 1 10 1 2 3 4 5 6 7 8 9 10 [...]]]></description>
			<content:encoded><![CDATA[<p>Some times, while scripting in your favorite shell (I mean Bash !! :) you need to print a sequence of letters or numbers. Don&#8217;t write it yourself ! Script it using <strong>seq</strong> or <strong>curly braces</strong> !</p>
<p><strong> Print a sequence of number</strong></p>
<pre class="brush:bash">nicolas@macvin:~$ seq 1 10
1 2 3 4 5 6 7 8 9 10
nicolas@macvin:~$ seq 0 2 10
0 2 4 6 8 10
nicolas@macvin:~$ echo {1..10}
1 2 3 4 5 6 7 8 9 10</pre>
<p><strong>Print a sequence of letters</strong></p>
<pre class="brush:bash">nicolas@macvin:~$ echo {a..g}
a b c d e f g</pre>
<p>Hope this will help you while doing a loop or building some hash directories :</p>
<pre class="brush:bash">nicolas@macvin:~$  mkdir -p test/{1..10}/{1..10}</pre>
<p>Enjoy !</p>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fwww.shell-tips.com%2F2008%2F01%2F14%2Fprinting-a-sequence-of-letters-or-numbers%2F&amp;title=Printing+a+sequence+of+letters+or+numbers" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fwww.shell-tips.com%2F2008%2F01%2F14%2Fprinting-a-sequence-of-letters-or-numbers%2F&amp;title=Printing+a+sequence+of+letters+or+numbers" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.shell-tips.com%2F2008%2F01%2F14%2Fprinting-a-sequence-of-letters-or-numbers%2F&amp;title=Printing+a+sequence+of+letters+or+numbers" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fwww.shell-tips.com%2F2008%2F01%2F14%2Fprinting-a-sequence-of-letters-or-numbers%2F&amp;headline=Printing+a+sequence+of+letters+or+numbers" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Printing+a+sequence+of+letters+or+numbers&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2008%2F01%2F14%2Fprinting-a-sequence-of-letters-or-numbers%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Printing+a+sequence+of+letters+or+numbers&amp;u=http%3A%2F%2Fwww.shell-tips.com%2F2008%2F01%2F14%2Fprinting-a-sequence-of-letters-or-numbers%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Printing+a+sequence+of+letters+or+numbers&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2008%2F01%2F14%2Fprinting-a-sequence-of-letters-or-numbers%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Printing+a+sequence+of+letters+or+numbers&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2008%2F01%2F14%2Fprinting-a-sequence-of-letters-or-numbers%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Printing+a+sequence+of+letters+or+numbers&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2008%2F01%2F14%2Fprinting-a-sequence-of-letters-or-numbers%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2008%2F01%2F14%2Fprinting-a-sequence-of-letters-or-numbers%2F&amp;title=Printing+a+sequence+of+letters+or+numbers&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.shell-tips.com%2F2008%2F01%2F14%2Fprinting-a-sequence-of-letters-or-numbers%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fwww.shell-tips.com%2F2008%2F01%2F14%2Fprinting-a-sequence-of-letters-or-numbers%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fwww.shell-tips.com%2F2008%2F01%2F14%2Fprinting-a-sequence-of-letters-or-numbers%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.shell-tips.com/2008/01/14/printing-a-sequence-of-letters-or-numbers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
