<?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>code.openark.org &#187; mycheckpoint</title>
	<atom:link href="http://code.openark.org/blog/tag/mycheckpoint/feed" rel="self" type="application/rss+xml" />
	<link>http://code.openark.org/blog</link>
	<description>Blog by Shlomi Noach</description>
	<lastBuildDate>Wed, 01 Feb 2012 08:19:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Documentation in SQL: CALL for help()</title>
		<link>http://code.openark.org/blog/mysql/documentation-in-sql-call-for-help</link>
		<comments>http://code.openark.org/blog/mysql/documentation-in-sql-call-for-help#comments</comments>
		<pubDate>Wed, 11 Jan 2012 07:01:54 +0000</pubDate>
		<dc:creator>shlomi</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[common_schema]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[mycheckpoint]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[openark kit]]></category>
		<category><![CDATA[Stored routines]]></category>

		<guid isPermaLink="false">http://code.openark.org/blog/?p=4536</guid>
		<description><![CDATA[Documentation is an important part of any project. On the projects I maintain I put a lot of effort on documentation, and, frankly, the majority of time spent on my projects is on documentation. The matter of keeping the documentation faithful is a topic of interest. I'd like to outline a few documentation bundling possibilities, [...]]]></description>
			<content:encoded><![CDATA[<p>Documentation is an important part of any project. On the projects I maintain I put a lot of effort on documentation, and, frankly, the majority of time spent on my projects is on documentation.</p>
<p>The matter of keeping the documentation faithful is a topic of interest. I'd like to outline a few documentation bundling possibilities, and the present the coming new documentation method for <a href="http://code.google.com/p/common-schema/" rel="nofollow">common_schema</a>. I'll talk about any bundling that is NOT <em>man pages</em>.</p>
<h4>High level: web docs</h4>
<p>This is the initial method of documentation I used for <a title="openark kit" href="../../forge/openark-kit">openark kit</a> and <a title="mycheckpoint" href="../../forge/mycheckpoint">mycheckpoint</a>. It's still valid for <em>mycheckpoint</em>. Documentation is web-based. You need Internet access to read it. It's in HTML format.</p>
<p>Well, not exactly HTML format: I wrote it in WordPress. Yes, it's HTML, but there's a lot of noise around (theme, menus, etc.) which is not strictly part of the documentation.</p>
<p>While this is perhaps the easiest way to go, here's a few drawbacks:<span id="more-4536"></span></p>
<ul>
<li>You're bound to some framework (WordPress in this case)</li>
<li>Docs are split between MySQL database (my underlying WordPRess storage) &amp; WordPress files (themes, style, header, footer etc.)</li>
<li>Documentation is separate from your code - they're just not in the same place</li>
<li>There is no version control over the documentation.</li>
</ul>
<p>The result is a single source of documentation, which applies to whatever version is latest. It's impossible to maintain docs for multiple versions. You must manually synchronize your WordPress updates with code commits (or rather - code release!).</p>
<h4>Mid level: version controlled HTML docs</h4>
<p>I first saw this approach on Baron's <a href="http://www.xaprb.com/blog/2010/09/22/aspersa-gets-a-user-manual/" rel="bookmark">Aspersa gets a user manual</a> post. I loved it: the documentation is HTML, but stored as part of your project's code, in same version control.</p>
<p>This means one can <a href="http://openarkkit.googlecode.com/svn/trunk/openarkkit/doc/html/introduction.html">browse the documentation</a> (<em>openark kit</em> in this example) exactly as it appears in the baseline. Depending on your project hosting, one may be able to do so per version.</p>
<p>The approach has the great benefit of having the docs tightly coupled with the code in terms of development. Before committing code, one updates documentation for that code, then commits/releases both together.</p>
<p>You're also not bound to any development framework. You may edit with <em>vim, emacs, gedit, bluefish, eclipse,</em> ... any tool of your choice. It's all down to plain old text files.</p>
<h4>Mid level #2: documentation bundling</h4>
<p>One thing I started doing with common_schema is to release a doc bundle with the code. So one can download a compressed bundle of all HTML files. That way one is absolutely certain what's the right documentation for revision <strong>178</strong>. There's no effort about it: the docs are already tightly coupled with code versions. Just compress and distribute.</p>
<h4>Low level: documentation coupled with your code</h4>
<p>Perl scripts can be written as Perl modules, in which case they are eligible for using the <em>perldoc</em> convention. You code your documentation within your script itself, as comment. <em>Perldoc</em> can extract the documentation and present in man-like format. Same happens with Python's <em>pydoc</em>. Baron's <a href="http://www.xaprb.com/blog/2011/11/07/when-documentation-is-code/" rel="bookmark">When documentation is code</a> illustrates that approach. <a href="http://www.maatkit.org/">Maatkit</a> (now <em>Percona Toolkit</em>) has been using it for years.</p>
<p>This method has the advantage of having the documentation ready right within your shell. You don't need a browser, nor firewall access. The docs are just there for you in the same environment where you're executing the code.</p>
<h4>SQL Low level: CALL for help()</h4>
<p><em>common_schema</em> is a different type of project. It is merely a schema. There's no Perl nor Python. One imports the schema into one's MySQL server.</p>
<p>What's the low-level approach for this type of code?</p>
<p>For <em>common_schema</em> I use three levels of documentation: the mid-level, where one can <a href="http://common-schema.googlecode.com/svn/trunk/common_schema/doc/html/introduction.html">browse through the versioned docs</a>, the 2nd mid-level, where one can <a href="http://code.google.com/p/common-schema/downloads/list">download bundled documentation</a>, and then a low-level approach: documentation embedded within the code.</p>
<p>MySQL's documentation is also built into the server: see the <strong>help_*</strong> tables within the <strong>mysql</strong> schema. The <em>mysql</em> command line client allows one to access help by supporting the help command, e.g.</p>
<blockquote>
<pre>mysql&gt; help create table;</pre>
</blockquote>
<p>The client intercepts this command (this is not server side command) and searches through the <strong>mysql.help_*</strong> docs.</p>
<p>With <em>common_schema</em>, I don't have control over the client; it's all on server side. But the code being a schema, what with stored routines and tables, it's easy enough to set up documentation.</p>
<p>As of the next version of <em>common_schema</em>, and following MySQL's method, <em>common_schema</em> provides a <strong>help</strong> table:</p>
<blockquote>
<pre>DESC help;
+--------------+-------------+------+-----+---------+-------+
| Field        | Type        | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| topic        | varchar(32) | NO   | PRI | NULL    |       |
| help_message | text        | NO   |     | NULL    |       |
+--------------+-------------+------+-----+---------+-------+</pre>
</blockquote>
<p>And a <strong>help()</strong> procedure, so that you can call for <em>help()</em>. The procedure will look for the best matching document based on your search expression:</p>
<blockquote>
<pre>root@mysql-5.1.51&gt; <strong>CALL help('match');</strong>
<strong>+---------------------------------------</strong>----------------------------------------+
| help                                                                          |
+-------------------------------------------------------------------------------+
|                                                                               |
| NAME                                                                          |
|                                                                               |
| match_grantee(): Match an existing account based on user+host.                |
|                                                                               |
| TYPE                                                                          |
|                                                                               |
| Function                                                                      |
|                                                                               |
| DESCRIPTION                                                                   |
|                                                                               |
| MySQL does not provide with identification of logged in accounts. It only     |
| provides with user + host:port combination within processlist. Alas, these do |
| not directly map to accounts, as MySQL lists the host:port from which the     |
| connection is made, but not the (possibly wildcard) user or host.             |
| This function matches a user+host combination against the known accounts,     |
| using the same matching method as the MySQL server, to detect the account     |
| which MySQL identifies as the one matching. It is similar in essence to       |
| CURRENT_USER(), only it works for all sessions, not just for the current      |
| session.                                                                      |
|                                                                               |
| SYNOPSIS                                                                      |
|                                                                               |
|                                                                               |
|                                                                               |
|        match_grantee(connection_user char(16) CHARSET utf8,                   |
|        connection_host char(70) CHARSET utf8)                                 |
|          RETURNS VARCHAR(100) CHARSET utf8                                    |
|                                                                               |
|                                                                               |
| Input:                                                                        |
|                                                                               |
| * connection_user: user login (e.g. as specified by PROCESSLIST)              |
| * connection_host: login host. May optionally specify port number (e.g.       |
|   webhost:12345), which is discarded by the function. This is to support      |
|   immediate input from as specified by PROCESSLIST.                           |
|                                                                               |
|                                                                               |
| EXAMPLES                                                                      |
|                                                                               |
| Find an account matching the given use+host combination:                      |
|                                                                               |
|                                                                               |
|        mysql&gt; SELECT match_grantee('apps', '192.128.0.1:12345') AS            |
|        grantee;                                                               |
|        +------------+                                                         |
|        | grantee    |                                                         |
|        +------------+                                                         |
|        | 'apps'@'%' |                                                         |
|        +------------+                                                         |
|                                                                               |
|                                                                               |
|                                                                               |
| ENVIRONMENT                                                                   |
|                                                                               |
| MySQL 5.1 or newer                                                            |
|                                                                               |
| SEE ALSO                                                                      |
|                                                                               |
| processlist_grantees                                                          |
|                                                                               |
| AUTHOR                                                                        |
|                                                                               |
| Shlomi Noach                                                                  |
|                                                                               |
+-------------------------------------------------------------------------------+</pre>
</blockquote>
<p>I like HTML for documentation. I think it's a good format, provided you don't start doing funny things. Perhaps <em>TROFF</em> is more suitable; certainly more popular on Unix machines. But I already have everything in HTML. So, what do I do?</p>
<p>My decision was to keep documentation in HTML, and use the handy <em>html2text</em> tool to do the job. And it does it pretty well! The sample you see above is an automated translation of HTML to plain text.</p>
<p>I add a few touches of my own: SELECTing long texts is ugly, whether you do it via "<strong>;</strong>" or "<strong>\G</strong>". The <strong>help()</strong> routine breaks the text by '<strong>\n</strong>', returning a multi row result set. The above sample makes for some <strong>60+</strong> rows, nicely formatted, broken from the original single text appearing in the <strong>help</strong> table.</p>
<p>So now you have an internal help method for <em>common_schema</em>, right where the code is. You don't have to leave the command line client in order to get help.</p>
<p><a href="http://datacharmer.blogspot.com/">Giuseppe</a> offered me the idea for this, even while my own thinking about it was in early stages.</p>
<p>The next version of <em>common_schema</em> will be available in a few weeks. The code is pretty much ready. I just need to work on, ahem..., the documentation.</p>
]]></content:encoded>
			<wfw:commentRss>http://code.openark.org/blog/mysql/documentation-in-sql-call-for-help/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Generating Google line charts with SQL, part II</title>
		<link>http://code.openark.org/blog/mysql/generating-google-line-charts-with-sql-part-ii</link>
		<comments>http://code.openark.org/blog/mysql/generating-google-line-charts-with-sql-part-ii#comments</comments>
		<pubDate>Thu, 03 Mar 2011 07:38:10 +0000</pubDate>
		<dc:creator>shlomi</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Graphs]]></category>
		<category><![CDATA[mycheckpoint]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://code.openark.org/blog/?p=3337</guid>
		<description><![CDATA[This post continues Generating Google line charts with SQL, part I, in pursue of generating time series based image charts. We ended last post with the following chart: http://chart.apis.google.com/chart?cht=lc&#038;chs=400x200&#038;chtt=SQL%20chart&#038;chxt=x,y&#038;chxr=1,-4716.6,5340.0&#038;chd=s:dddddddddeeeeeefffffffffeeeedddcccbbaaZZZYYYXXXXXXXXXYYYZZabbcdeefghhijkkllmmmmmmmmllkkjihgfedcbZYXWVUTSRRQQPPPPQQQRSTUVWXZacdfgijlmnpqrssttuuuttssrqonmkigfdbZXVTSQONMLKJIIIIIIJKLMOPRTVXZbegilnprtvwyz01111110zyxvtrpnkifcaXUSPNLJHFECBBAAABBCEFHJLNQTWZcfilortwy1346789999876420yvspmjfcYVSOL which has a nice curve, and a proper y-legend, but incorrect x-legend and no ticks nor grids. To date, Google Image Charts do not support time-series [...]]]></description>
			<content:encoded><![CDATA[<p>This post continues <a href="http://code.openark.org/blog/mysql/generating-google-line-charts-with-sql-part-i">Generating Google line charts with SQL, part I</a>, in pursue of generating time series based image charts.</p>
<p>We ended last post with the following chart:</p>
<blockquote>
<pre><img class="alignnone" title="Sample SQL Google Chart" src="http://chart.apis.google.com/chart?cht=lc&amp;chs=400x200&amp;chtt=SQL%20chart&amp;chxt=x,y&amp;chxr=1,-4716.6,5340.0&amp;chd=s:dddddddddeeeeeefffffffffeeeedddcccbbaaZZZYYYXXXXXXXXXYYYZZabbcdeefghhijkkllmmmmmmmmllkkjihgfedcbZYXWVUTSRRQQPPPPQQQRSTUVWXZacdfgijlmnpqrssttuuuttssrqonmkigfdbZXVTSQONMLKJIIIIIIJKLMOPRTVXZbegilnprtvwyz01111110zyxvtrpnkifcaXUSPNLJHFECBBAAABBCEFHJLNQTWZcfilortwy1346789999876420yvspmjfcYVSOL" alt="" width="400" height="200" />

http://chart.apis.google.com/chart?cht=lc&#038;chs=400x200&#038;chtt=SQL%20chart&#038;chxt=x,y&#038;chxr=1,-4716.6,5340.0&#038;chd=s:dddddddddeeeeeefffffffffeeeedddcccbbaaZZZYYYXXXXXXXXXYYYZZabbcdeefghhijkkllmmmmmmmmllkkjihgfedcbZYXWVUTSRRQQPPPPQQQRSTUVWXZacdfgijlmnpqrssttuuuttssrqonmkigfdbZXVTSQONMLKJIIIIIIJKLMOPRTVXZbegilnprtvwyz01111110zyxvtrpnkifcaXUSPNLJHFECBBAAABBCEFHJLNQTWZcfilortwy1346789999876420yvspmjfcYVSOL
</pre>
</blockquote>
<p>which has a nice curve, and a proper y-legend, but incorrect x-legend and no ticks nor grids.</p>
<p>To date, Google Image Charts do not support time-series charts. We can't just throw timestamp values and expect the chart to properly position them. We need to work these by hand.</p>
<p>This is not easily done; if our input consists of evenly spread timestamp values, we are in a reasonable position. If not, what do we do?</p>
<p>There are several solutions to this:</p>
<ul>
<li>We can present whatever points we have on the chart, making sure to position them properly. This makes for an uneven distribution of ticks on the x-axis, and is not pleasant to watch.</li>
<li>We can extrapolate values for round hours (or otherwise round timestamp resolutions), and so show evenly spread timestamps. I don't like this solution one bit, since we're essentially inventing values here. Extrapolation is nice when you know you have nice curves, but not when you're doing database monitoring, for example. You must have the precise values.</li>
<li>We can do <a href="http://en.wikipedia.org/wiki/Oversampling">oversampling</a>, then group together several measurements within round timestamp resolutions. For example, we can make a measurement every <strong>2</strong> minutes, yet present only <strong>6</strong> measurements per hour, each averaging up <strong>10</strong> round minutes. This is the approach I take with <a href="http://code.openark.org/forge/mycheckpoint">mycheckpoint</a>.</li>
</ul>
<p>The latest approach goes even beyond that: what if we missed 30 minutes of sampling? Say the server was down. We then need to "invent" the missing timestamps. Note that we invent the timestamps, we do not invent values. We must present the chart with missing values on our invented timestamps.</p>
<p>I may show how to do this in a future post. Meanwhile, let's simplify and assume our values <em>are</em> evenly spread.<span id="more-3337"></span></p>
<h4>Sample data</h4>
<p>We use <a href="http://code.openark.org/blog/wp-content/uploads/2011/03/google_charts.sql_.txt">google_charts.sql</a>. Note that the timestamp values provided in Part I of this post is skewed, so make sure to use this file.</p>
<h4>x-axis values</h4>
<p>We use <strong>chxl</strong> to present with x-axis values. We may be tempted to just list all values. Would that work?</p>
<p>Sadly, no, for two reasons:</p>
<ol>
<li>Google is not smart enough; whatever we throw at it, it will try to present. So, if we have <strong>288</strong> rows, that's <strong>288</strong> x-axis values. Not enough room, to be sure! Smarter implementations would automatically hide some values, so as only to present with non-overlapping values.</li>
<li>Our URL will turn out to be too long. Remember: <strong>2048</strong> characters is our maximum limit for GET request!</li>
</ol>
<p>Also, we must format our timestamp to be of minimal width. In our example, we have a <strong>24</strong> hour range. We therefore present timestamps in hh:MM format. So, a naive approach would be to:</p>
<blockquote>
<pre>SELECT
  CONCAT(
    'http://chart.apis.google.com/chart?cht=lc&amp;chs=400x200&amp;chtt=SQL%20chart&amp;chxt=x,y&amp;chxr=1,',
    ROUND(min_value, 1), ',',
    ROUND(max_value, 1),
    '&amp;chd=s:',
    GROUP_CONCAT(
      IF(
        data IS NULL,
        '_',
        SUBSTRING(
          'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
          1+61*(data - min_value)/(max_value - min_value),
          1
        )
      )
      SEPARATOR ''
    ),
   '&amp;chxl=0:|',
    <strong>GROUP_CONCAT(</strong>
<strong>      DATE_FORMAT(ts, '%H:%i')</strong>
<strong>      SEPARATOR '|'</strong>
<strong>    )</strong>
  ) FROM chart_data, chart_data_minmax</pre>
</blockquote>
<p>The resulting URL is just too long.</p>
<p>Solution? Let's only consider round hour timestamps! Our next attempt looks like this (we also throw in <strong>chxs</strong>, to show ticks):</p>
<blockquote>
<pre>SELECT
  CONCAT(
    'http://chart.apis.google.com/chart?cht=lc&amp;chs=400x200&amp;chtt=SQL%20chart&amp;chxt=x,y&amp;chxr=1,',
    ROUND(min_value, 1), ',',
    ROUND(max_value, 1),
    '&amp;chd=s:',
    GROUP_CONCAT(
      IF(
        data IS NULL,
        '_',
        SUBSTRING(
          'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
          1+61*(data - min_value)/(max_value - min_value),
          1
        )
      )
      SEPARATOR ''
    ),
   <strong>'&amp;chxs=0,505050,10,0,lt',</strong>
<strong>   '&amp;chxl=0:|',</strong>
<strong>    GROUP_CONCAT(</strong>
<strong>      IF(</strong>
<strong>        MINUTE(ts) = 0,</strong>
<strong>        DATE_FORMAT(ts, '%H:%i'),</strong>
<strong>        NULL</strong>
<strong>      )</strong>
<strong>      SEPARATOR '|'</strong>
<strong>    )</strong>
  ) FROM chart_data, chart_data_minmax
</pre>
</blockquote>
<p>and results with:</p>
<blockquote>
<pre><img class="alignnone" title="SQL line chart" src="http://chart.apis.google.com/chart?cht=lc&amp;chs=400x200&amp;chtt=SQL%20chart&amp;chxt=x,y&amp;chxr=1,-4716.6,5340.0&amp;chd=s:dddddddddeeeeeefffffffffeeeedddcccbbaaZZZYYYXXXXXXXXXYYYZZabbcdeefghhijkkllmmmmmmmmllkkjihgfedcbZYXWVUTSRRQQPPPPQQQRSTUVWXZacdfgijlmnpqrssttuuuttssrqonmkigfdbZXVTSQONMLKJIIIIIIJKLMOPRTVXZbegilnprtvwyz01111110zyxvtrpnkifcaXUSPNLJHFECBBAAABBCEFHJLNQTWZcfilortwy1346789999876420yvspmjfcYVSOL&amp;chxs=0,505050,10,0,lt&amp;chxl=0:|00:00|01:00|02:00|03:00|04:00|05:00|06:00|07:00|08:00|09:00|10:00|11:00|12:00|13:00|14:00|15:00|16:00|17:00|18:00|19:00|20:00|21:00|22:00|23:00" alt="" width="400" height="200" />

http://chart.apis.google.com/chart?cht=lc&#038;chs=400x200&#038;chtt=SQL%20chart&#038;chxt=x,y&#038;chxr=1,-4716.6,5340.0&#038;chd=s:dddddddddeeeeeefffffffffeeeedddcccbbaaZZZYYYXXXXXXXXXYYYZZabbcdeefghhijkkllmmmmmmmmllkkjihgfedcbZYXWVUTSRRQQPPPPQQQRSTUVWXZacdfgijlmnpqrssttuuuttssrqonmkigfdbZXVTSQONMLKJIIIIIIJKLMOPRTVXZbegilnprtvwyz01111110zyxvtrpnkifcaXUSPNLJHFECBBAAABBCEFHJLNQTWZcfilortwy1346789999876420yvspmjfcYVSOL&#038;chxs=0,505050,10,0,lt&#038;chxl=0:|00:00|01:00|02:00|03:00|04:00|05:00|06:00|07:00|08:00|09:00|10:00|11:00|12:00|13:00|14:00|15:00|16:00|17:00|18:00|19:00|20:00|21:00|22:00|23:00</pre>
</blockquote>
<p>Too messy, isn't it?</p>
<h4>A word about ticks</h4>
<p>You would think: OK, then, let's just present every <strong>4</strong> round hours timestamps. But there's a catch: a tick will show only when there's an x-axis value. It's nice to have a tick for every hour, but we only want to present values every <strong>4</strong> hours.</p>
<p>Fortunately, we can provide with an unseen value: a space (URL encoded as '<strong>+</strong>'). So we complicate things up a bit on the <strong>chxl</strong> to read:</p>
<blockquote>
<pre>SELECT
  CONCAT(
    'http://chart.apis.google.com/chart?cht=lc&amp;chs=400x200&amp;chtt=SQL%20chart&amp;chxt=x,y&amp;chxr=1,',
    ROUND(min_value, 1), ',',
    ROUND(max_value, 1),
    '&amp;chd=s:',
    GROUP_CONCAT(
      IF(
        data IS NULL,
        '_',
        SUBSTRING(
          'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
          1+61*(data - min_value)/(max_value - min_value),
          1
        )
      )
      SEPARATOR ''
    ),
   '&amp;chxs=0,505050,10,0,lt',
   '&amp;chxl=0:|',
    <strong>GROUP_CONCAT(</strong>
<strong>      IF(</strong>
<strong>        MINUTE(ts) = 0,</strong>
<strong>        IF(</strong>
<strong>          HOUR(ts) MOD 4 = 0,</strong>
<strong>          DATE_FORMAT(ts, '%H:%i'),</strong>
<strong>          '+'</strong>
<strong>        ),</strong>
<strong>        NULL</strong>
<strong>      )</strong>
<strong>      SEPARATOR '|'</strong>
<strong>    )</strong>
  ) FROM chart_data, chart_data_minmax</pre>
</blockquote>
<p>and get:</p>
<blockquote>
<pre><img class="alignnone" title="SQL line chart" src="http://chart.apis.google.com/chart?cht=lc&amp;chs=400x200&amp;chtt=SQL%20chart&amp;chxt=x,y&amp;chxr=1,-4716.6,5340.0&amp;chd=s:dddddddddeeeeeefffffffffeeeedddcccbbaaZZZYYYXXXXXXXXXYYYZZabbcdeefghhijkkllmmmmmmmmllkkjihgfedcbZYXWVUTSRRQQPPPPQQQRSTUVWXZacdfgijlmnpqrssttuuuttssrqonmkigfdbZXVTSQONMLKJIIIIIIJKLMOPRTVXZbegilnprtvwyz01111110zyxvtrpnkifcaXUSPNLJHFECBBAAABBCEFHJLNQTWZcfilortwy1346789999876420yvspmjfcYVSOL&amp;chxs=0,505050,10,0,lt&amp;chxl=0:|00:00|+|+|+|04:00|+|+|+|08:00|+|+|+|12:00|+|+|+|16:00|+|+|+|20:00|+|+|+" alt="" width="400" height="200" />

http://chart.apis.google.com/chart?cht=lc&#038;chs=400x200&#038;chtt=SQL%20chart&#038;chxt=x,y&#038;chxr=1,-4716.6,5340.0&#038;chd=s:dddddddddeeeeeefffffffffeeeedddcccbbaaZZZYYYXXXXXXXXXYYYZZabbcdeefghhijkkllmmmmmmmmllkkjihgfedcbZYXWVUTSRRQQPPPPQQQRSTUVWXZacdfgijlmnpqrssttuuuttssrqonmkigfdbZXVTSQONMLKJIIIIIIJKLMOPRTVXZbegilnprtvwyz01111110zyxvtrpnkifcaXUSPNLJHFECBBAAABBCEFHJLNQTWZcfilortwy1346789999876420yvspmjfcYVSOL&#038;chxs=0,505050,10,0,lt&#038;chxl=0:|00:00|+|+|+|04:00|+|+|+|08:00|+|+|+|12:00|+|+|+|16:00|+|+|+|20:00|+|+|+
</pre>
</blockquote>
<h4>OK, I cheated</h4>
<p>Who says sample data starts with a round hour? We have that hidden assumption here, since the first tick is necessarily a round hour in our code. Yet our data may start at <strong>12:35</strong>, for example. Sorry, you'll have to dig into <a href="http://code.google.com/p/mycheckpoint/source/browse/trunk/src/mycheckpoint.py">mycheckpoint's source code</a> to see a thorough solution. It's just too much for this post.</p>
<h4>Grids</h4>
<p>Let's wrap this up with grids. Grids work by specifying the step size (in percent of overall height/width) and initial offset (again, in percent).</p>
<p>Wouldn't it be nicer if grids were automatically attached to ticks? I mean, REALLY! What were those guys thinking? (I know, they're doing great work. Keep it up!)</p>
<p>Problem is, I have no idea how Google chooses to distribute values on the y-axis. I don't know where y-axis ticks will be placed. So on y-axis, I just choose to split charts to <strong>4</strong> even parts, and draw horizontal grids between them. Percent is <strong>25</strong> (<strong>100/4</strong>), offset is <strong>0</strong>.</p>
<p>But I do have control over the x-axis. In our case, I know how many ticks we'll be having. Plus, I made life easier by assuming we start with a round hour, so no offset is required.</p>
<p>Umm... How many ticks do we have? Easy: the number of round hours. This can be calculated by: <strong>SUM(MINUTE(ts) = 0</strong>. Actually, we need to take <strong>1</strong> off.</p>
<p>We now build the <a href="http://code.google.com/apis/chart/docs/chart_params.html#gcharts_grid_lines"><strong>chg</strong></a> parameter:</p>
<blockquote>
<pre>SELECT
  CONCAT(
    'http://chart.apis.google.com/chart?cht=lc&amp;chs=400x200&amp;chtt=SQL%20chart&amp;chxt=x,y&amp;chxr=1,',
    ROUND(min_value, 1), ',',
    ROUND(max_value, 1),
    '&amp;chd=s:',
    GROUP_CONCAT(
      IF(
        data IS NULL,
        '_',
        SUBSTRING(
          'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
          1+61*(data - min_value)/(max_value - min_value),
          1
        )
      )
      SEPARATOR ''
    ),
   '&amp;chxs=0,505050,10,0,lt',
   '&amp;chxl=0:|',
    GROUP_CONCAT(
      IF(
        MINUTE(ts) = 0,
        IF(
          HOUR(ts) MOD 4 = 0,
          DATE_FORMAT(ts, '%H:%i'),
          '+'
        ),
        NULL
      )
      SEPARATOR '|'
    ),
   <strong>'&amp;chg=', ROUND(100.0/((SUM(MINUTE(ts) = 0) -1)), 2), ',25,1,2,0,0'</strong>
  ) FROM chart_data, chart_data_minmax
</pre>
</blockquote>
<p>and get:</p>
<blockquote>
<pre><img class="alignnone" title="SQL line chart" src="http://chart.apis.google.com/chart?cht=lc&amp;chs=400x200&amp;chtt=SQL%20chart&amp;chxt=x,y&amp;chxr=1,-4716.6,5340.0&amp;chd=s:dddddddddeeeeeefffffffffeeeedddcccbbaaZZZYYYXXXXXXXXXYYYZZabbcdeefghhijkkllmmmmmmmmllkkjihgfedcbZYXWVUTSRRQQPPPPQQQRSTUVWXZacdfgijlmnpqrssttuuuttssrqonmkigfdbZXVTSQONMLKJIIIIIIJKLMOPRTVXZbegilnprtvwyz01111110zyxvtrpnkifcaXUSPNLJHFECBBAAABBCEFHJLNQTWZcfilortwy1346789999876420yvspmjfcYVSOL&amp;chxs=0,505050,10,0,lt&amp;chxl=0:|00:00|+|+|+|04:00|+|+|+|08:00|+|+|+|12:00|+|+|+|16:00|+|+|+|20:00|+|+|+&amp;chg=4.35,25,1,2,0,0" alt="" width="400" height="200" />

http://chart.apis.google.com/chart?cht=lc&#038;chs=400x200&#038;chtt=SQL%20chart&#038;chxt=x,y&#038;chxr=1,-4716.6,5340.0&#038;chd=s:dddddddddeeeeeefffffffffeeeedddcccbbaaZZZYYYXXXXXXXXXYYYZZabbcdeefghhijkkllmmmmmmmmllkkjihgfedcbZYXWVUTSRRQQPPPPQQQRSTUVWXZacdfgijlmnpqrssttuuuttssrqonmkigfdbZXVTSQONMLKJIIIIIIJKLMOPRTVXZbegilnprtvwyz01111110zyxvtrpnkifcaXUSPNLJHFECBBAAABBCEFHJLNQTWZcfilortwy1346789999876420yvspmjfcYVSOL&#038;chxs=0,505050,10,0,lt&#038;chxl=0:|00:00|+|+|+|04:00|+|+|+|08:00|+|+|+|12:00|+|+|+|16:00|+|+|+|20:00|+|+|+&#038;chg=4.35,25,1,2,0,0
</pre>
</blockquote>
<p>Phew!</p>
<h4>Conclusion</h4>
<p>So we haven't worked on offsets. And, this is a single line chart. What about multiple lines? Legend? The following chart:</p>
<blockquote>
<pre><img class="alignnone" title="SQL multi line chart" src="http://chart.apis.google.com/chart?cht=lc&amp;chs=370x180&amp;chts=303030,12&amp;chtt=Latest+24+hours:+Nov+9,+05:50++-++Nov+10,+05:50&amp;chf=c,s,ffffff&amp;chdl=com_select_psec|com_insert_psec|com_delete_psec|com_update_psec|com_replace_psec&amp;chdlp=b&amp;chco=ff8c00,4682b4,9acd32,dc143c,9932cc&amp;chd=s:RTOSRORPNSSORROQTNQQMQRPQSOMUMPQOQUNRUQPUPSRQPUPSTRPQPPQQQQPPURPSQKUQPUQPUTPUQRUTRSRRWTRURRUPQUQSWTSUSOUURTRUTSPSRPPRMRRPRROQSNPQNPPSSRMQPQPQNRQV,MMMRQMPMNPOLOLLORLPOLQSLPRNNUNNQOPSNOQMNRNNPNMRMOQNNNOMNNLOPLPNNOOJPMMOOKRTMPONQNNQOLOMLOMLOKPXNMPMOOMKNNMPNMY976eMMRNQOOMKLOMKLKMMNKMOIPRJPMJMNK,EEDEEDEEDEFEEEDEFEEEDEFEEFEDEEEFEEEEEFEEEFEFEEFEEFEDEEEFEEEEEFEEEEEEFFEFFFEEEFFFFEEEFFFEEEEFDEEEEFFEEEEEFEEFFPx0xXFEEDEFEEEDEFEEEDEFEEEDEEDEEDEFF,FFEFFEFEEFFEFEEFFEFFEFGDEFDEFDEFEEGEEFEEFEEFEEFEEFEEEEEFEEFFDFEEFFDFEEFFEFEEFEEFEEFFDFEEFEDFEEFEEFDEFEDFEEFFENGDFEEFEEFEEFEEFFEFEEEFEFEEEFDFEEFGE,AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA&amp;chxt=x,y&amp;chxr=1,0,356.830000&amp;chxl=0:|+||08:00||+||12:00||+||16:00||+||20:00||+||00:00||+||04:00||&amp;chxs=0,505050,10,0,lt&amp;chg=4.17,25,1,2,0.69,0&amp;chxp=0,0.69,4.86,9.03,13.20,17.37,21.54,25.71,29.88,34.05,38.22,42.39,46.56,50.73,54.90,59.07,63.24,67.41,71.58,75.75,79.92,84.09,88.26,92.43,96.60&amp;tsstart=2010-11-09+05:50:00&amp;tsstep=600" alt="" width="370" height="180" />
</pre>
</blockquote>
<p>is harder to achieve. I'm leaving this up to you!</p>
]]></content:encoded>
			<wfw:commentRss>http://code.openark.org/blog/mysql/generating-google-line-charts-with-sql-part-ii/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Generating Google line charts with SQL, part I</title>
		<link>http://code.openark.org/blog/mysql/generating-google-line-charts-with-sql-part-i</link>
		<comments>http://code.openark.org/blog/mysql/generating-google-line-charts-with-sql-part-i#comments</comments>
		<pubDate>Tue, 01 Feb 2011 08:29:31 +0000</pubDate>
		<dc:creator>shlomi</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Graphs]]></category>
		<category><![CDATA[mycheckpoint]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://code.openark.org/blog/?p=1468</guid>
		<description><![CDATA[In this series of posts I wish to show how Google Charts can be generated via SQL. We discuss the Google Charts limitations which must be challenged, and work towards a simple chart. I'm going to present the algorithm I use in mycheckpoint, a MySQL monitoring utility, which generates Google charts by raw data using [...]]]></description>
			<content:encoded><![CDATA[<p>In this series of posts I wish to show how <a href="http://code.google.com/apis/chart/image_charts.html">Google Charts</a> can be generated via SQL. We discuss the Google Charts limitations which must be challenged, and work towards a simple chart.</p>
<p>I'm going to present the algorithm I use in <a href="http://code.openark.org/forge/mycheckpoint">mycheckpoint</a>, a MySQL monitoring utility, which generates Google charts by raw data using views. An example of such chart follows:</p>
<blockquote>
<pre><img class="alignnone" title="Sample Google Chart" src="http://chart.apis.google.com/chart?cht=lc&amp;chs=370x180&amp;chts=303030,12&amp;chtt=Latest+24+hours:+Nov+9,+05:50++-++Nov+10,+05:50&amp;chf=c,s,ffffff&amp;chdl=Rentals+rate:+custom_1_psec&amp;chdlp=b&amp;chco=ff8c00&amp;chd=s:GDGKGFLFGMJHRLMPPNULJRPLTOPRUMYPPVRNbQUSUSbSNWUOfSWTObVSUVWSVYVPbTPjfTbRTdXReUWhcTQRQZbTWYVYPaVZXdYYWPTabYUTbW99QLgLNIOIRNNMIKRJEHGFHGJGGFIFDFGDK&amp;chxt=x,y&amp;chxr=1,0,8.720000&amp;chxl=0:|+||08:00||+||12:00||+||16:00||+||20:00||+||00:00||+||04:00||&amp;chxs=0,505050,10,0,lt&amp;chg=4.17,25,1,2,0.69,0&amp;chxp=0,0.69,4.86,9.03,13.20,17.37,21.54,25.71,29.88,34.05,38.22,42.39,46.56,50.73,54.90,59.07,63.24,67.41,71.58,75.75,79.92,84.09,88.26,92.43,96.60&amp;tsstart=2010-11-09+05:50:00&amp;tsstep=600" alt="" width="370" height="180" />

http://chart.apis.google.com/chart?cht=lc&#038;chs=370x180&#038;chts=303030,12&#038;chtt=Latest+24+hours:+Nov+9,+05:50++-++Nov+10,+05:50&#038;chf=c,s,ffffff&#038;chdl=Rentals+rate:+custom_1_psec&#038;chdlp=b&#038;chco=ff8c00&#038;chd=s:GDGKGFLFGMJHRLMPPNULJRPLTOPRUMYPPVRNbQUSUSbSNWUOfSWTObVSUVWSVYVPbTPjfTbRTdXReUWhcTQRQZbTWYVYPaVZXdYYWPTabYUTbW99QLgLNIOIRNNMIKRJEHGFHGJGGFIFDFGDK&#038;chxt=x,y&#038;chxr=1,0,8.720000&#038;chxl=0:|+||08:00||+||12:00||+||16:00||+||20:00||+||00:00||+||04:00||&#038;chxs=0,505050,10,0,lt&#038;chg=4.17,25,1,2,0.69,0&#038;chxp=0,0.69,4.86,9.03,13.20,17.37,21.54,25.71,29.88,34.05,38.22,42.39,46.56,50.73,54.90,59.07,63.24,67.41,71.58,75.75,79.92,84.09,88.26,92.43,96.60&#038;tsstart=2010-11-09+05:50:00&#038;tsstep=600</pre>
</blockquote>
<p><em>mycheckpoint</em> does not actually call on Google to do the chart rendering, but invokes its own JavaScript code to visualize the URL locally.</p>
<p>Here are some downsides for using Google charts:</p>
<ul>
<li>The URL cannot be as long as you like. 2048 characters is an upper bound you'll want to keep behind. <em>[Google charts POST method calls are available, which leads to 16K equivalent of URL length -- this is still not too helpful due to the nature of POST calls]</em></li>
<li>Features are inconsistent. To specify label or tick positions, one must specify exact positions. To specify grid positions, one must supply with step, offset, etc. There are more such inconsistencies.</li>
<li>Google charts are not too friendly. Taking the ticks and grids example from above, there really shouldn't be a reason why grids would not be automatically generated according to ticks definitions. But we are required to specify positions for the ticks as well as for the grids.</li>
<li>There is no support for time-series. One must translate time as x-axis values.</li>
<li>Perhaps most intimidating to many people: to generate a Google chart, once must send data to Google. Which is the main reason I used local JavaScript rendering.</li>
</ul>
<p>Anyway, let's build a very simple chart. Since I will not cover everything in this post, we make for some relaxed conditions.<span id="more-1468"></span></p>
<h4>Sample data</h4>
<p>Consider the chart_data table, below:</p>
<blockquote>
<pre>SELECT * FROM chart_data;
+-----+---------------------+-------------------+
| id  | ts                  | data              |
+-----+---------------------+-------------------+
|   1 | 2011-02-01 09:59:15 |  1.99666833293656 |
|   2 | 2011-02-01 09:59:15 |  7.94677323180245 |
|   3 | 2011-02-01 09:59:15 |  17.7312123996804 |
|   4 | 2011-02-01 09:59:15 |   31.153467384692 |
|   5 | 2011-02-01 09:59:15 |  47.9425538604203 |
|   6 | 2011-02-01 09:59:15 |  67.7570968074042 |
|   7 | 2011-02-01 09:59:15 |  90.1904762132767 |
|   8 | 2011-02-01 09:59:15 |  114.776974543924 |
|   9 | 2011-02-01 09:59:15 |  140.998843732947 |
|  10 | 2011-02-01 09:59:15 |  168.294196961579 |
|  11 | 2011-02-01 09:59:15 |  196.065619213516 |
|  12 | 2011-02-01 09:59:15 |  223.689380632134 |
|  13 | 2011-02-01 09:59:15 |   250.52512820847 |
...</pre>
</blockquote>
<p>Find complete SQL script in <a href="http://code.openark.org/blog/wp-content/uploads/2011/02/google_charts.sql_.txt">google_charts.sql</a></p>
<p>In the above table we assume the timestamp values are evenly distributed. This is because of the aforementioned fact that Google Charts do not support time-series. So, if the given timnestamps are not evenly distributed, or maybe some values are skipped, we must manually compensate for that. In <em>mycheckpoint</em> I do that. In this blog post, we skip it.</p>
<h4>Axis boundaries</h4>
<p>By default, Google Charts expect data to lie within the range 0..100. We need to reset the scale to match our minimum/maximum values, and lay out our values within that range.</p>
<p>We will be using views in this solution, and here is the first view:</p>
<blockquote>
<pre>CREATE OR REPLACE VIEW
 chart_data_minmax
AS
 SELECT MIN(data) AS min_value, MAX(data) AS max_value
FROM
 chart_data
;</pre>
</blockquote>
<p>In our example we will just settle with the min/max values. In real worlds we may:</p>
<ul>
<li>Choose <strong>0</strong> to be the lower value, even if the minimal value is positive</li>
<li>Choose to round min-max values to a nearest power of <strong>10</strong>.</li>
</ul>
<p>The axis boundaries go under the following parameters:</p>
<ul>
<li><strong>chxt=x,y</strong> (we hard code bottom axis, left axis)</li>
<li><strong>chxr=1,<em>min</em>,<em>max</em></strong> (with min, max as computed by the above)</li>
</ul>
<p>The following query produces these params:</p>
<blockquote>
<pre>SELECT CONCAT('&amp;chxt=x,y&amp;chxr=1,', ROUND(min_value, 1), ',', ROUND(max_value, 1)) AS minmax FROM chart_data_minmax;
+---------------------------------+
| minmax                          |
+---------------------------------+
| &amp;chxt=x,y&amp;chxr=1,-4716.6,5340.0 |
+---------------------------------+
</pre>
</blockquote>
<h3>Data values</h3>
<p>Next, we have some <strong>244</strong> rows of data. Data is double. Can we be certain this all fits within <strong>2048</strong> characters? What if we had more rows?</p>
<p>Alas, we must make a trade-off. We will sacrifice accuracy in favor of a short URL. We will use <a href="http://code.google.com/apis/chart/docs/data_formats.html#simple">simple encoding</a> for our data. This means just one character per value, encoded <strong>A-Za-z0-9</strong>. This means just <strong>62</strong> distinct values.</p>
<p>So we must translate each data value into the range 0..61, and then into a character. First step is:</p>
<blockquote>
<pre>SELECT (data - min_value)/(max_value - min_value) AS range_01 FROM chart_data, chart_data_minmax;
+---------------------+
| range_01            |
+---------------------+
|   0.469204617275163 |
|   0.469796281944551 |
|   0.470769223945374 |
|   0.472103901937297 |
|   0.473773369865649 |
|   0.475743682188048 |
|   0.477974405550919 |
...
</pre>
</blockquote>
<p>The above translates the data into the 0..1 range. Next is to simply multiply by 61:</p>
<blockquote>
<pre>SELECT 61*(data - min_value)/(max_value - min_value) AS range_0_61 FROM chart_data, chart_data_minmax;
+-------------------+
| range_0_61        |
+-------------------+
|  28.6214816537849 |
|  28.6575731986176 |
|  28.7169226606678 |
|  28.7983380181751 |
|  28.9001755618046 |
|  29.0203646134709 |
|  29.1564387386061 |
|  29.3055730348683 |
|  29.4646269983728 |
|  29.6301923928522 |
...</pre>
</blockquote>
<p>To translate into a <em>simple format</em> character we parse a constant string:</p>
<blockquote>
<pre>SELECT
  SUBSTRING(
    'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
    1+61*(data - min_value)/(max_value - min_value),
    1
  ) AS c FROM chart_data, chart_data_minmax;
+------+
| c    |
+------+
| d    |
| d    |
| d    |
| d    |
| d    |
| d    |
| d    |
| d    |
| d    |
| e    |
| e    |
...</pre>
</blockquote>
<p>Oh, and we should handle NULLs, as well, so:</p>
<blockquote>
<pre>SELECT
  IF(
    data IS NULL,
    '_',
    SUBSTRING(
      'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
      1+61*(data - min_value)/(max_value - min_value),
      1
    )
  ) AS c FROM chart_data, chart_data_minmax;
</pre>
<pre>+------+
| c    |
+------+
| d    |
| d    |
| d    |
| d    |
| d    |
| d    |
| d    |
| d    |
| d    |
| e    |
| e    |
...</pre>
</blockquote>
<p>And, to present it as a char sequence, we use the <strong>chd</strong> parameter and call <strong>GROUP_CONCAT</strong> to the rescue:</p>
<blockquote>
<pre>SELECT
  CONCAT('&amp;chd=s:',
    GROUP_CONCAT(
      IF(
        data IS NULL,
        '_',
        SUBSTRING(
          'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
          1+61*(data - min_value)/(max_value - min_value),
          1
        )
      )
      SEPARATOR ''
    )
  ) AS c FROM chart_data, chart_data_minmax
\G
*************************** 1. row ***************************
c: &amp;chd=s:dddddddddeeeeeefffffffffeeeedddcccbbaaZZZYYYXXXXXXXXXYYYZZabbcdeefghhijkkllmmmmmmmmllkkjihgfedcbZYXWVUTSRRQQPPPPQQQRSTUVWXZacdfgijlmnpqrssttuuuttssrqonmkigfdbZXVTSQONMLKJIIIIIIJKLMOPRTVXZbegilnprtvwyz01111110zyxvtrpnkifcaXUSPNLJHFECBBAAABBCEFHJLNQTWZcfilortwy1346789999876420yvspmjfcYVSOL</pre>
</blockquote>
<h4>Wrap up</h4>
<p>Combining the above two queries, with some URL necessities, we get:</p>
<blockquote>
<pre>SELECT
  CONCAT(
    'http://chart.apis.google.com/chart?cht=lc&amp;chs=400x200&amp;chtt=SQL%20chart&amp;chxt=x,y&amp;chxr=1,',
    ROUND(min_value, 1), ',',
    ROUND(max_value, 1),
    '&amp;chd=s:',
    GROUP_CONCAT(
      IF(
        data IS NULL,
        '_',
        SUBSTRING(
          'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
          1+61*(data - min_value)/(max_value - min_value),
          1
        )
      )
      SEPARATOR ''
    )
  ) FROM chart_data, chart_data_minmax
;
</pre>
</blockquote>
<p>And get:</p>
<blockquote>
<pre><img class="alignnone" title="Sample SQL Google Chart" src="http://chart.apis.google.com/chart?cht=lc&amp;chs=400x200&amp;chtt=SQL%20chart&amp;chxt=x,y&amp;chxr=1,-4716.6,5340.0&amp;chd=s:dddddddddeeeeeefffffffffeeeedddcccbbaaZZZYYYXXXXXXXXXYYYZZabbcdeefghhijkkllmmmmmmmmllkkjihgfedcbZYXWVUTSRRQQPPPPQQQRSTUVWXZacdfgijlmnpqrssttuuuttssrqonmkigfdbZXVTSQONMLKJIIIIIIJKLMOPRTVXZbegilnprtvwyz01111110zyxvtrpnkifcaXUSPNLJHFECBBAAABBCEFHJLNQTWZcfilortwy1346789999876420yvspmjfcYVSOL" alt="" width="400" height="200" />

http://chart.apis.google.com/chart?cht=lc&#038;chs=400x200&#038;chtt=SQL%20chart&#038;chxt=x,y&#038;chxr=1,-4716.6,5340.0&#038;chd=s:dddddddddeeeeeefffffffffeeeedddcccbbaaZZZYYYXXXXXXXXXYYYZZabbcdeefghhijkkllmmmmmmmmllkkjihgfedcbZYXWVUTSRRQQPPPPQQQRSTUVWXZacdfgijlmnpqrssttuuuttssrqonmkigfdbZXVTSQONMLKJIIIIIIJKLMOPRTVXZbegilnprtvwyz01111110zyxvtrpnkifcaXUSPNLJHFECBBAAABBCEFHJLNQTWZcfilortwy1346789999876420yvspmjfcYVSOL
</pre>
</blockquote>
<p>The above chart depicts our visualized data. Alas, x-axis ranges are wrong; no ticks nor grids are yet presented.</p>
<p>Granularity is not the best, either: the different <strong>62</strong> values are spread across a <strong>200</strong> pixel high chart, making for a <strong>3</strong> pixel distinction between two values, evident on the left area of the chart.</p>
<p>Continues on <a href="http://code.openark.org/blog/mysql/generating-google-line-charts-with-sql-part-ii">Generating Google line charts with SQL, part II</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://code.openark.org/blog/mysql/generating-google-line-charts-with-sql-part-i/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>mycheckpoint (rev 208): aggregation tables, enhanced charting, RPM distribution</title>
		<link>http://code.openark.org/blog/mysql/mycheckpoint-rev-208-aggregation-tables-enhanced-charting-rpm-distribution</link>
		<comments>http://code.openark.org/blog/mysql/mycheckpoint-rev-208-aggregation-tables-enhanced-charting-rpm-distribution#comments</comments>
		<pubDate>Mon, 08 Nov 2010 10:45:45 +0000</pubDate>
		<dc:creator>shlomi</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Monitoring]]></category>
		<category><![CDATA[mycheckpoint]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://code.openark.org/blog/?p=3066</guid>
		<description><![CDATA[Revision 208 of mycheckpoint, a MySQL monitoring solution, has been released. New and updated in this revision: Aggregation tables: aggregated data makes for fast reports on previously slow queries. Enhanced charting: interactive charts now present time stamps dynamically (see demo); "Zoom in" charts are available (see demo) on mycheckpoint's HTTP server. RPM distribution: a "noarch" [...]]]></description>
			<content:encoded><![CDATA[<p>Revision <strong>208</strong> of <a href="../../forge/mycheckpoint">mycheckpoint</a>, a MySQL monitoring solution, has  been released. New and updated in this revision:</p>
<ul>
<li><strong>Aggregation tables</strong>: aggregated data makes for fast reports on previously slow queries.</li>
<li><strong>Enhanced charting</strong>: interactive charts now present time stamps dynamically (see <a href="http://mycheckpoint.googlecode.com/svn/trunk/doc/html/sample/http/mcp_sql00/sv_report_html_brief"><strong>demo</strong></a>); "Zoom in" charts are available (see <a href="http://mycheckpoint.googlecode.com/svn/trunk/doc/html/sample/http/mcp_sql00/zoom/questions"><strong>demo</strong></a>) on <em>mycheckpoint</em>'s HTTP server.</li>
<li><strong>RPM distribution</strong>: a "noarch" RPM <em>mycheckpoint</em> build is now available.</li>
<li>Initial work on formalizing test environment</li>
</ul>
<p><em>mycheckpoint</em> celebrates one year of existence!</p>
<h4>Aggregation tables</h4>
<p>I really wanted to avoid using these: everything was so more beautiful with one single dataset and dozens of supporting views (OK, the views themselves are hardly "beautiful").</p>
<p>However it was impossible (for my level of expertise) to optimize query performance what with all those views on per-hour and per-day aggregation. The GROUP BYs and the JOINs did not make it possible for condition pushdown (i.e. using MERGE algorithm) where desired.</p>
<p>As result, mycheckpoint now manages aggregation tables: per-hour and per-day. The impact on sample taking is neglect able (making for two additional fast queries), but the impact on reading aggregated data is overwhelming. Generating a HTML full report could take a few minutes to complete. It now returns in no time. This makes charting more attractive, and allows for enhanced charting, such as zooming in on charts, as described following.</p>
<p>Aggregation tables will automatically be created and retroactively populated upon using revision 208. There's nothing special to do; be advised that for one single execution of <em>mycheckpoint</em>, many INSERT queries are going to be executed. Shouldn't take more than a couple minutes on commodity hardware and a few months of history.</p>
<p>It is possible to disable aggregation tables, or make for a complete rebuild of tables; by default, though, aggregation is ON.</p>
<h4>Enhanced charting</h4>
<p>Two enhancements here:<span id="more-3066"></span></p>
<ol>
<li>The interactive line charts already know how to update legend data as mouse hovers over them. Now they also present accurate date &amp; time. This provides with fully informative charts.</li>
<li>As with other monitoring tools, it is possible to "zoom in" on a chart: zooming in will present any chart in "last 24 hours", "last 10 days" and "complete history" views, magnified on screen. See <a href="http://mycheckpoint.googlecode.com/svn/trunk/doc/html/sample/http/mcp_sql00/zoom/questions"><strong>demo</strong></a> here.</li>
</ol>
<h4>RPM distribution</h4>
<p>No excuse for this being so late, I know. But RPM distribution is now <a href="http://code.google.com/p/mycheckpoint/">available</a>. Yeepee!</p>
<p>This is a <em>noarch</em> distribution, courtesy of Python's <a href="http://docs.python.org/distutils/">distutils</a>; you should be able to install the package on any RPM supporting platform. I have only tested in on CentOS; feedback is welcome.</p>
<h4>Future plans</h4>
<p>Work is going on. These are the non-scheduled future tasks I see:</p>
<ul>
<li>Monitoring InnoDB Plugin &amp; XtraDB status.</li>
<li>A proper <em>man</em> page.</li>
<li>Anything else that interests me &amp; the users.</li>
</ul>
<h4>Try it out</h4>
<p>Try out <em>mycheckpoint</em>. It’s a different kind of monitoring    solution. Simple monitoring (charting) is immediate. For more  interesting results you will need basic SQL skills, and in return you’ll  get a lot   of power under your hands.</p>
<ul>
<li>Download mycheckpoint <a href="https://code.google.com/p/mycheckpoint/">here</a></li>
<li>Visit the project’s <a href="../../forge/mycheckpoint">homepage</a></li>
<li>Browse the <a href="../../forge/mycheckpoint/documentation">documentation</a></li>
<li>Report <a href="https://code.google.com/p/mycheckpoint/issues/list">bugs</a></li>
</ul>
<p><em>mycheckpoint</em> is released under the <a href="http://www.opensource.org/licenses/bsd-license.php">New BSD  License</a>.</p>
<p>Umm, I'll repeat this last one: <em>mycheckpoint</em> is released under the <a href="http://www.opensource.org/licenses/bsd-license.php">New BSD  License</a>. Still, and will continue to be. Thanks for the <a href="http://code.openark.org/blog/mysql/openark-kit-facebook-online-schema-change-and-thoughts-on-open-source-licenses#comments">good advice</a> by Lenz, Domas and others.</p>
]]></content:encoded>
			<wfw:commentRss>http://code.openark.org/blog/mysql/mycheckpoint-rev-208-aggregation-tables-enhanced-charting-rpm-distribution/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>openark-kit, Facebook Online Schema Change, and thoughts on open source licenses</title>
		<link>http://code.openark.org/blog/mysql/openark-kit-facebook-online-schema-change-and-thoughts-on-open-source-licenses</link>
		<comments>http://code.openark.org/blog/mysql/openark-kit-facebook-online-schema-change-and-thoughts-on-open-source-licenses#comments</comments>
		<pubDate>Thu, 16 Sep 2010 06:02:53 +0000</pubDate>
		<dc:creator>shlomi</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[mycheckpoint]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[openark kit]]></category>
		<category><![CDATA[Opinions]]></category>

		<guid isPermaLink="false">http://code.openark.org/blog/?p=2947</guid>
		<description><![CDATA[MySQL@Facebook team have recently published an Online Schema Change code for non blocking ALTER TABLE operations. Thumbs Up! The code is derived from oak-online-alter-table, part of openark-kit, a toolkit I'm authoring. Looking at the documentation I can see many ideas were incorporated as well. And of course many things are different, a lot of work [...]]]></description>
			<content:encoded><![CDATA[<p>MySQL@Facebook team have recently published an <a href="http://www.facebook.com/note.php?note_id=430801045932">Online Schema Change</a> code for non blocking ALTER TABLE operations. Thumbs Up!</p>
<p>The code is derived from <em>oak-online-alter-table</em>, part of <a href="http://code.openark.org/forge/openark-kit">openark-kit</a>, a toolkit I'm authoring. Looking at the documentation I can see many ideas were incorporated as well. And of course many things are different, a lot of work has been put to it by MySQL@Facebook.</p>
<p><em>openark-kit</em> is currently released under the new BSD license, and, as far as I can tell (I'm not a lawyer), Facebook's work has followed the license to the letter. It is a strange thing to see your code incorporated into another project. While I knew work has begun on the tool by Facebook, I wasn't in on it except for a few preliminary email exchanges.</p>
<h4>And this is the beauty</h4>
<p>You release code under open source license, and anyone can pick it up and continue working on it. One doesn't have to ask or even let you know. Eventually one may release back to the community improved code, more tested (not many comments on <em>oak-online-alter-table</em> in the past <strong>18</strong> months).</p>
<p>It is a beauty, that you can freely use one's patches, and he can then use yours.</p>
<h4>And here is my concern</h4>
<p>When I created both <em>openark-kit</em> and <em>mycheckpoint</em>, I licensed them under the BSD license. A very permissive license. <em>Let anyone do what they want with it</em>, I thought. However Facebook's announcement suddenly hit me: what license would other people use for their derived work?</p>
<p>The OSC has been release under permissive license back to the community (again, I am not a lawyer). But, someone else could have made it less friendly. Perhaps not release the code at all: just sell it, closed-source, embedded in their product. And I found out that <em>I do not want anyone to do whatever they want with my code</em>.</p>
<h4>I want all derived work to <em>remain open</em>!</h4>
<p>Which is why in next releases of code I'm authoring the license will change to <em>less permissive</em> and <em>more open</em> license, such as GPL or LGPL. (Of course, all code released so far remains under the BSD license).</p>
]]></content:encoded>
			<wfw:commentRss>http://code.openark.org/blog/mysql/openark-kit-facebook-online-schema-change-and-thoughts-on-open-source-licenses/feed</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>mycheckpoint (rev. 190): HTTP server; interactive charts</title>
		<link>http://code.openark.org/blog/mysql/mycheckpoint-rev-190-http-server-interactive-charts</link>
		<comments>http://code.openark.org/blog/mysql/mycheckpoint-rev-190-http-server-interactive-charts#comments</comments>
		<pubDate>Tue, 07 Sep 2010 05:53:01 +0000</pubDate>
		<dc:creator>shlomi</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Monitoring]]></category>
		<category><![CDATA[mycheckpoint]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://code.openark.org/blog/?p=2866</guid>
		<description><![CDATA[Revision 190 of mycheckpoint, a MySQL monitoring solution, has been released. New and updated in this revision: HTTP server: mycheckpoint can now act as a web server. Point your browser and start browsing through HTML reports. See mock up demo. Interactive charts: HTML line charts are now interactive, presenting with accurate data as you move [...]]]></description>
			<content:encoded><![CDATA[<p>Revision <strong>190</strong> of <a href="../../forge/mycheckpoint">mycheckpoint</a>, a MySQL monitoring solution, has  been released. New and updated in this revision:</p>
<ul>
<li><strong>HTTP server</strong>: <em>mycheckpoint</em> can now act as a web server. Point your browser and start browsing through HTML reports. See mock up <a href="http://code.openark.org/forge/wp-content/uploads/2010/09/r190/mcp_sql00/sv_report_html_brief.html"><strong>demo</strong></a>.</li>
<li><strong>Interactive charts</strong>: HTML line charts are now interactive, presenting with accurate data as you move over them. See <a href="http://code.openark.org/forge/wp-content/uploads/2010/09/r190/mcp_sql00_samples/sv_report_html_brief.html"><strong>sample</strong></a>.</li>
<li><strong>Enhanced auto-deploy</strong>: now auto-recognizing failed upgrades.</li>
<li><strong>Reduced footprint</strong>: much code taken out of the views, leading to faster loading times.</li>
<li><strong>Better configuration file use</strong>: now supporting all command line options in config file.</li>
<li><strong>Remote host monitoring accessibility</strong>: now supporting complete configurable accessibility details.</li>
<li><strong>Bug fixes</strong>: thanks to the bug reporters!</li>
</ul>
<p><em>mycheckpoint</em> is free, simple, easy to use (now easier with HTTP server) and <strong>useful</strong>. I encourage you to try it out: even compared with other existing and emerging monitoring tools, I believe you will find it a breeze; it's low impact and lightness appealing; it's alerts mechanism assuring; its geeky SQL-based nature with ability to drill down to fine details -- geeky-kind-of-attractive.</p>
<p>&lt;/encouragement&gt;</p>
<h4>HTTP server</h4>
<p>You can now run <em>mycheckpoint</em> in <em>http</em> mode:</p>
<blockquote>
<pre>bash$ <strong>mycheckpoint http</strong></pre>
</blockquote>
<p><em>mycheckpoint</em> will listen on port <strong>12306</strong>, and will present you with easy browsing through the reports of your <em>mycheckpoint</em> databases.<span id="more-2866"></span></p>
<p>The <em>http</em> server automatically detects those schemata used by mycheckpoint, and utilizes the existing HTML views, integrating them into the greater web framework.</p>
<p>While in <em>http</em> mode, mycheckpoint does nothing besides serving web pages. It does not actively exercise monitoring: you must still use the usual cron jobs or other scheduled tasks by which you invoke <em>mycheckpoint</em> for monitoring.</p>
<p>The http server is directed at a single MySQL server, as with the following example:</p>
<blockquote>
<pre>bash$ <strong>mycheckpoint --host=slave1.localdomain --port=3306 --http-port=12306 http</strong></pre>
</blockquote>
<p>It is assumed that this server has the monitoring schemata.</p>
<p>See mock up <a href="http://code.openark.org/forge/wp-content/uploads/2010/09/r190/mcp_sql00/sv_report_html_brief.html"><strong>demo</strong></a>. The demo uses presents with real output from a mycheckpoint HTTP server; I haven't got the means to put up a live demo.</p>
<h4>Interactive charts</h4>
<p>The <em>openark line charts</em>, used in the HTML reports, are now interactive. As you scroll over, the legend presents you with series values.</p>
<p>No more <em>"I have this huge spike once every 4 hours, which reduces all other values to something that looks like zero but is actually NOT"</em>. Hover, and see the real values.</p>
<p>See <a href="http://code.openark.org/forge/wp-content/uploads/2010/09/r190/mcp_sql00_samples/sv_report_html_brief.html"><strong>sample</strong></a>.</p>
<h4>Enhanced auto-deploy</h4>
<p>The idea with mycheckpoint is that it should know how to self upgrade the schema on version upgrade (much like automatic WordPress upgrades). mycheckpoint does bookkeeping of installed versions within the database, and upgrades by simple comparison.</p>
<p>It now, following a couple of reported bugs, also recognizes failure of partial, failed upgrades. This adds to the automation of <em>mycheckpoint</em>'s installation.</p>
<h4>Reduced footprint</h4>
<p>Some of <em>mycheckpoint</em>'s views are complicated, and lead to a large amount of code in view declaration. This leads to increased table definition size (large <strong>.frm</strong> files). There has been some work to reduce this size where possible. Work is still ongoing, but some 30% has been taken off already. This leads to faster table (view) load time.</p>
<h4>Better configuration file use</h4>
<p>Any argument supported on the command line is now also supported in the config style. Much like is handled with MySQL. For example, one can issue:</p>
<blockquote>
<pre>mycheckpoint --monitored-host=sql02.mydb.com  --monitored-user=monitor --monitored-password=123456</pre>
</blockquote>
<p>But now also:</p>
<blockquote>
<pre>mycheckpoint</pre>
</blockquote>
<p>With the following in <strong>/etc/mycheckpoint.cnf</strong>:</p>
<blockquote>
<pre>[mycheckpoint]
monitored_host     = sql02.mydb.com
monitored_user     = monitor
monitored_password = 123456
</pre>
</blockquote>
<p>Rules are:</p>
<ul>
<li>If an option is specified on command line, it takes precedence over anything else.</li>
<li>Otherwise, if it's specified in the configuration file, value is read from file.</li>
<li>Otherwise use default value is used.</li>
<li>On command line, option format is<strong> xxx-yyy-zzz</strong>: words split with dash/minus character.</li>
<li>On configuration file, option format is <strong>xxx_yyy_zzz</strong>: words split with underscore. Unlike MySQL configuration format, dashes cannot be used.</li>
<li>If an option is specified multiple times on configuration file -- well -- I have the answer, but I won't tell. Just don't do it. It's bad for your health.</li>
</ul>
<h4>Future plans</h4>
<p>Work is going on. These are the non-scheduled future tasks I see:</p>
<ul>
<li>Monitoring InnoDB Plugin &amp; XtraDB status.</li>
<li>A proper <em>man</em> page.</li>
<li>Anything else that interests me &amp; the users.</li>
</ul>
<h4>Try it out</h4>
<p>Try out <em>mycheckpoint</em>. It’s a different kind of monitoring   solution. Simple monitoring (charting) is immediate. For more interesting results you will need basic SQL skills, and in return you’ll get a lot   of power under your hands.</p>
<ul>
<li>Download mycheckpoint <a href="https://code.google.com/p/mycheckpoint/">here</a></li>
<li>Visit the project’s <a href="../../forge/mycheckpoint">homepage</a></li>
<li>Browse the <a href="../../forge/mycheckpoint/documentation">documentation</a></li>
<li>Report <a href="https://code.google.com/p/mycheckpoint/issues/list">bugs</a></li>
</ul>
<p><em>mycheckpoint</em> is released under the <a href="http://www.opensource.org/licenses/bsd-license.php">New BSD  License</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://code.openark.org/blog/mysql/mycheckpoint-rev-190-http-server-interactive-charts/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>mycheckpoint (rev. 170): improved custom queries; local charting; page/swap I/O monitoring; improved HTML reports</title>
		<link>http://code.openark.org/blog/mysql/mycheckpoint-rev-170-improved-custom-queries-local-charting-pageswap-io-monitoring-improved-html-reports</link>
		<comments>http://code.openark.org/blog/mysql/mycheckpoint-rev-170-improved-custom-queries-local-charting-pageswap-io-monitoring-improved-html-reports#comments</comments>
		<pubDate>Fri, 16 Jul 2010 08:58:40 +0000</pubDate>
		<dc:creator>shlomi</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Graphs]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Monitoring]]></category>
		<category><![CDATA[mycheckpoint]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://code.openark.org/blog/?p=2650</guid>
		<description><![CDATA[Revision 170 of mycheckpoint, a MySQL monitoring solution, has been released. New and updated in this revision: Improved custom queries: lifting of limitations from previous, introductory revision; better HTML presentation Local, inline charting: no rendering of Google Charts, unless explicitly requested. All charts are now rendered locally using JavaScript. No data is now sent over [...]]]></description>
			<content:encoded><![CDATA[<p>Revision <strong>170</strong> of <a href="../../forge/mycheckpoint">mycheckpoint</a>, a MySQL monitoring solution, has  been released. New and updated in this revision:</p>
<ul>
<li><strong>Improved custom queries</strong>: lifting of limitations from previous, introductory revision; better HTML presentation</li>
<li><strong>Local, inline charting</strong>: no rendering of Google Charts, unless explicitly requested. All charts are now rendered locally using JavaScript. No data is now sent over the network.</li>
<li><strong>Page/Swap I/O monitoring</strong>: now monitoring for page ins and outs, swap ins and outs (Linux only).</li>
<li><strong>Improved HTML reports</strong>: several improvements on presentation (see <a href="http://code.openark.org/forge/wp-content/uploads/2010/07/mycheckpoint-report-brief-169.html">sample</a>, more follow).</li>
</ul>
<h4>Improved custom queries</h4>
<p>Some limitations, introduced in revision <strong>132</strong>, are now lifted. New features are introduced.</p>
<ul>
<li>There is now no limit to the number of custom queries (well, an INT limit).</li>
<li>In fact, the data tables adjust themselves to the existing custom queries in the form of auto-deploy: once a new <a href="http://code.openark.org/forge/mycheckpoint/documentation/custom-monitoring">custom query is added</a> or an old one removed, mycheckpoint will add or remove the relevant columns from the data tables.</li>
<li>The <strong>chart_order</strong> column is now utilized: HTML reports which include custom query charts now order those charts according to <strong>chart_order</strong> values. This makes for nicer reports.</li>
<li>The standard <a href="http://code.openark.org/forge/wp-content/uploads/2010/07/mycheckpoint-report-brief-169.html">HTML brief report</a> (<strong>SELECT html FROM sv_report_html_brief</strong>) now automatically includes all custom charts. The HTML brief report is the report one usually wants to look at: it provides with the latest 24 hours metrics for selected values. It now becomes a centralized place for all that is interesting in the past 24 hours.</li>
<li>Custom queries are now allowed to return <strong>NULL</strong>, treated as a missing value. This is a bugfix from previous revisions.</li>
</ul>
<h4>Local charting</h4>
<p>Motivation for local charting is clear: no one likes having their data being sent over the network. And no one likes Google to know about their DML values.</p>
<p>I've been playing around with quite a few charting solutions, and have gone into depths with two of them, adding and rewriting quite a lot of code. Eventually, I settled on my very own rendering. Here's what I've seen &amp; tested:<span id="more-2650"></span></p>
<ul>
<li><a href="http://danvk.org/dygraphs/">dygraphs</a>: a very nice time series charting library. I've presented a use case on <a href="http://code.openark.org/blog/mysql/static-charts-vs-interactive-charts">a previous post</a>.
<ul>
<li>Pros: slick, easy to work with.</li>
<li>Cons: uses HTML Canvas for rendering. This is fine on Firefox, Chrome, Safari, you name it. This isn't fine on IE, which does not support Canvas. There's <a href="http://excanvas.sourceforge.net/">ExplorerCanvas</a>, a hack tool which converts canvas to IE's VML, but it is far from being satisfactory: it is <em>sloooow</em>. Very, very slow. It is slow with one chart; but loading of 21 charts, as I do in some of <em>mycheckpoint</em>'s reports can take <em>long minutes</em> on Internet explorer.</li>
<li>Cons: Only provides with a time series chart. No scatter plots.</li>
</ul>
</li>
<li>Because they're using ExplorerCanvas for IE, <a href="http://code.google.com/p/flot/">flot</a>, <a href="http://www.jqplot.com/">jqPlot</a> etc., are all unacceptable.</li>
<li><a href="http://g.raphaeljs.com/">gRaphael</a>: very slick charts based on Raphael. The original line charts are very basic, and I have invested a lot of time rewriting a great deal (you can find it all <a href="http://code.google.com/p/mycheckpoint/source/browse/#svn/trunk/graphael">here</a>). Raphael uses VML on IE, and SVG for all other browsers.
<ul>
<li>Pros: very slick. Supports various chart types, including line (though not time-series) and scatter.</li>
<li>Cons: <em>slooooooooow</em> when instantiating multiple charts. Unbearably slow, both on Firefox and IE. Slow as in minutes of waiting.</li>
</ul>
</li>
</ul>
<p>In addition, all of the above solutions were quite heavyweight: at about 45KB to start with, then add ExplorerCanvas or jQuery, or Raphael as supporting libraries, these became a real burden.</p>
<p>So, I had some time to spare (business is fine, thank you. I was a bit Ill. I'm feeling well now, thank you), and was upset what with all the time I invested in the above coding. And I decided to invest even more time, and build <em>my own</em> charts.</p>
<p>Enter <em>openark-charts</em>.</p>
<blockquote>
<pre><a href="http://code.openark.org/blog/wp-content/uploads/2010/07/mycheckpoint-report-html-screenshot.png"><img class="alignnone size-full wp-image-2662" title="mycheckpoint-report-html-screenshot" src="http://code.openark.org/blog/wp-content/uploads/2010/07/mycheckpoint-report-html-screenshot.png" alt="" width="808" height="307" /></a>

<a href="http://code.openark.org/blog/wp-content/uploads/2010/07/mycheckpoint-24-7-report-html-screenshot.png"><img class="alignnone size-full wp-image-2663" title="mycheckpoint-24-7-report-html-screenshot" src="http://code.openark.org/blog/wp-content/uploads/2010/07/mycheckpoint-24-7-report-html-screenshot.png" alt="" width="808" height="267" /></a></pre>
</blockquote>
<p>Currently, these line charts and scatter charts know how to parse a Google Image chart URL (only some features supported -- only those I'm actually using with <em>mycheckpoint</em>). These are not full blown solutions: they come to serve mycheckpoint. And they do so nicely, if I may say so. Using Canvas for most browsers, or VML for IE, these very small pieces of code (10K for line chart, 6K for scatter chart, minified) load fast, use very little memory, and do their work well.</p>
<p>Granted, neither provides with interactive features: this is planned for the future.</p>
<h4>Page/swap I/O monitoring</h4>
<p>(Linux only) <em>mycheckpoint</em> now reads <strong>/proc/vmstat</strong> to get the <em>pageins</em>, <em>pageouts</em>, <em>swapins</em> and <em>swapouts</em> (since last reboot). I was actually looking at completely different places on the <strong>/proc</strong> file system to get swap info, and was frustrated with the complexity involved, till I bumped on <strong>/proc/vmstat</strong>... New tricks every day!</p>
<h4>Improved HTML reports</h4>
<p>This is mostly HTML make-up. Some minimal design, some more details thrown into the HTML pages (name of DB, MySQL version, <em>mycheckpoint</em> version). A little more verbosity; all sorts of stuff which was neglected so far.</p>
<p>Here are some <span style="text-decoration: line-through;"><strong>show off</strong></span> examples of the new HTML views: <a href="http://code.openark.org/forge/wp-content/uploads/2010/07/mycheckpoint-report-full-169.html">[full report]</a>, <a href="http://code.openark.org/forge/wp-content/uploads/2010/07/mycheckpoint-report-brief-169.html">[brief report]</a>, <a href="http://code.openark.org/forge/wp-content/uploads/2010/07/mycheckpoint-report-24-7-169.html">[24/7 report]</a>, <a href="http://code.openark.org/forge/wp-content/uploads/2010/07/mycheckpoint-report-custom-full-169.html">[custom full report]</a>, <a href="http://code.openark.org/forge/wp-content/uploads/2010/07/mycheckpoint-report-custom-brief-169.html">[custom brief report]</a>, <a href="http://code.openark.org/forge/wp-content/uploads/2010/07/mycheckpoint-alert-pending-169.html">[alert pending report]</a>.</p>
<p>All HTML views now utilize the new <em>openark-charts</em>, and none renders charts with Google charts. This means when you <a href="http://code.openark.org/forge/mycheckpoint/documentation/generating-html-reports">use your HTML view</a>, your data is safe. No data is sent over the net. All charts are rendered using Javascript, which is loaded and executed locally.</p>
<p>But if you like, there's a [url] link next to each chart, which leads to a (online) Google chart image. Why? Because neither HTML Canvas nor VML allow for a complete rendering of the charts to an image. So this is a way for one to retrieve &amp; store a chart's image. Don't use it if you see no reason for it; it's just there.</p>
<p>And I even threw in rounded corners (IE users: only as of Windows 7).</p>
<h4>Future plans</h4>
<p>Work is going on. These are the non-scheduled future tasks I see:</p>
<ul>
<li>Monitoring InnoDB Plugin &amp; XtraDB status.</li>
<li>Interactive charts. See my <a href="../mysql/static-charts-vs-interactive-charts">earlier  post</a>.</li>
<li>A proper <em>man</em> page.</li>
<li>Anything else that interests me.</li>
</ul>
<h4>Try it out</h4>
<p>Try out <em>mycheckpoint</em>. It’s a different kind of monitoring  solution. You will need basic SQL skills, and in return you’ll get a lot  of power under your hands.</p>
<ul>
<li>Download mycheckpoint <a href="https://code.google.com/p/mycheckpoint/">here</a></li>
<li>Visit the project’s <a href="../../forge/mycheckpoint">homepage</a></li>
<li>Browse the <a href="../../forge/mycheckpoint/documentation">documentation</a></li>
<li>Report <a href="https://code.google.com/p/mycheckpoint/issues/list">bugs</a></li>
</ul>
<p><em>mycheckpoint</em> is released under the <a href="http://www.opensource.org/licenses/bsd-license.php">New BSD  License</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://code.openark.org/blog/mysql/mycheckpoint-rev-170-improved-custom-queries-local-charting-pageswap-io-monitoring-improved-html-reports/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>mycheckpoint (rev. 132): custom monitoring, custom charts, process list dump</title>
		<link>http://code.openark.org/blog/mysql/mycheckpoint-rev-132-custom-monitoring-custom-charts-process-list-dump</link>
		<comments>http://code.openark.org/blog/mysql/mycheckpoint-rev-132-custom-monitoring-custom-charts-process-list-dump#comments</comments>
		<pubDate>Fri, 04 Jun 2010 09:17:27 +0000</pubDate>
		<dc:creator>shlomi</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Graphs]]></category>
		<category><![CDATA[Monitoring]]></category>
		<category><![CDATA[mycheckpoint]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[scripts]]></category>

		<guid isPermaLink="false">http://code.openark.org/blog/?p=2463</guid>
		<description><![CDATA[Revision 132 of mycheckpoint has been released. New and updated in this revision: Custom monitoring: monitoring &#38; charting for user defined queries HTML reports for custom monitoring Process list dump upon alert notifications Custom monitoring &#38; charts Custom monitoring allows the user to supply with a query, the results of which will be monitored. That [...]]]></description>
			<content:encoded><![CDATA[<p>Revision <strong>132</strong> of <a href="../../forge/mycheckpoint">mycheckpoint</a> has been released. New and updated in this revision:</p>
<ul>
<li>Custom monitoring: monitoring &amp; charting for user defined queries</li>
<li>HTML reports for custom monitoring</li>
<li>Process list dump upon alert notifications</li>
</ul>
<h4>Custom monitoring &amp; charts</h4>
<p>Custom monitoring allows the user to supply with a query, the results of which will be monitored.</p>
<p>That is, <em>mycheckpoint</em> monitors the status variables, replication status, OS metrics. But it cannot by itself monitor one's <em>application</em>. Which is why a user may supply with such query as:</p>
<blockquote><pre class="brush: sql; title: ; notranslate">
SELECT COUNT(*) FROM shopping_cart WHERE is_pending=1
</pre>
</blockquote>
<p>Such a query will tell an online store how many customers are in the midst of shopping. There is no argument that this number is worth monitoring for. Given the above query, <em>mycheckpoint</em> will execute it per sample, and store the query's result along with all sampled data, to be then aggregated by complex views to answer for:</p>
<ul>
<li>What was the value per given sample?</li>
<li>What is the value difference for each sample?</li>
<li>What is the change per second, i.e. the rate?</li>
</ul>
<p>mycheckpoint goes one step forward, and explicity records another metric:</p>
<ul>
<li>How much time did it take to take that sample?</li>
</ul>
<p><span id="more-2463"></span>As another example, a query worth testing for rate:</p>
<blockquote><pre class="brush: sql; title: ; notranslate">
SELECT MAX(shopping_cart_id) FROM shopping_cart
</pre>
</blockquote>
<p>The above will provide with the last id. Assuming this is <strong>AUTO_INCREMENT</strong>, and assuming we're on <strong>auto_increment_increment=1</strong>, two samples will allow us to get the number of created carts between those samples. Now, here's a metric I'd like to read:</p>
<ul>
<li>How many carts are created per second, for each hour of the day?</li>
</ul>
<p>We get all these for free with mycheckpoint, which already does this analysis. All we need to provide is the query, and how we would like it to be visualized (visualization is optional, it is not the only way to diagnose monitored data) graphically:</p>
<blockquote><pre class="brush: sql; title: ; notranslate">
INSERT INTO
 custom_query (custom_query_id, enabled, query_eval, description, chart_type, chart_order)
 VALUES (0, 1, 'SELECT COUNT(*) FROM store.shopping_cart WHERE is_pending=1', 'Number of pending carts', 'value', 0);

INSERT INTO
 custom_query (custom_query_id, enabled, query_eval, description, chart_type, chart_order)
 VALUES (1, 1, 'SELECT MAX(shopping_cart_id) FROM store.shopping_cart', 'Created carts rate', 'value_psec', 0);
</pre>
</blockquote>
<p>We can later query for these values, just like we do for normal monitored values:</p>
<blockquote><pre class="brush: sql; title: ; notranslate">
mysql&gt; SELECT id, ts, created_tmp_tables_psec, custom_0, custom_1_psec FROM sv_sample WHERE ts &gt;= NOW() - INTERVAL 1 HOUR;
+-------+---------------------+-------------------------+----------+---------------+
| id    | ts                  | created_tmp_tables_psec | custom_0 | custom_1_psec |
+-------+---------------------+-------------------------+----------+---------------+
| 50730 | 2010-05-21 19:05:01 |                   16.64 |      448 |          3.02 |
| 50731 | 2010-05-21 19:10:02 |                   20.97 |       89 |          1.73 |
| 50732 | 2010-05-21 19:15:01 |                   15.70 |      367 |          3.56 |
| 50733 | 2010-05-21 19:20:01 |                   18.32 |       54 |          1.43 |
| 50734 | 2010-05-21 19:25:01 |                   16.42 |       91 |          1.96 |
| 50735 | 2010-05-21 19:30:02 |                   21.93 |      233 |          2.11 |
| 50736 | 2010-05-21 19:35:02 |                   14.58 |      176 |          1.91 |
| 50737 | 2010-05-21 19:40:01 |                   21.61 |      168 |          1.93 |
| 50738 | 2010-05-21 19:45:01 |                   16.05 |      241 |          2.44 |
| 50739 | 2010-05-21 19:50:01 |                   19.70 |       46 |          1.19 |
| 50740 | 2010-05-21 19:55:01 |                   15.85 |      177 |          2.28 |
| 50741 | 2010-05-21 20:00:01 |                   19.04 |        8 |          0.82 |
+-------+---------------------+-------------------------+----------+---------------+
</pre>
</blockquote>
<p>Of course, it is also possible to harness <em>mycheckpoint</em>'s views power to generate charts:</p>
<blockquote>
<pre>mysql&gt; SELECT custom_1_psec FROM sv_report_chart_sample\G
<img class="alignnone" title="custom_1_psec" src="http://chart.apis.google.com/chart?cht=lc&amp;chs=400x200&amp;chts=303030,12&amp;chtt=Latest+24+hours:+May+19,+20:10++-++May+20,+20:10&amp;chf=c,s,ffffff&amp;chdl=custom_1_psec&amp;chdlp=b&amp;chco=ff8c00&amp;chd=s:QfXQmZQhXTmWVkWRobPpWUtQPVROaOOUMJPOKdJHQJFJEDJJEGCAIEFJHFFEGGDQHGJGMJPPMNZNRWR_ZUWfR_nSjuUcaXa3OgxRl4UivWZ5UhtWX4VgnUTYktiVW9WanUVxVYlgXwVdicXpb&amp;chxt=x,y&amp;chxr=1,0,5.120000&amp;chxl=0:||+||00:00||+||04:00||+||08:00||+||12:00||+||16:00||+||20:00|&amp;chxs=0,505050,10,0,lt&amp;chg=4.17,25,1,2,3.47,0&amp;chxp=0,3.47,7.64,11.81,15.98,20.15,24.32,28.49,32.66,36.83,41.00,45.17,49.34,53.51,57.68,61.85,66.02,70.19,74.36,78.53,82.70,86.87,91.04,95.21,99.38" alt="" width="400" height="200" />
</pre>
</blockquote>
<p>The rules are:</p>
<ul>
<li>There can (currently) only be 18 custom queries.</li>
<li>The <strong>custom_query_id</strong> must range 0-17 (to be lifted soon).</li>
<li>A custom query must return with <em>exactly</em> one row, with <em>exactly</em> one column, which is a kind of <em>integer</em>.</li>
</ul>
<p>Please read <a href="http://code.openark.org/blog/mysql/things-to-monitor-on-mysql-the-users-perspective">my earlier post</a> on custom monitoring to get more background.</p>
<h4>Custom monitoring HTML reports</h4>
<p>Custom monitoring comes with a HTML reports, featuring requested charts. See a <a href="http://code.openark.org/blog/wp-content/uploads/2010/05/mcp_custom_report-128.html">sample custom report</a>.</p>
<p>In this sample report, a few queries are monitored for value (pending rentals, pending downloads) and a few for rates (downloads per second, emails per second etc.).</p>
<p>Custom HTML reports come in two flavors:</p>
<ul>
<li>Brief reports, featuring last 24 hours, as in the example above. These are handled by the <strong>sv_custom_html_brief</strong> view.</li>
<li>Full reports, featuring last 24 hours, last 10 days, known history. These take longer to generate, and are handled by the <strong>sv_custom_html</strong> view.</li>
</ul>
<p>The sample report was generated by issuing:</p>
<blockquote>
<pre>SELECT html FROM sv_custom_html_brief;</pre>
</blockquote>
<p>I won't go into details here as for how this view generates the HTML code. There is a myriad of view dependencies, with many interesting tricks on the way. But do remember it's <em>just a view</em>. You don't need an application (not even <em>mycheckpoint</em> itself) to generate the report. All it takes is a query.</p>
<h4>Processlist dump</h4>
<p>When an alert notification fires (an email is prepared to inform on some alert condition), a processlist dump summary is taken and included in email report. It may be useful to understand why the slave is lagging, or exactly why there are so many active threads.</p>
<p>The dump summary presents the processlist much as you would see it on SHOW PROCESSLIST, but only lists the active threads, noting down how many sleeping processes there are (PS, thread &amp; process are the same in the terminology of MySQL connections). An example dump looks like this:</p>
<blockquote>
<pre>PROCESSLIST summary:

     Id: 3
   User: system user
   Host:
     db: NULL
Command: Connect
   Time: 3168098
  State: Waiting for master to send event
   Info: NULL
-------

     Id: 4
   User: system user
   Host:
     db: prod_db
Command: Connect
   Time: 612
  State: Updating
   Info: UPDATE user SET is_offline = 1 WHERE id IN (50440010,50440011)
-------

     Id: 8916579
   User: prod_user
   Host: localhost
     db: prod_db
Command: Query
   Time: 1
  State: Sending data
   Info: INSERT IGNORE INTO archive.stat_archive (id, origin, path, ts, content
-------

     Id: 8916629
   User: mycheckpoint
   Host: localhost
     db: NULL
Command: Query
   Time: 0
  State: NULL
   Info: SHOW PROCESSLIST
-------
Sleeping: 3 processes
</pre>
</blockquote>
<h4>Future plans</h4>
<p>Work is going on. These are the non-scheduled future tasks I see:</p>
<ul>
<li>Monitoring InnoDB Plugin &amp; XtraDB status.</li>
<li>Interactive charts. See my <a href="http://code.openark.org/blog/mysql/static-charts-vs-interactive-charts">earlier post</a>.</li>
<li>Monitoring for swap activity (Linux only).</li>
<li>Enhanced custom queries handling, including auto-deploy upon change of custom queries.</li>
<li>A proper <em>man</em> page.</li>
<li>Anything else that interests me.</li>
</ul>
<h4>Try it out</h4>
<p>Try out <em>mycheckpoint</em>. It’s a different kind of monitoring solution. You will need basic SQL skills, and in return you'll get a lot of power under your hands.</p>
<ul>
<li>Download mycheckpoint <a href="https://code.google.com/p/mycheckpoint/">here</a></li>
<li>Visit the project’s <a href="../../forge/mycheckpoint">homepage</a></li>
<li>Browse the <a href="../../forge/mycheckpoint/documentation">documentation</a></li>
<li>Report <a href="https://code.google.com/p/mycheckpoint/issues/list">bugs</a></li>
</ul>
<p><em>mycheckpoint</em> is released under the <a href="http://www.opensource.org/licenses/bsd-license.php">New BSD License</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://code.openark.org/blog/mysql/mycheckpoint-rev-132-custom-monitoring-custom-charts-process-list-dump/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>mycheckpoint (Rev. 118): alerts, email notifications and more</title>
		<link>http://code.openark.org/blog/mysql/mycheckpoint-rev-118-alerts-email-notifications-and-more</link>
		<comments>http://code.openark.org/blog/mysql/mycheckpoint-rev-118-alerts-email-notifications-and-more#comments</comments>
		<pubDate>Thu, 25 Mar 2010 06:26:34 +0000</pubDate>
		<dc:creator>shlomi</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Monitoring]]></category>
		<category><![CDATA[mycheckpoint]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://code.openark.org/blog/?p=2221</guid>
		<description><![CDATA[Revision 118 of mycheckpoint has been released. New and updated in this revision: Conditional alerts Email notifications Revised HTML reports, including 24/7 reports. Updated documentation With this new revision mycheckpoint turns into a monitoring solution for MySQL. One can now: Store measure metrics Query for raw, aggregated or digested metrics Generate charts for selected metrics [...]]]></description>
			<content:encoded><![CDATA[<p>Revision <strong>118</strong> of <a href="http://code.openark.org/forge/mycheckpoint">mycheckpoint</a> has been released. New and updated in this revision:</p>
<ul>
<li>Conditional alerts</li>
<li>Email notifications</li>
<li>Revised HTML reports, including 24/7 reports.</li>
<li>Updated documentation</li>
</ul>
<p>With this new revision mycheckpoint turns into a <em>monitoring solution</em> for MySQL. One can now:</p>
<ul>
<li>Store measure metrics</li>
<li>Query for raw, aggregated or digested metrics</li>
<li>Generate charts for selected metrics</li>
<li>View HTML reports for selecetd metrics</li>
<li>Define alerts conditions, query for pending alerts</li>
<li>Be notified via <em>email</em> on <em>raised</em> or <em>resolved</em> alerts.</li>
</ul>
<h4>Conditional alerts</h4>
<p><em>mycheckpoint</em> is <em>SQL oriented</em>. As such, it allows for creation of alert conditions, which are nothing more than SQL conditions.</p>
<p><span id="more-2221"></span>For example, we wish to raise an alerts when the slave stops replicating (just ping us with an email one this happens):</p>
<blockquote><pre class="brush: sql; title: ; notranslate">INSERT INTO alert_condition (condition_eval, description, alert_delay_minutes)
  VALUES ('seconds_behind_master IS NULL', 'Slave not replicating', 0);</pre>
</blockquote>
<p>Or is too far behind (but since we do maintenance work during the night, it's OK on those hours). We only want to be notified if this goes on for <strong>10</strong> minutes:</p>
<blockquote><pre class="brush: sql; title: ; notranslate">INSERT INTO alert_condition (condition_eval, description, alert_delay_minutes)
  VALUES ('(seconds_behind_master &gt; 60) AND (HOUR(ts) NOT BETWEEN 2 AND 4)', 'Slave lags too far behind', 10);</pre>
</blockquote>
<p>We want to be notified when the <strong>datadir</strong> mount point disk quota exceeds 95% usage. Oh, and please keep nagging us about this, as long as it is unresolved:</p>
<blockquote><pre class="brush: sql; title: ; notranslate">INSERT INTO alert_condition (condition_eval, description, repetitive_alert)
  VALUES ('os_datadir_mountpoint_usage_percent &gt; 95', 'datadir mount point is over 95%', 1);</pre>
</blockquote>
<p>There's much more to alert conditions. You can generate a pending alerts report, get a textual presentation of raised and pending alerts, view the query which determines what alerts are currently raised, and more.</p>
<p>Read more on the <a href="http://code.openark.org/forge/mycheckpoint/documentation/alerts">alerts documentation page</a>.</p>
<h4>Email notifications</h4>
<p>Introducing email notifications, <em>mycheckpoint</em> now:</p>
<ul>
<li>Sends email notification on alert conditions meeting. See <a href="http://code.openark.org/forge/wp-content/uploads/2010/03/mycheckpoint-alerts-email-sample-113.jpeg">sample email screenshot</a>.</li>
<li>Sends email notification when it is unable to access the database.</li>
<li>Sends report via mail. Currently only HTML brief report is supported. Report is attached as HTML file in email message.</li>
</ul>
<p>Alert notifications are automatically sent by mail (once SMTP configuration is in place, see following) when an alert is <em>raised</em> (alert condition becomes <strong>true</strong>) or <em>resolved</em> (alert condition turns <strong>false</strong>).</p>
<p>Email notifications require simple configuration for SMTP host, SMTP-from-address, SMTP-to-address. These can be made in the <a href="http://code.openark.org/forge/mycheckpoint/documentation/usage#defaults_file">defaults file</a> (revised), or through the command line. The following example shows how one can manually send an HTML brief report:</p>
<blockquote>
<pre>mycheckpoint --defaults-file=/etc/mycheckpoint.cnf <strong>--smtp-from</strong>=monitor@my-server-company.com <strong>--smtp-to</strong>=dba@my-server-company.com <strong>--smtp-host</strong>=mail.my-server-company.com <strong>email_brief_report</strong></pre>
</blockquote>
<p>One should generally set up these parameters in the configuration file (aka <em>defaults file</em>) and forget all about it. mycheckpoint now has a default for the defaults file, which is <strong>/etc/mycheckpoint.cnf</strong>.</p>
<p>Read more on the <a href="http://code.openark.org/forge/mycheckpoint/documentation/emails">emails documentation page</a>.</p>
<h4>Revised HTML reports</h4>
<ul>
<li>The brief HTML reports has been updated, see <a href="http://code.openark.org/forge/wp-content/uploads/2010/03/mycheckpoint-brief-report-sample-113.html">sample</a>.</li>
<li>An HTML 24/7 report as been added, see <a href="../../forge/wp-content/uploads/2010/03/mycheckpoint-24-7-report-sample-107.html">sample</a>. This report shows the distribution of popular metrics throughout the weekdays and hours.</li>
</ul>
<p>Full HTML reports remain slow to load. I'm putting some work into this, but I'm not sure I can work around the optimizer's limitations of using indexes for GROUPing through views.</p>
<h4>Updated documentation</h4>
<p>The documentation has been revised, with more details put into the pages. Since <em>mycheckpoint</em> gains more and more features, I saw fit to write a <a href="http://code.openark.org/forge/mycheckpoint/documentation/quick-howto">Quick HOWTO</a> page which gets you up to speed, no fuss around, with <em>mycheckpoint</em>'s usage and features.</p>
<p>Read the mycheckpoint <a href="http://code.openark.org/forge/mycheckpoint/documentation/quick-howto">Quick HOWTO</a> here.</p>
<h4>Future plans</h4>
<p>Work is going on. These are the non-scheduled future tasks I see:</p>
<ul>
<li>Custom monitoring + notifications. See my <a href="http://code.openark.org/blog/mysql/things-to-monitor-on-mysql-the-users-perspective">earlier post</a>.</li>
<li>Monitoring InnoDB Plugin &amp; XtraDB status.</li>
<li>PROCESSLIST dump on alerts.</li>
<li>Interactive charts. See my <a href="http://code.openark.org/blog/mysql/static-charts-vs-interactive-charts">earlier post</a>.</li>
<li>A proper <em>man</em> page...</li>
</ul>
<h4>Try it out</h4>
<p>Try out <em>mycheckpoint</em>. It's a different kind of monitoring solution. It does not require to to have a web server or complicated dependencies. To the experienced DBA it can further provide with valuable, raw or digested information in the form of SQL accessible data. I have used it to find anomalies in passing months, doing SQL search for periods of time where several conditions applied -- it really gives you some extra power.</p>
<ul>
<li>Download mycheckpoint <a href="https://code.google.com/p/mycheckpoint/">here</a></li>
<li>Visit the project's <a href="http://code.openark.org/forge/mycheckpoint">homepage</a></li>
<li>Browse the <a href="http://code.openark.org/forge/mycheckpoint/documentation">documentation</a></li>
<li>Report <a href="https://code.google.com/p/mycheckpoint/issues/list">bugs</a></li>
</ul>
<p><em>mycheckpoint</em> is released under the <a href="http://www.opensource.org/licenses/bsd-license.php">New BSD License</a>.</p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 855px; width: 1px; height: 1px;">http://code.openark.org/forge/mycheckpoint/documentation/quick-howto</div>
]]></content:encoded>
			<wfw:commentRss>http://code.openark.org/blog/mysql/mycheckpoint-rev-118-alerts-email-notifications-and-more/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Things to monitor on MySQL, the user&#039;s perspective</title>
		<link>http://code.openark.org/blog/mysql/things-to-monitor-on-mysql-the-users-perspective</link>
		<comments>http://code.openark.org/blog/mysql/things-to-monitor-on-mysql-the-users-perspective#comments</comments>
		<pubDate>Wed, 10 Mar 2010 09:12:24 +0000</pubDate>
		<dc:creator>shlomi</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Execution plan]]></category>
		<category><![CDATA[Monitoring]]></category>
		<category><![CDATA[mycheckpoint]]></category>

		<guid isPermaLink="false">http://code.openark.org/blog/?p=2008</guid>
		<description><![CDATA[Working on mycheckpoint, I have the intention of adding custom monitoring. That is, letting the user define things to monitor. I have my own thoughts, I would be grateful to get more input! What would the user want to monitor? Monitoring for the number of SELECT statements per second, InnoDB locks, slave replication lag etc. [...]]]></description>
			<content:encoded><![CDATA[<p>Working on <em>mycheckpoint</em>, I have the intention of adding custom monitoring. That is, letting the user define things to monitor. I have my own thoughts, I would be grateful to get more input!</p>
<h4>What would the user want to monitor?</h4>
<p>Monitoring for the number of SELECT statements per second, InnoDB locks, slave replication lag etc. is very important, and monitoring utilities provide with this information. But what does that tell the end user? Not much.</p>
<p>The experienced DBA may gain a lot. The user would be more interested in completely other kind of information. In between, some information is relevant to both.</p>
<p>Say we were managing an on-line store. We want to monitor the health of the database. But the health of the database is inseparable from the health of the application. I mean, having little to no disk usage is fine, unless... something is wrong with the application, which leads to no new purchases.</p>
<p>And so a user would be interested in monitoring the number of purchases per hour, or the time passed since last successful purchase. This kind of data can only be generated by a user's specific query. Looking at the charts, the user would then feel safer and confident in the wellness of his store app.</p>
<p><span id="more-2008"></span>But let's dig further. We want the store's website to provide with good response. In particular, the query which returns the items in a customer's cart must react quickly. Our user would not only want to see that purchases get along, but also that page load times (as in our example) are quick for those critical parts. And so a user should be able to monitor the <em>time</em> it took to execute a given query.</p>
<p>It can be of further interest to know how many times per second a given query is executed. This part is not easily done on the server side, and requires the user's cooperation (or else we must analyze the general log, sniff, or set up a proxy). If the user is willing, she can log to some table each time she executes a certain query. Then we're back to monitoring a regular table, as with the first example.</p>
<p>It is also possible to monitor for a query's execution plan. Is it full scan? How many rows are expected? But given that we can monitor the time it took to execute a query, I'm not sure this is useful. If everything runs fast enough -- who cares about <em>how</em> it executes?</p>
<p>Some of the above can be monitored on an altogether higher level: if  we're talking about some web application, then we can use our Apache logs to determine load time for pages, or number of requests to our "cart items" page. But not always do we work with web servers, and we may be interested in checking the specific queries behind the scenes.</p>
<h4>Summary</h4>
<p>Custom monitoring can include:</p>
<ul>
<li>User defined queries (number of concurrent visitors; count of successful operations per second; number of rows per given table or condition; ...)</li>
<li>Execution time for user defined queries (time it takes to return cart items; find rows matching condition; sort a table; ...)</li>
<li>Number of executions for a given query, per second.</li>
</ul>
<p>I intend to incorporate the above into <em>mycheckpoint</em> as part of its standard monitoring scheme.</p>
<p>Please share your thought below.</p>
]]></content:encoded>
			<wfw:commentRss>http://code.openark.org/blog/mysql/things-to-monitor-on-mysql-the-users-perspective/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

