Saturday, March 7, 2020

How To Monitor MySQL With dim_STAT

Monitoring a database is a critical mission: collecting information over time allows tracking how's behaving certain instance in response to a determined workload. There are several solution on the market, and MySQL offers its own solution in the Enterprise Edition, MySQL Enterprise Monitor (MEM). Today I'd like to remember that there's also another nice solution that is free, and designed by MySQL performance architect, Dimitri Kravtchuk (hence not to be considered as an Oracle MySQL solution, not supported and "as is"). I'm talking about dim_STAT. dim_STAT has a slightly different purpose than MEM as it is specialized to make some low level analysis of the impact of the workload on our MySQL Server instance (e.g. can profile mysqld process), and above all, permits offline metrics captures.

Extensive instructions to setup, configure and use dim_STAT are presented here. In this post I will share a practical summary of what I did to set it up. First of all it's worth clarifying that dim_STAT is composed of a server, dim_STAT-Server, and allows two modalities: online and offline.
  1. Online: can monitor live instances (STAT-service) from multiple hosts
  2. Offline: can collect metrics for later analysis (EasySTAT), useful for instances that are not accessible e.g. behind a firewall
Here's a brief recap of the architecture: STAT-service is the remote Agent that monitors the instance and delivers metrics back to a backend, which in turn stores them into an own MySQL Server for later processing. The web interface allows configuration and it's the main entry point to retrieve data, make graphs and in general consult captured data. Following picture summarises the architecture.

In this post I'll explore the offline analysis: this is using EasySTAT. 


dim_STAT-v90-linux-x64.tgz here's the main package
WebX_apps-v90-u19-12.tgz the upgrade package to apply on top of the main install
STATsrv-v5-Linux-x64-mysql.tgz includes EasySTAT tool, to allow data collection "offline"

There are also packages for macOS (which I will use in this post).


Once uncompressed the main package dim_STAT-v90-linux-x64.tgz, run as root. This will prompt different choices, like paths for install, user and group to run processes, MySQL (if running other MySQL instance on the same host, specify a port) and STAT-service port.
If everything is correct, installation will finalise with:

** =========================================================================
** You can start dim_STAT-Server now from /opt/packages/ADMIN:
** # /opt/packages/ADMIN/dim_STAT-Server start
** NOTE: for the very first start you'll need to type "start-force"
** (instead of simple "start" command)
** and access homepage via Web browser - http://mortensi:80
** To collect stats from any Solaris, Linux or MacOSX machines just
** install & start on them a corresponding [STAT-service] package...
** Enjoy! ;-)
** -Dimitri
** =========================================================================


After installation, it is possible to apply the latest patch. Uncompress WebX_apps-v90-u19-12.tgz and then copy its content over /opt/WebX/apps. Patching is hot, so can be done later as well, especially when dim_STAT-Server is already running.


In order to start dim_STAT-Server, this one command will do the job:

sh-3.2# /opt/packages/ADMIN/dim_STAT-Server start-force
================[ dim_STAT-Server: start-force ]================
* MySQL Database Server
=> Log output : /opt/packages/mysql/data/mysqld.log
=> Local socket: /opt/packages/mysql/data/mysql.sock
=> Admin Access: root# /opt/packages/mysql/bin/mysql -S /opt/packages/mysql/data/mysql.sock

200305 01:21:40 mysqld_safe Logging to '/opt/packages/mysql/data/mysqld.log'.
200305 01:21:40 mysqld_safe Starting mysqld daemon with databases from /opt/packages/mysql/data
** CHECK MySQL Server connection...
Starting HTTP server from: /opt/packages/httpd
================[ dim_STAT-Server: start-force -- done. ]================

This will start the minimal Apache web server and the internal MySQL instance used internally to store all the metrics that will be imported after the collection. Test the internal MySQL instance, can be accessed with:

sh-3.2# /opt/packages/mysql/bin/mysql -S /opt/packages/mysql/data/mysql.sock
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.5.53 Source distribution

Check the installation is successful by loading in your browser:

Collect metrics with EasySTAT

As mentioned, here I am interested in doing an offline audit of an instance, then I have used EasySTAT to capture metrics from the MySQL instance under observation. Instructions to deploy, configure, test and start the collection can be followed here:

I have tested a 8 hours collection of a MySQL 8 instance:

nohup ./ /opt/stats/data/ 10 8 "20200228-mortensi"

And once collection is started, make sure something is running in background:

[root@host1 bin]# ps aux | grep STAT
root 1448 0.0 0.0 6356 624 pts/1 S 18:51 0:00 /opt/stats/STATsrv/bin/vmstat 10
root 1450 0.0 0.0 5096 884 pts/1 S 18:51 0:00 /opt/stats/STATsrv/bin/WebX /opt/stats/STATsrv/bin/x.Timer -Timeout 10
root 1462 0.0 0.0 4328 764 pts/1 S 18:51 0:00 /opt/stats/STATsrv/bin/mpstat -P ALL 10
root 1463 0.0 0.0 5096 876 pts/1 S 18:51 0:00 /opt/stats/STATsrv/bin/WebX /opt/stats/STATsrv/bin

At the end of the collection, a gunzipped series of files will be collected under /opt/stats/data.

Import metrics with BatchLOAD

Now it's time to import data with BatchLOAD under the database (that back-end MySQL instance started by dim_STAT-Server).
First, configure file ./ (this is generated by EasySTAT under data folder collection: /opt/stats/data/2020_02_28.host1.12503/, this import procedure uses socket authentication, so make sure there is no conflicting "~/.my.cnf".
As an example, my header for will look like:


Read more details about BatchLoad. Three important things to keep in mind to complete import of metrics:

Prepare the database
A single collection done with EasySTAT will be imported into a dedicated MySQL schema. This must be created in advance and configured in I decided to call my schema "mortensi" (BASE=${BASE:=mortensi}). This schema must come prepared with all the tables beneath, and must be created from dim_STAT preferences panel, choosing a name under "Create a New Database".

Enable Add-Ons
Upgrade patch delivers several add-ons that must be installed. To the purpose, from main menu, browse to "Add-On STAT(s)" and install all new add-ons at the bottom of the page. Only after this operation it is convenient to import metrics into the system, so that all collected data will be stored and used, otherwise data collected by a more recent agent (EasySTAT or STAT-service) won't be imported and simply discarded. Important note: add-ons must be enabled for every new database created in the previous step!

Troubleshoot errors
If you are trying this import procedure, for one reason or another you will fail, then it's handy to refer to the sql.error error log to understand what's gone wrong. It's generated under the install directory chosen.

It is now possible to start the import with, which will log all the metrics imported, one by one:

*** START dim_STAT BatchLOAD
*** Collect ID: 1 Host: goldgate Command: ADD
* DTSET: 2020-02-28 20:52:11
* STAT: mysqlFILE_IO
* END [#359]
*** END BatchLOAD
*** Collect ID: 1

Generate reports

After all this effort, time to extract information from the data captured.
  1. Go to preferences and choose the default database, where this capture metrics were stored (mortensi, in the example followed)
  2. Go back to main menu and choose "Analyze". Documentation available here.
Choosing graphs to show, and also how many different metrics combinations, has a wide set of options to generate ad-hoc reports. For that, official online documentation and experimenting are the best ways to get the most out of this very interesting tool.

1 comment: