<?xml version="1.0" encoding="utf-8" ?>

<rss version="2.0" 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   >
<channel>
    <title>Code in the hole (Entries tagged as linux)</title>
    <link>http://codeinthehole.com/</link>
    <description>David Winterbottom</description>
    <dc:language>en</dc:language>
    <generator>Serendipity 1.3.1 - http://www.s9y.org/</generator>
    
    

<item>
    <title>Monitoring MySQL with Ganglia and gmetric</title>
    <link>http://codeinthehole.com/archives/8-Monitoring-MySQL-with-Ganglia-and-gmetric.html</link>
            <category>Monitoring</category>
    
    <comments>http://codeinthehole.com/archives/8-Monitoring-MySQL-with-Ganglia-and-gmetric.html#comments</comments>
    <wfw:comment>http://codeinthehole.com/wfwcomment.php?cid=8</wfw:comment>

    <slash:comments>4</slash:comments>
    <wfw:commentRss>http://codeinthehole.com/rss.php?version=2.0&amp;type=comments&amp;cid=8</wfw:commentRss>
    

    <author>nospam@example.com (David Winterbottom)</author>
    <content:encoded>
    &lt;div class=&quot;book_cover&quot;&gt;
&lt;a onclick=&quot;javascript: pageTracker._trackPageview(&#039;/extlink/www.amazon.co.uk/gp/product/0596102356?ie=UTF8&amp;amp;tag=codinthehol-21&amp;amp;linkCode=as2&amp;amp;camp=1634&amp;amp;creative=6738&amp;amp;creativeASIN=0596102356&#039;);&quot;  href=&quot;http://www.amazon.co.uk/gp/product/0596102356?ie=UTF8&amp;tag=codinthehol-21&amp;linkCode=as2&amp;camp=1634&amp;creative=6738&amp;creativeASIN=0596102356&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://codeinthehole.com/app/images/books/building-scalable-websites.jpg&quot;&gt;&lt;/a&gt;&lt;img src=&quot;http://www.assoc-amazon.co.uk/e/ir?t=codinthehol-21&amp;l=as2&amp;o=2&amp;a=0596102356&quot; width=&quot;1&quot; height=&quot;1&quot; border=&quot;0&quot; alt=&quot;&quot; style=&quot;border:none !important; margin:0px !important;&quot; /&gt;
&lt;/div&gt;

&lt;p&gt;Following some server monitoring advice from the excellent &#039;Building Scalable Web Sites&#039; by Cal Henderson, I&#039;ve recently been experimenting with &lt;a onclick=&quot;javascript: pageTracker._trackPageview(&#039;/extlink/ganglia.info/&#039;);&quot;  href=&quot;http://ganglia.info/&quot; title=&quot;Ganglia homepage&quot;&gt;Ganglia&lt;/a&gt; on a cluster of servers at &lt;a href=&quot;www.tangentlabs.co.uk&quot; title=&quot;Tangent Labs&quot;&gt;Tangent Labs&lt;/a&gt;.  It has proved to be deeply impressive and has given us a great tool for keeping an eye on how our servers are performing, as well as providing an invaluable diagnostic tool should things go wrong.&lt;/p&gt;

&lt;p&gt;In essence, Ganglia is a distributed monitoring application that allows statistics on a cluster of servers to be aggregated in a single place.  Moreover, an excellent web front-end is also provided to view charts of the statistics being collected.  You can view a &lt;a onclick=&quot;javascript: pageTracker._trackPageview(&#039;/extlink/monitor.millennium.berkeley.edu/&#039;);&quot;  href=&quot;http://monitor.millennium.berkeley.edu/&quot; title=&quot;Live demo of Ganglia&quot;&gt;live demo of the Ganglia monitoring application for the UC Berkeley Millennium Project&lt;/a&gt; which shows exactly what Ganglia can provide.&lt;/p&gt;

&lt;p&gt;Out of the box, Ganglia collects basic server stats on load, memory, CPU, network and disk.  However, what makes it great is that it can be easily extended to collect statistics on anything that you can measure from the command line.  There is a &lt;a onclick=&quot;javascript: pageTracker._trackPageview(&#039;/extlink/ganglia.sourceforge.net/gmetric/&#039;);&quot;  href=&quot;http://ganglia.sourceforge.net/gmetric/&quot; title=&quot;Visit the repository&quot;&gt;repository of user-contributed scripts&lt;/a&gt; although it&#039;s not that extensive.  In this post, I detail a script that can used to feed statistics about MySQL into Ganglia for monitoring - something important to any LAMP-stack application.&lt;/p&gt;&lt;p&gt;A few technical details first: Ganglia utilises three utilities to run each with a distinct responsibility:&lt;/p&gt;

&lt;dl&gt;
&lt;dt&gt;gmond&lt;/dt&gt;&lt;dd&gt;A daemon responsible for collecting monitoring stats and sharing them using XML over TCP.   The gmond daemon runs on all nodes that you want to monitor.&lt;/dd&gt;
&lt;dt&gt;gmetad&lt;/dt&gt;&lt;dd&gt;A daemon responsible for collecting and storing data from other gmetad and gmomd services.  This only needs to be running on a single, central node.&lt;/dd&gt;
&lt;dt&gt;gmetric&lt;/dt&gt;&lt;dd&gt;A command-line application used for using Ganglia to monitor custom metrics.&lt;/dd&gt;
&lt;/dl&gt;
&lt;p&gt;All very simple really - see &lt;a onclick=&quot;javascript: pageTracker._trackPageview(&#039;/extlink/ganglia.wiki.sourceforge.net/ganglia_documents&#039;);&quot;  href=&quot;http://ganglia.wiki.sourceforge.net/ganglia_documents&quot; title=&quot;Ganglia docs&quot;&gt;the docs for the nitty gritty&lt;/a&gt;.  Ok, enough intro - here&#039;s my script for MySQL:&lt;/p&gt;

&lt;p&gt;&amp;raquo; &lt;a href=&quot;http://codeinthehole.com/app/downloads/gmetric-mysql.sh&quot;&gt;gmetric-mysql.sh (3.1kb)&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;It&#039;s written in Bash and uses a temporary file to read the MySQL stats into before parsing and submitting to gmetric.  This is done as many of the MySQL stats of interest are cumulative counts rather than rates (eg SELECTs per second) which are generally of more interest.  Hence, the script estimates the rate of change by dividing the value delta by the timestamp delta.&lt;/p&gt;

&lt;p&gt;To use this script, simply copy it into a convenient location, ensure it is executable and add the following line to your crontab.&lt;/p&gt;
&lt;div class=&quot;bash&quot; style=&quot;text-align: left&quot;&gt;* * * * * /path/to/gmetric-mysql.sh &amp;gt; /dev/null &lt;span style=&quot;color: #cc66cc;&quot;&gt;2&lt;/span&gt;&amp;gt;&amp;amp;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;/div&gt;
&lt;p&gt;As soon as this is done, your Ganglia web front-end should start plotting the new metrics.&lt;/p&gt;
&lt;img src=&quot;http://codeinthehole.com/app/images/ganglia-snapshot.jpeg&quot; alt=&quot;Sample Ganglia charts&quot; /&gt;

 
    </content:encoded>

    <pubDate>Sun, 14 Dec 2008 21:34:00 +0000</pubDate>
    <guid isPermaLink="false">http://codeinthehole.com/archives/8-guid.html</guid>
    <category>bash</category>
<category>ganglia</category>
<category>linux</category>
<category>monitoring</category>
<category>mysql</category>

</item>
<item>
    <title>Monitoring MySQL processes</title>
    <link>http://codeinthehole.com/archives/2-Monitoring-MySQL-processes.html</link>
            <category>Tidbits</category>
    
    <comments>http://codeinthehole.com/archives/2-Monitoring-MySQL-processes.html#comments</comments>
    <wfw:comment>http://codeinthehole.com/wfwcomment.php?cid=2</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://codeinthehole.com/rss.php?version=2.0&amp;type=comments&amp;cid=2</wfw:commentRss>
    

    <author>nospam@example.com (David Winterbottom)</author>
    <content:encoded>
    &lt;p&gt;Just a quick tip on monitoring the queries that mysql is handling on a production site.  You can use the mysqladmin tool to return a list of the processes currently being handled. Combining this with the UNIX watch command allows a real-time monitoring of what&#039;s going on. &lt;/p&gt;
&lt;div class=&quot;bash&quot; style=&quot;text-align: left&quot;&gt;watch -n &lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt; mysqladmin processlist&lt;/div&gt;
&lt;p&gt;The &quot;-n 1&quot; specifies that mysqladmin executes every second.  Depending on your set-up, you may need to specify a mysql user and password:&lt;/p&gt;
&lt;div class=&quot;bash&quot; style=&quot;text-align: left&quot;&gt;watch -n &lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt; mysqladmin --&lt;span style=&quot;color: #0000ff;&quot;&gt;user=&lt;/span&gt;&amp;lt;user&amp;gt; --&lt;span style=&quot;color: #0000ff;&quot;&gt;password=&lt;/span&gt;&amp;lt;password&amp;gt; processlist&lt;/div&gt; 
    </content:encoded>

    <pubDate>Sun, 26 Oct 2008 22:06:00 +0000</pubDate>
    <guid isPermaLink="false">http://codeinthehole.com/archives/2-guid.html</guid>
    <category>bash</category>
<category>linux</category>
<category>mysql</category>

</item>
<item>
    <title>Following log files with tail -f</title>
    <link>http://codeinthehole.com/archives/1-Following-log-files-with-tail-f.html</link>
            <category>Tidbits</category>
    
    <comments>http://codeinthehole.com/archives/1-Following-log-files-with-tail-f.html#comments</comments>
    <wfw:comment>http://codeinthehole.com/wfwcomment.php?cid=1</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://codeinthehole.com/rss.php?version=2.0&amp;type=comments&amp;cid=1</wfw:commentRss>
    

    <author>nospam@example.com (David Winterbottom)</author>
    <content:encoded>
    &lt;p&gt;UNIX is a majestic onion of discovery.  Every day a new layer of understanding can be peeled away to give some new pungent goodness. Today&#039;s was the &#039;follow&#039;
option of the tail command. &lt;/p&gt;
&lt;p&gt;
It&#039;s commonplace to use tail for viewing the recent entries to a log file:&lt;/p&gt;
&lt;div class=&quot;bash&quot; style=&quot;text-align: left&quot;&gt;tail /var/log/apache2/error.log&lt;/div&gt;
&lt;p&gt;Much more useful is set the &#039;follow&#039; option so that, rather than echoing to STDOUT and returning control to the prompt -  tail continues to watch the file in question and echos additional lines to the terminal.  This can be very useful during development - I often leave a terminal open watching the error logs while I develop - so that I can quickly pounce on any errors that pop up.&lt;/p&gt;
&lt;div class=&quot;bash&quot; style=&quot;text-align: left&quot;&gt;tail -f my-app-error.log&lt;/div&gt;
&lt;p&gt;
Return control to the command prompt using CTRL+C (or run as a background process using &amp;).  This can be quite useful for monitoring the error logs of production sites where echoing error messages and warnings to the screen would be unacceptable.
&lt;/p&gt; 
    </content:encoded>

    <pubDate>Wed, 22 Oct 2008 09:03:00 +0000</pubDate>
    <guid isPermaLink="false">http://codeinthehole.com/archives/1-guid.html</guid>
    <category>bash</category>
<category>linux</category>

</item>

</channel>
</rss>