Tracking SQL statistics with ExtSQL

Configuration Options

More than 100 vars (data items) are available. Configure the ExtSQL server by describing which vars you are interested in tracking and how you want to collect data. For a more complete example, consider this string, which must be one line in the configuration file:

extsql_class_list=" user, max-50, time-60, units-m, (Com_select, Com_update), db, max-50, time-10, units-h, (Com_insert, Com_select, Com_update, Qcache_hits), host, max-5, time-3, units-d, (Com_select, Com_update, Slow_queries), server, max-5, time-3, units-d, (Questions, Qcache_hits)"

As with SHOW STATUS (in this case with historical data), the server will track information on four different classes: user, db, host, and cumulative server stats.

For each class, max- precedes the maximum number of instances of that class. time- precedes the number of historical time units to store, and units- designates the period of interest (m, minutes; h, hours; d, days). After the limits for each class, a comma-separated list of vars is included. The line starting with db is a directive to track a maximum of 50 dbs and record historical data for each of the last 10 hours. The vars addressed in the preceding command are inserts, selects, updates, and query cache hits.

SHOW STATISTICS Syntax

The goal for command syntax was to stay as close to standard SQL as possible. The syntax described here should look familiar, especially if you replace SHOW STATISTICS with SELECT. Listing 1 shows some ExtSQL usage examples.

Significantly different are LIKE, to match specific instances, and the new keyword HISTORY, to produce historical output. LIMIT operates differently if HISTORY is specified. Without HISTORY, it limits the number of results displayed. With HISTORY, it functions as a time limit.

SHOW STATISTICS ( * | Var list) FROM Class [LIKE 'Instance pattern']
[WHERE Var ( '<' | '>' | '=' ) num] [ORDER BY Var] [HISTORY] [LIMIT num]

For example, you can ask:

SHOW STATISTICS * FROM user LIKE '%joe%' WHERE Com_select > 500

In standard SQL, that would be:

SHOW STATISTICS * FROM user WHERE user LIKE '%joe%' AND Com_select > 500

LIKE is a separate clause in the syntax that matched just Class instances. For now, the syntax is limited in the WHERE clause, and ORDER BY is available if INFORMATION SCHEMA is supported in your base version of the ExtSQL server.

Listing 1

Usage Examples

The examples below show a cross section of ExtSQL commands and output.
## Show number of selects and inserts given by all users:
sql> SHOW STATISTICS Com_select, Com_insert, Questions FROM user;
+----------+-------------+-----------+------------+
| user     | Com_select  | Com_insert | Questions  |
+----------+-------------+-----------+------------+
| bandala  | 8302675     | 95973      | 23153940    |
| sandymao | 1702812     | 6205       | 3829023     |
| ponnetli | 24909       | 4784       | 95646       |
## Show number of selects, total queries, and updates made by all
## client hosts:
sql> SHOW STATISTICS Com_select, Questions, Com_update FROM host;
+-------------------+-------------+-----------+--------------+
| host               | Com_select   | Questions | Com_update    |
+-------------------+-------------+-----------+--------------+
| db2.adomain.com   | 17715223     | 44224076  | 4143634981    |
| lathe.adomain.com | 2738061      | 9743215   | 3913397495    |
| telkomadsl.co.za  | 195          | 5390       | 539604        |
## Show number of selects, total queries, and updates made by all
## users@client host with more than 10,000 queries:
sql> SHOW STATISTICS Com_select, Questions, Com_update FROM conuser
     WHERE Questions > 10000;
+----------------------------+-------------+-----------+------------+
| conuser   (user@host)       | Com_select  | Questions | Com_update  |
+--------- ------------------+-------------+-----------+------------+
| bandala@db2.adomain.com    | 8306726      | 23163320  | 3439850933  |
| sandymao@db2.adomain.com   | 1704040      |  3831803  | 3365501841  |
| ponnetli@taro.adomain.com  |   24920      |    95662  |  156529077  |
## Show number of selects, total queries, and updates to DB allison for
## the last three minutes with activity:
sql> SHOW STATISTICS Com_select, Questions, Com_update FROM db
     LIKE 'allison' HISTORY LIMIT 3;
+---------+-------------+------------+-----------+------------+
|      db  | minutes     | Com_select | Questions  | Com_update |
+---------+-------------+------------+-----------+------------+
| allison | 11/20 13:56 | 216         |     382     | 318343     |
| allison | 11/20 13:55 | 642         |    1618     | 1386347    |
| allison | 11/20 13:54 | 280         |     699     | 646855     |

Information Schema Syntax

Many of you are aware that INFORMATION SCHEMA is already part of the SQL standard, and its purpose is to make SQL databases more "self describing." The ExtSQL project already has an example working implementation for MySQL 5.0.x (see Listing 2).

Listing 2

INFORMATION_SCHEMA

mysql> use INFORMATION_SCHEMA;
mysql> SHOW TABLES;
  ## Note:  the additional tables configured by the DBA for ExtSQL are
  ## prefaced with 'EXTSTATS_'
| EXTSTATS_condb                        |
| EXTSTATS_conuser                      |
| EXTSTATS_db                           |
| EXTSTATS_host                         |
| EXTSTATS_server                       |
| EXTSTATS_user                         |
   ## End of added tables
mysql> SELECT user, minutes, Com_select, Questions FROM EXTSTATS_user
              WHERE TIMEDIFF(now(), minutes) < '10:00';
+---------+--------------------+------------+-----------+
| user    | minutes              | Com_select | Questions |
+---------+--------------------+------------+-----------+
| thebook | 2008-07-19 09:28:00 | 2           | 4          |
| thebook | 2008-07-19 09:27:00 | 3           | 3          |
| matt    | 2008-07-19 09:53:00 | 4           | 4          |
| matt    | 2008-07-19 09:52:00 | 0           | 1          |
## This makes the full syntax of the SQL parser available, BUT.... it
## exposes that data is recorded in a circular buffer by time interval
## (minutes in our example), with the time '0000-00-00' containing
## totals since server start.
mysql> SELECT user, minutes, Com_select, Questions FROM EXTSTATS_user
              WHERE user='thebook' LIMIT 5;
+---------+--------------------+------------+-----------+
| user    | minutes              | Com_select | Questions |
+---------+--------------------+------------+-----------+
| thebook | 2008-07-19 09:27:00 | 3           | 3         |
| thebook | 2008-07-19 09:25:00 | 2           | 73        |
| thebook | 2008-07-18 16:44:00 | 0           | 14        |

Server Performance

Performance was a primary design constraint on ExtSQL. With more and more memory available on servers, it made sense to store data in RAM while giving the database administrator complete control over how much memory would be allocated. This resulted in an average performance effect of about 5% – an acceptable number on most servers.

For a better understanding of performance statistics, consider how ExtSQL records and reports time. With the class definition user, max-50, time-10, units-h, ExtSQL will create a buffer that holds 11 time periods. The 0 buffer always holds cumulative numbers since server start and is the number displayed in the command SHOW STATISTICS * FROM user.

Historical activity is captured for 10-hour periods in a circular manner and only when activity occurs (e.g., start the server and 20 hours later enter):

SHOW STATISTICS * FROM user HISTORY

Assume user activity was recorded in each of the first 10 hours of server operation, and then only in the last five hours (i.e., a five-hour gap with no activity). Activity that occurred between server operation hours 5 and 10 is reported by the hour, then the last five hours. Each row is timestamped to the hour. With the command SHOW STATISTICS * FROM user, you would see just one line of cumulative totals for all 20 hours.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • systemd Tips

    Sure, you've heard about systemd, which is rapidly replacing the old System V init system as the go-to service management daemon for the Linux world. But what can you do with systemd really? We'll show you some tricks for improving security, managing processes, and analyzing boot times with systemd.

  • Liferay CMS

    Liferay is a powerful and easily customizable CMS that is ideal for community collaboration – once you get it configured.

  • Snort

    Search out hidden attacks with the Snort intrusion detection system.

  • Free Software Projects

    Even hardened nerds are often over-challenged by the less than intuitive field of statistics. Besides the theory, you need to know how to use the software that converts all the theory into a practical application.

  • VpsAdmin Manages OpenVZ Instances

    The developers of a Czech hosting company has released a Web interface for administering virtual servers under OpenVZ.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News