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.
« Previous 1 2 3 Next »
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
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.
News
-
Endless OS 6 has Arrived
After more than a year since the last update, the latest release of Endless OS is now available for general usage.
-
Fedora Asahi 40 Remix Available for Macs with Apple Silicon
If you've been anticipating KDE's Plasma 6 for your Apple Silicon-powered Mac, then you're in luck.
-
Red Hat Adds New Deployment Option for Enterprise Linux Platforms
Red Hat has re-imagined enterprise Linux for an AI future with Image Mode.
-
OSJH and LPI Release 2024 Open Source Pros Job Survey Results
See what open source professionals look for in a new role.
-
Proton 9.0-1 Released to Improve Gaming with Steam
The latest release of Proton 9 adds several improvements and fixes an issue that has been problematic for Linux users.
-
So Long Neofetch and Thanks for the Info
Today is a day that every Linux user who enjoys bragging about their system(s) will mourn, as Neofetch has come to an end.
-
Ubuntu 24.04 Comes with a “Flaw"
If you're thinking you might want to upgrade from your current Ubuntu release to the latest, there's something you might want to consider before doing so.
-
Canonical Releases Ubuntu 24.04
After a brief pause because of the XZ vulnerability, Ubuntu 24.04 is now available for install.
-
Linux Servers Targeted by Akira Ransomware
A group of bad actors who have already extorted $42 million have their sights set on the Linux platform.
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.