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
-
Juno Computers Launches Another Linux Laptop
If you're looking for a powerhouse laptop that runs Ubuntu, the Juno Computers Neptune 17 v6 should be on your radar.
-
ZorinOS 17.1 Released, Includes Improved Windows App Support
If you need or desire to run Windows applications on Linux, there's one distribution intent on making that easier for you and its new release further improves that feature.
-
Linux Market Share Surpasses 4% for the First Time
Look out Windows and macOS, Linux is on the rise and has even topped ChromeOS to become the fourth most widely used OS around the globe.
-
KDE’s Plasma 6 Officially Available
KDE’s Plasma 6.0 "Megarelease" has happened, and it's brimming with new features, polish, and performance.
-
Latest Version of Tails Unleashed
Tails 6.0 is based on Debian 12 and includes GNOME 43.
-
KDE Announces New Slimbook V with Plenty of Power and KDE’s Plasma 6
If you're a fan of KDE Plasma, you'll be thrilled to hear they've announced a new Slimbook with an AMD CPU and the latest version of KDE Plasma desktop.
-
Monthly Sponsorship Includes Early Access to elementary OS 8
If you want to get a glimpse of what's in the pipeline for elementary OS 8, just set up a monthly sponsorship to help fund its continued existence.
-
DebConf24 to be Held in South Korea
Busan will be the location of the latest DebConf running July 28 through August 4
-
Fedora Unleashes Atomic Desktops
Fedora has combined its solid distribution with rpm-ostree system to make it possible to deliver a new family of Fedora spins, called Fedora Atomic Desktops.
-
Bootloader Vulnerability Affects Nearly All Linux Distributions
The developers of shim have released a version to fix numerous security flaws, including one that could enable remote control execution of malicious code under certain circumstances.