Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit f965014

Browse files
Merge pull request #91 from JesperWisborgKrogh/dev/remove_metrics_56
Changing to metrics_56.sql is only used for MySQl 5.6 and will have the name metrics for all versions. This can be done as 5.7.9+ will support performance_schema.global_status for all configurations. Updated diagnostics() to always use metrics except when performance_schema = OFF in 5.7 as metrics requires the Performance_Schema engine to be available in 5.7.
2 parents 339d268 + 434f3fc commit f965014

File tree

8 files changed

+68
-60
lines changed

8 files changed

+68
-60
lines changed

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,22 +1303,19 @@ mysql> select * from memory_global_total;
13031303
+-----------------+
13041304
```
13051305

1306-
#### metrics / metrics_56
1306+
#### metrics
13071307

13081308
##### Description
13091309

13101310
Creates a union of the following information:
13111311

1312-
* performance_schema.global_status (information_schema.GLOBAL_STATUS for metrics_56)
1312+
* performance_schema.global_status (information_schema.GLOBAL_STATUS in MySQL 5.6)
13131313
* information_schema.INNODB_METRICS
1314-
* Performance Schema global memory usage information
1314+
* Performance Schema global memory usage information (only in MySQL 5.7)
13151315
* Current time
13161316

1317-
The difference between the metrics and the metrics_56 views are whether the global status is taken from performance_schema.global_status instead of
1318-
from the Information Schema. Use the metrics view if the MySQL version is 5.6, 5.7.5 and earlier, or 5.7.6-5.7.8 with show_compatibility_56 = OFF. Otherwise use metrics_56.
1319-
See also https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_show_compatibility_56
1320-
1321-
In MySQL 5.7.6 and later the metrics_56 view will generate a warning that INFORMATION_SCHEMA.GLOBAL_STATUS is deprecated.
1317+
In MySQL 5.7 it is required that performance_schema = ON, though there is no requirements to which
1318+
instruments and consumers that are enabled. See also the description of the Enabled column below.
13221319

13231320
For view has the following columns:
13241321

@@ -4254,7 +4251,7 @@ Query OK, 0 rows affected (0.00 sec)
42544251
Create a report of the current status of the server for diagnostics purposes. Data collected includes (some items depends on versions and settings):
42554252
42564253
* The GLOBAL VARIABLES
4257-
* Several sys schema views including metrics or metrics_56
4254+
* Several sys schema views including metrics or equivalent (depending on version and settings)
42584255
* Queries in the 95th percentile
42594256
* Several ndbinfo views for MySQL Cluster
42604257
* Replication (both master and slave) information.
@@ -4270,10 +4267,14 @@ Some of the sys schema views are calculated as initial (optional), overall, delt
42704267
* The delta view is the difference from the beginning to the end. Note that for min and max values
42714268
they are simply the min or max value from the end view respectively, so does not necessarily reflect
42724269
the minimum/maximum value in the monitored period.
4273-
Note: except for the metrics/metrics_56 views the delta is only calculation between the first and last outputs.
4270+
Note: except for the metrics view the delta is only calculation between the first and last outputs.
42744271
42754272
Requires the SUPER privilege for "SET sql_log_bin = 0;".
42764273
4274+
Versions supported:
4275+
* MySQL 5.6: 5.6.10 and later
4276+
* MySQL 5.7: 5.7.9 and later
4277+
42774278
Some configuration options are supported:
42784279
42794280
* sys.diagnostics.allow_i_s_tables

mysql-test/suite/sysschema/r/all_sys_objects_exist.result

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ memory_by_user_by_current_bytes
2222
memory_global_by_current_bytes
2323
memory_global_total
2424
metrics
25-
metrics_56
2625
processlist
2726
ps_check_lost_instrumentation
2827
schema_auto_increment_columns

mysql-test/suite/sysschema/r/v_metrics.result

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,3 @@ Variable_value text YES NULL
55
Type varchar(210) YES NULL
66
Enabled varchar(7) NO
77
SELECT * FROM sys.metrics;
8-
DESC sys.metrics_56;
9-
Field Type Null Key Default Extra
10-
Variable_name varchar(193) YES NULL
11-
Variable_value text YES NULL
12-
Type varchar(210) YES NULL
13-
Enabled varchar(7) NO
14-
SELECT * FROM sys.metrics_56;

mysql-test/suite/sysschema/t/v_metrics.test

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,3 @@ DESC sys.metrics;
1010
--disable_result_log
1111
SELECT * FROM sys.metrics;
1212
--enable_result_log
13-
14-
15-
# Ensure structure changes don't slip in
16-
DESC sys.metrics_56;
17-
18-
# Make sure view select does not error, but ignore results
19-
--disable_result_log
20-
SELECT * FROM sys.metrics_56;
21-
--enable_result_log
22-

procedures/diagnostics.sql

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ CREATE DEFINER='root'@'localhost' PROCEDURE diagnostics (
2828
Create a report of the current status of the server for diagnostics purposes. Data collected includes (some items depends on versions and settings):
2929
3030
* The GLOBAL VARIABLES
31-
* Several sys schema views including metrics or metrics_56
31+
* Several sys schema views including metrics or equivalent (depending on version and settings)
3232
* Queries in the 95th percentile
3333
* Several ndbinfo views for MySQL Cluster
3434
* Replication (both master and slave) information.
@@ -44,10 +44,14 @@ CREATE DEFINER='root'@'localhost' PROCEDURE diagnostics (
4444
* The delta view is the difference from the beginning to the end. Note that for min and max values
4545
they are simply the min or max value from the end view respectively, so does not necessarily reflect
4646
the minimum/maximum value in the monitored period.
47-
Note: except for the metrics/metrics_56 views the delta is only calculation between the first and last outputs.
47+
Note: except for the metrics views the delta is only calculation between the first and last outputs.
4848
4949
Requires the SUPER privilege for "SET sql_log_bin = 0;".
5050
51+
Versions supported:
52+
* MySQL 5.6: 5.6.10 and later
53+
* MySQL 5.7: 5.7.9 and later
54+
5155
Parameters
5256
-----------
5357
@@ -108,7 +112,7 @@ CREATE DEFINER='root'@'localhost' PROCEDURE diagnostics (
108112
BEGIN
109113
DECLARE v_start, v_runtime, v_iter_start, v_sleep DECIMAL(20,2) DEFAULT 0.0;
110114
DECLARE v_has_innodb, v_has_ndb, v_has_ps, v_has_replication, v_has_ps_replication VARCHAR(8) CHARSET utf8 DEFAULT 'NO';
111-
DECLARE v_this_thread_enabled, v_has_ps_vars ENUM('YES', 'NO');
115+
DECLARE v_this_thread_enabled, v_has_ps_vars, v_has_metrics ENUM('YES', 'NO');
112116
DECLARE v_table_name, v_banner VARCHAR(64) CHARSET utf8;
113117
DECLARE v_sql_status_summary_select, v_sql_status_summary_delta, v_sql_status_summary_from, v_no_delta_names TEXT;
114118
DECLARE v_output_time, v_output_time_prev DECIMAL(20,3) UNSIGNED;
@@ -295,17 +299,22 @@ BEGIN
295299
IF(@@master_info_repository = 'TABLE', IF((SELECT COUNT(*) FROM mysql.slave_master_info) > 0, 'YES', 'NO'),
296300
IF(@@relay_log_info_repository = 'TABLE', IF((SELECT COUNT(*) FROM mysql.slave_relay_log_info) > 0, 'YES', 'NO'),
297301
'MAYBE'))),
302+
v_has_metrics = IF(v_has_ps = 'YES' OR (sys.version_major() = 5 AND sys.version_minor() = 6), 'YES', 'NO'),
298303
v_has_ps_vars = 'NO';
304+
299305
-- 5.7.7 introduced the possibility to get SHOW [GLOBAL|SESSION] VARIABLES and SHOW [GLOBAL|SESSION] STATUS
300306
-- from the Performance Schema. But it's optional whether it's enabled.
301-
-- Note that @@global.show_compatibility_56 = OFF will only actually work if the Performance Schema is enabled,
307+
-- 5.7.9 changes so the Performance Schema tables always work.
308+
-- Note that @@global.show_compatibility_56 = OFF will only actually work if the Performance Schema is enabled in <=5.7.8,
302309
-- however except overriding the global value there is nothing that can be done about it.
303310
-- v_has_ps_vars defaults to NO
304311
/*!50707 SET v_has_ps_vars = IF(@@global.show_compatibility_56, 'NO', 'YES');*/
312+
/*!50709 SET v_has_ps_vars = 'YES';*/
305313

306314
IF (@sys.debug = 'ON') THEN
307315
SELECT v_has_innodb AS 'Has_InnoDB', v_has_ndb AS 'Has_NDBCluster',
308316
v_has_ps AS 'Has_Performance_Schema', v_has_ps_vars AS 'Has_P_S_SHOW_Variables',
317+
v_has_metrics AS 'Has_metrics',
309318
v_has_ps_replication 'AS Has_P_S_Replication', v_has_replication AS 'Has_Replication';
310319
END IF;
311320

@@ -737,11 +746,42 @@ BEGIN
737746
PRIMARY KEY (Type, Variable_name)
738747
) ENGINE = InnoDB DEFAULT CHARSET=utf8'));
739748

740-
SET @sys.diagnostics.sql = CONCAT(
749+
IF (v_has_metrics) THEN
750+
SET @sys.diagnostics.sql = CONCAT(
741751
'INSERT INTO ', v_table_name,
742-
' SELECT Variable_name, REPLACE(Variable_value, ''\n'', ''\\\\n'') AS Variable_value, Type, Enabled FROM ',
743-
IF(v_has_ps_vars = 'YES', 'sys.metrics', 'sys.metrics_56')
744-
);
752+
' SELECT Variable_name, REPLACE(Variable_value, ''\n'', ''\\\\n'') AS Variable_value, Type, Enabled FROM sys.metrics'
753+
);
754+
ELSE
755+
-- 5.7+ and the Performance Schema disabled. Use information_schema.GLOBAL_STATUS instead like in 5.6.
756+
SET @sys.diagnostics.sql = CONCAT(
757+
'INSERT INTO ', v_table_name,
758+
'(SELECT LOWER(VARIABLE_NAME) AS Variable_name, REPLACE(VARIABLE_VALUE, ''\n'', ''\\\\n'') AS Variable_value,
759+
''Global Status'' AS Type, ''YES'' AS Enabled
760+
FROM performance_schema.global_status
761+
) UNION ALL (
762+
SELECT NAME AS Variable_name, COUNT AS Variable_value,
763+
CONCAT(''InnoDB Metrics - '', SUBSYSTEM) AS Type,
764+
IF(STATUS = ''enabled'', ''YES'', ''NO'') AS Enabled
765+
FROM information_schema.INNODB_METRICS
766+
-- Deduplication - some variables exists both in GLOBAL_STATUS and INNODB_METRICS
767+
-- Keep the one from GLOBAL_STATUS as it is always enabled and it''s more likely to be used for existing tools.
768+
WHERE NAME NOT IN (
769+
''lock_row_lock_time'', ''lock_row_lock_time_avg'', ''lock_row_lock_time_max'', ''lock_row_lock_waits'',
770+
''buffer_pool_reads'', ''buffer_pool_read_requests'', ''buffer_pool_write_requests'', ''buffer_pool_wait_free'',
771+
''buffer_pool_read_ahead'', ''buffer_pool_read_ahead_evicted'', ''buffer_pool_pages_total'', ''buffer_pool_pages_misc'',
772+
''buffer_pool_pages_data'', ''buffer_pool_bytes_data'', ''buffer_pool_pages_dirty'', ''buffer_pool_bytes_dirty'',
773+
''buffer_pool_pages_free'', ''buffer_pages_created'', ''buffer_pages_written'', ''buffer_pages_read'',
774+
''buffer_data_reads'', ''buffer_data_written'', ''file_num_open_files'',
775+
''os_log_bytes_written'', ''os_log_fsyncs'', ''os_log_pending_fsyncs'', ''os_log_pending_writes'',
776+
''log_waits'', ''log_write_requests'', ''log_writes'', ''innodb_dblwr_writes'', ''innodb_dblwr_pages_written'', ''innodb_page_size'')
777+
) UNION ALL (
778+
SELECT ''NOW()'' AS Variable_name, NOW(3) AS Variable_value, ''System Time'' AS Type, ''YES'' AS Enabled
779+
) UNION ALL (
780+
SELECT ''UNIX_TIMESTAMP()'' AS Variable_name, ROUND(UNIX_TIMESTAMP(NOW(3)), 3) AS Variable_value, ''System Time'' AS Type, ''YES'' AS Enabled
781+
)
782+
ORDER BY Type, Variable_name;'
783+
);
784+
END IF;
745785
CALL sys.execute_prepared_stmt(@sys.diagnostics.sql);
746786

747787
-- Prepare the query to retrieve the summary
@@ -778,10 +818,10 @@ BEGIN
778818
SET v_output_time_prev = v_output_time;
779819

780820
IF (@sys.diagnostics.include_raw = 'ON') THEN
781-
IF (v_has_ps_vars = 'YES') THEN
821+
IF (v_has_metrics) THEN
782822
SELECT 'SELECT * FROM sys.metrics' AS 'The following output is:';
783823
ELSE
784-
SELECT 'SELECT * FROM sys.metrics_56' AS 'The following output is:';
824+
SELECT 'sys.metrics equivalent' AS 'The following output is:';
785825
END IF;
786826
-- Ensures that the output here is the same as the one used in the status summary at the end
787827
CALL sys.execute_prepared_stmt(CONCAT('SELECT Type, Variable_name, Enabled, Variable_value FROM ', v_table_name, ' ORDER BY Type, Variable_name'));
@@ -1034,10 +1074,10 @@ BEGIN
10341074
DROP TEMPORARY TABLE tmp_sys_views_delta;
10351075
END IF;
10361076

1037-
IF (v_has_ps_vars = 'YES') THEN
1077+
IF (v_has_metrics) THEN
10381078
SELECT 'SELECT * FROM sys.metrics' AS 'The following output is:';
10391079
ELSE
1040-
SELECT 'SELECT * FROM sys.metrics_56' AS 'The following output is:';
1080+
SELECT 'sys.metrics equivalent' AS 'The following output is:';
10411081
END IF;
10421082
CALL sys.execute_prepared_stmt(
10431083
CONCAT(v_sql_status_summary_select, v_sql_status_summary_delta, ', Type, s1.Enabled', v_sql_status_summary_from,

sys_57.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ SOURCE ./views/p_s/waits_global_by_latency.sql
146146
SOURCE ./views/p_s/x_waits_global_by_latency.sql
147147

148148
SOURCE ./views/p_s/metrics.sql
149-
SOURCE ./views/p_s/metrics_56.sql
150149

151150
SOURCE ./views/p_s/processlist_57.sql
152151
SOURCE ./views/p_s/x_processlist_57.sql

views/p_s/metrics.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
-- along with this program; if not, write to the Free Software
1414
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1515

16+
-- IMPORTANT
17+
-- If you update this view, also update the "5.7+ and the Performance Schema disabled"
18+
-- query in procedures/diagnostics.sql
1619

1720
-- View: metrics
1821
--

views/p_s/metrics_56.sql

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1515

1616

17-
-- View: metrics_56
17+
-- View: metrics
1818
--
1919
-- Creates a union of the following information:
2020
--
@@ -70,8 +70,6 @@
7070
-- | trx_rw_commits | 0 ...| InnoDB Metrics - transaction | NO |
7171
-- | trx_undo_slots_cached | 0 ...| InnoDB Metrics - transaction | NO |
7272
-- | trx_undo_slots_used | 0 ...| InnoDB Metrics - transaction | NO |
73-
-- | memory_current_allocated | 138244216 ...| Performance Schema | PARTIAL |
74-
-- | memory_total_allocated | 138244216 ...| Performance Schema | PARTIAL |
7573
-- | NOW() | 2015-05-31 13:27:50.382 ...| System Time | YES |
7674
-- | UNIX_TIMESTAMP() | 1433042870.382 ...| System Time | YES |
7775
-- +-----------------------------------------------+-------------------------...+--------------------------------------+---------+
@@ -81,7 +79,7 @@ CREATE OR REPLACE
8179
ALGORITHM = TEMPTABLE
8280
DEFINER = 'root'@'localhost'
8381
SQL SECURITY INVOKER
84-
VIEW metrics_56 (
82+
VIEW metrics (
8583
Variable_name,
8684
Variable_value,
8785
Type,
@@ -106,22 +104,7 @@ SELECT NAME AS Variable_name, COUNT AS Variable_value,
106104
'buffer_data_reads', 'buffer_data_written', 'file_num_open_files',
107105
'os_log_bytes_written', 'os_log_fsyncs', 'os_log_pending_fsyncs', 'os_log_pending_writes',
108106
'log_waits', 'log_write_requests', 'log_writes', 'innodb_dblwr_writes', 'innodb_dblwr_pages_written', 'innodb_page_size')
109-
) /*!50702
110-
-- memory instrumentation available in 5.7.2 and later
111-
UNION ALL (
112-
SELECT 'memory_current_allocated' AS Variable_name, SUM(CURRENT_NUMBER_OF_BYTES_USED) AS Variable_value, 'Performance Schema' AS Type,
113-
IF((SELECT COUNT(*) FROM performance_schema.setup_instruments WHERE NAME LIKE 'memory/%' AND ENABLED = 'YES') = 0, 'NO',
114-
IF((SELECT COUNT(*) FROM performance_schema.setup_instruments WHERE NAME LIKE 'memory/%' AND ENABLED = 'YES') = (SELECT COUNT(*) FROM performance_schema.setup_instruments WHERE NAME LIKE 'memory/%'), 'YES',
115-
'PARTIAL')) AS Enabled
116-
FROM performance_schema.memory_summary_global_by_event_name
117107
) UNION ALL (
118-
SELECT 'memory_total_allocated' AS Variable_name, SUM(SUM_NUMBER_OF_BYTES_ALLOC) AS Variable_value, 'Performance Schema' AS Type,
119-
IF((SELECT COUNT(*) FROM performance_schema.setup_instruments WHERE NAME LIKE 'memory/%' AND ENABLED = 'YES') = 0, 'NO',
120-
IF((SELECT COUNT(*) FROM performance_schema.setup_instruments WHERE NAME LIKE 'memory/%' AND ENABLED = 'YES') = (SELECT COUNT(*) FROM performance_schema.setup_instruments WHERE NAME LIKE 'memory/%'), 'YES',
121-
'PARTIAL')) AS Enabled
122-
FROM performance_schema.memory_summary_global_by_event_name
123-
) */
124-
UNION ALL (
125108
SELECT 'NOW()' AS Variable_name, NOW(3) AS Variable_value, 'System Time' AS Type, 'YES' AS Enabled
126109
) UNION ALL (
127110
SELECT 'UNIX_TIMESTAMP()' AS Variable_name, ROUND(UNIX_TIMESTAMP(NOW(3)), 3) AS Variable_value, 'System Time' AS Type, 'YES' AS Enabled

0 commit comments

Comments
 (0)