|
| 1 | +/* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
| 2 | +
|
| 3 | + This program is free software; you can redistribute it and/or modify |
| 4 | + it under the terms of the GNU General Public License as published by |
| 5 | + the Free Software Foundation; version 2 of the License. |
| 6 | +
|
| 7 | + This program is distributed in the hope that it will be useful, |
| 8 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | + GNU General Public License for more details. |
| 11 | +
|
| 12 | + You should have received a copy of the GNU General Public License |
| 13 | + along with this program; if not, write to the Free Software |
| 14 | + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ |
| 15 | + |
| 16 | +/* |
| 17 | + * View: host_summary |
| 18 | + * |
| 19 | + * Summarizes statement activity, file IO and connections by host. |
| 20 | + * |
| 21 | + * mysql> select * from host_summary; |
| 22 | + * +------+------------+-------------------+-----------------------+-------------+----------+-----------------+---------------------+-------------------+--------------+ |
| 23 | + * | host | statements | statement_latency | statement_avg_latency | table_scans | file_ios | file_io_latency | current_connections | total_connections | unique_users | |
| 24 | + * +------+------------+-------------------+-----------------------+-------------+----------+-----------------+---------------------+-------------------+--------------+ |
| 25 | + * | hal1 | 2924 | 00:03:59.53 | 81.92 ms | 82 | 54702 | 55.61 s | 1 | 1 | 1 | |
| 26 | + * +------+------------+-------------------+-----------------------+-------------+----------+-----------------+---------------------+-------------------+--------------+ |
| 27 | + * |
| 28 | + */ |
| 29 | + |
| 30 | +CREATE OR REPLACE |
| 31 | + ALGORITHM = TEMPTABLE |
| 32 | + DEFINER = 'root'@'localhost' |
| 33 | + SQL SECURITY INVOKER |
| 34 | +VIEW host_summary ( |
| 35 | + host, |
| 36 | + statements, |
| 37 | + statement_latency, |
| 38 | + statement_avg_latency, |
| 39 | + table_scans, |
| 40 | + file_ios, |
| 41 | + file_io_latency, |
| 42 | + current_connections, |
| 43 | + total_connections, |
| 44 | + unique_hosts |
| 45 | +) AS |
| 46 | +SELECT accounts.host, |
| 47 | + SUM(stmt.total) AS statements, |
| 48 | + sys.format_time(SUM(stmt.total_latency)) AS statement_latency, |
| 49 | + sys.format_time(SUM(stmt.total_latency) / SUM(stmt.total)) AS statement_avg_latency, |
| 50 | + SUM(stmt.full_scans) AS table_scans, |
| 51 | + SUM(io.ios) AS file_ios, |
| 52 | + sys.format_time(SUM(io.io_latency)) AS file_io_latency, |
| 53 | + SUM(accounts.current_connections) AS current_connections, |
| 54 | + SUM(accounts.total_connections) AS total_connections, |
| 55 | + COUNT(DISTINCT accounts.user) AS unique_users |
| 56 | + FROM performance_schema.accounts |
| 57 | + LEFT JOIN sys.x$host_summary_by_statement_latency AS stmt ON accounts.host = stmt.host |
| 58 | + LEFT JOIN sys.x$host_summary_by_file_io AS io ON accounts.host = io.host |
| 59 | + WHERE accounts.host IS NOT NULL |
| 60 | + GROUP BY accounts.host; |
| 61 | + |
| 62 | +/* |
| 63 | + * View: x$host_summary |
| 64 | + * |
| 65 | + * Summarizes statement activity, file IO and connections by host. |
| 66 | + * |
| 67 | + * mysql> select * from x$host_summary; |
| 68 | + * +------+------------+-------------------+-----------------------+-------------+----------+-----------------+---------------------+-------------------+--------------+ |
| 69 | + * | host | statements | statement_latency | statement_avg_latency | table_scans | file_ios | file_io_latency | current_connections | total_connections | unique_users| |
| 70 | + * +------+------------+-------------------+-----------------------+-------------+----------+-----------------+---------------------+-------------------+--------------+ |
| 71 | + * | hal | 2925 | 239577283481000 | 81906763583.2479 | 83 | 54709 | 55605611965150 | 1 | 1 | 1 | |
| 72 | + * +------+------------+-------------------+-----------------------+-------------+----------+-----------------+---------------------+-------------------+--------------+ |
| 73 | + * |
| 74 | + */ |
| 75 | + |
| 76 | +CREATE OR REPLACE |
| 77 | + ALGORITHM = TEMPTABLE |
| 78 | + DEFINER = 'root'@'localhost' |
| 79 | + SQL SECURITY INVOKER |
| 80 | +VIEW x$host_summary ( |
| 81 | + host, |
| 82 | + statements, |
| 83 | + statement_latency, |
| 84 | + statement_avg_latency, |
| 85 | + table_scans, |
| 86 | + file_ios, |
| 87 | + file_io_latency, |
| 88 | + current_connections, |
| 89 | + total_connections, |
| 90 | + unique_hosts |
| 91 | +) AS |
| 92 | +SELECT accounts.host, |
| 93 | + SUM(stmt.total) AS statements, |
| 94 | + SUM(stmt.total_latency) AS statement_latency, |
| 95 | + SUM(stmt.total_latency) / SUM(stmt.total) AS statement_avg_latency, |
| 96 | + SUM(stmt.full_scans) AS table_scans, |
| 97 | + SUM(io.ios) AS file_ios, |
| 98 | + SUM(io.io_latency) AS file_io_latency, |
| 99 | + SUM(accounts.current_connections) AS current_connections, |
| 100 | + SUM(accounts.total_connections) AS total_connections, |
| 101 | + COUNT(DISTINCT accounts.user) AS unique_users |
| 102 | + FROM performance_schema.accounts |
| 103 | + LEFT JOIN sys.x$host_summary_by_statement_latency AS stmt ON accounts.host = stmt.host |
| 104 | + LEFT JOIN sys.x$host_summary_by_file_io AS io ON accounts.host = io.host |
| 105 | + WHERE accounts.host IS NOT NULL |
| 106 | + GROUP BY accounts.host; |
0 commit comments