MySQL数据库类似AWR巡检报告信息脚本
【说明】
有时候需要提供巡检报告信息,按照html格式来取一些数据,根据https://www.modb.pro/db/633746(主要参考)来修改了一下格式及采集内容,如果需要个人修改,可以联系说明信息。
【包含内容】
System Statistics
Database Statistics
SQL Statistics
Replication Statistics
Initialization Parameters
Performance Statistics
Innodb Status
System Statistics
Host Disk
Host Memory
Cpu info
Iostat info
System Messages
Database Statistics
QPS
TPS
Top Schema
Top Table
Top Fage
Not Primary Key Table
Database Charset
Table Charset
Table Not Innodb
SQL Statistics
SQL ordered by Elapsed Time
SQL ordered by Lock Time
SQL ordered by Numrows
SQL ordered by Sent Rows
SQL ordered by Sort Rows
SQL ordered by Update Delete
SQL ordered by Disk Temp Table
SQL ordered by Not Ues Index
SQL ordered by Logic Read
SQL ordered by Big Trans
Replication Statistics
Replication Hosts
Replication Status
Initialization Parameters
Parameters Status
Performance Statistics
Parameters Status
Memory Info
Host Info
User Info
File IO Info
Wait Event Info
Statistics INFO
Statement INFO
Current Process Info
Innodb Status
【结果展示】
【使用方法】
创建一个xunjian_awr.sh文件,然后添加脚本内容,赋予执行权限;
执行:./xunjian_awr.sh MYSQL 10.0.0.xxx 3306 root 'xxxxxx' 建议使用数据库服务器运行,因为会采集主机的信息,centos主机采集数据,如果其他主机则修改对应的采集命令测试
报告文件指定了/root/CHECK_MYSQL_*
【脚本】
vim xunjian_awr.sh
#!/bin/bash
# slow_query_log = on
# Deadlock log parameters
# innodb_print_all_deadlocks=ON
# performance_schema=ON
# performance_schema_events_statements_history_long_size=1000000 #保留百万条 默认是1万条 根据自己内存来设定 先在测试库确定内存消耗量 类似ORACLE V$SQL
# performance_schema_digests_size=100000 #此参数类似ORACLE SQLAREA汇总的 设置10万不同SQL基本覆盖7天的量
# performance_schema_max_sql_text_length=255 #此参数是文本长度,默认值1024 注意它是TEXT_LENGTH X HISTORY_LONG_SIZ的乘积消耗内存,这里不需要看完整的SQL
# performance_schema_max_digest_length=255 #同上
# ./xunjian_awr.sh MYSQL 10.0.0.xxx 3306 root 'xxxxxx'
#================================================Declare Segment===============================================
DB_TYPE=$1
if [ "$DB_TYPE" != 'MYSQL' ]
then
echo "help: invalid database type"
echo "help: $0 <MYSQL> <IP> <PORT> <DB_USER> <DB_PWD>"
exit 1
fi
TARGET_DB_IP=$2
TARGET_DB_PROT=$3
TARGET_DB_USER=$4
TARGET_DB_PASS=$5
MYSQL_ERROR_LOG='/db/mysql/logs/mysqld.log'
CHECK_RESULT_FILE="/root/CHECK_MYSQL_${TARGET_DB_IP}_$(date +%Y%m%d-%H%M%S).html"
START_DATE=`date --date='7 day ago' '+%Y-%m-%d %H:00:00.000000'`
END_DATE=`date '+%Y-%m-%d %H:00:00.000000'`
##下面参数没有起作用不用改
CURN_DATE=$(date "+%Y-%m-%d %H:%M:%S")
SEVEN_DATE=$(date -d"7 day ago" +%Y-%m-%d)
#===============================================Fuction segments======================================================================
function Target_MysqlDB()
{
mysql -h $TARGET_DB_IP -P $TARGET_DB_PROT -u$TARGET_DB_USER -p$TARGET_DB_PASS --html -t -e "$*" >> ${CHECK_RESULT_FILE} 2>/dev/null
}
function SALVE_MysqlDB()
{
mysql -h $TARGET_DB_IP -P $TARGET_DB_PROT -u$TARGET_DB_USER -p$TARGET_DB_PASS -e "$*" 1>tmp_slave_status.txt 2>/dev/null
}
function OUTPUT_TITLE()
{
echo -e "<h3 class="awr" id="\"$1"\" >$1</h3>" >>${CHECK_RESULT_FILE} 2>/dev/null
}
function OUTPUT_TITLE_02()
{
echo -e "<h4 class="awr" id="\"$1"\" >$1</h4>" >>${CHECK_RESULT_FILE} 2>/dev/null
}
CREATE_HTML_HEAD()
{
echo -e '<html>
<head>
<meta charset="UTF-8">
<style type="text/css">
body {font:12px Courier New,Helvetica,sansserif; color:#336699; background:White;}
table {font:12px Consolas; color:Black; background:#FFFFCC; padding:1px; margin:0px 0px 0px 0px; cellspacing:0px;border-collapse:collapse; border: none;}
th.awrbg {font:bold 12pt Arial,Helvetica,Geneva,sans-serif; color:White; background:#336699;padding-left:4px; padding-right:4px;padding-bottom:2px}
td.awrc {font:12pt Arial,Helvetica,Geneva,sans-serif;color:black;background:#FFFFCC; vertical-align:top;}
td.awrnc {font:12pt Arial,Helvetica,Geneva,sans-serif;color:black;background:White;vertical-align:top;}
h1.awr {font:bold 24pt Arial,Helvetica,Geneva,sans-serif;color:#336699;background-color:White; margin-bottom:0pt;padding:0px 0px 0px 0px;}
h2.awr {font:bold 20pt Arial,Helvetica,Geneva,sans-serif;color:#336699;background-color:White;border-bottom:1px solid #cccc99;margin-top:0pt; margin-bottom:0pt;padding:0px 0px 0px 0px;}
h3.awr {font:bold 18pt Arial,Helvetica,Geneva,sans-serif;color:#336699;background-color:White;margin-top:4pt; margin-bottom:0pt;}
h4.awr {font:bold 10pt Arial,Helvetica,Geneva,sans-serif;color:black;background-color:White;border-top:0px solid #cccc99;margin-top:0pt; margin-bottom:0pt;padding:0px 0px 0px 0px;}
table tr:nth-child(even){ background-color: #FFFFCC; }
table tr:nth-child(odd){ background-color: White; }
</style>
</head>
<body>' >>${CHECK_RESULT_FILE} 2>/dev/null
echo -e " <h1 class="awr"> WORKLOAD REPOSITORY report for </h1> ">>${CHECK_RESULT_FILE}
echo -e "<br/>" >>${CHECK_RESULT_FILE}
echo -e " <h2 class="awr"> </h2> <p> ">>${CHECK_RESULT_FILE}
}
CREATE_HTML_END(){
echo -e "</body></html>" >>${CHECK_RESULT_FILE} 2>/dev/null
}
OUT_PUT_TABLE_HEAD(){
echo -e '<table width="" border="1" >' >>${CHECK_RESULT_FILE}
}
OUT_PUT_FILED() ##Field name of the table
{
th_str=`echo $1|awk 'BEGIN {FS=" "}''{i=1; while(i<=NF) {print "<th class='awrbg' scope="col"> "$i"</th>";i++}}'`
}
OUT_PUT_TITEL() ##Field row of table
{
OUT_PUT_FILED "$*"; echo -e "<tr> $th_str </tr>" >> ${CHECK_RESULT_FILE}
}
OUT_PUT_VAULES() ##Output the contents of the line
{
th_str=`echo $1|awk 'BEGIN{FS=" "}''{i=1; while(i<=NF) {print "<td scope="row" class='awrc'> "$i"</td>";i++}}'`
}
OUT_PUT_LINES()
{
OUT_PUT_VAULES "$*"; echo -e "<tr> $th_str </tr>" >>${CHECK_RESULT_FILE}
}
OUT_PUT_NEW_LINE()
{
echo -e " <br />">>${CHECK_RESULT_FILE}
}
OUT_PUT_TABLE_TAIL()
{
echo -e "</table>" >>${CHECK_RESULT_FILE}
OUT_PUT_NEW_LINE
}
OUT_PUT_LINES_LOG()
{
echo -e "<tr> <td scope="row" class='awrc'> $1</td></tr>" >>${CHECK_RESULT_FILE}
}
sar_cpu()
{
TITL="DATE: CPU %user %nice %system %iowait %steal %idle "
OUT_PUT_TITEL $TITL
for file in `ls -tr /var/log/sa/sa* | grep -v sar`
do
dat=`sar -f $file | head -n 1 | awk '{print $4}'`
INFO=$(echo -n $dat ; sar -f $file | grep -i Average | sed "s/Average://")
OUT_PUT_LINES ${INFO}
done
}
disk_info()
{
TITL="Filesystem Size Used Avail Use% Mountedon "
OUT_PUT_TITEL $TITL
mapfile -t lines < <(df -h | tail -n +2)
for line in "${lines[@]}"; do
OUT_PUT_LINES ${line}
done
}
iostat_info()
{
TITL="Device: rrqm/s wrqm/s r/s w/s rMB/s wMB/s avgrq-sz avgqu-sz await r_await w_await svctm %util"
OUT_PUT_TITEL $TITL
mapfile -t lines < <(iostat -x -m -d -t -p all -c 10 -d $(lsblk -d -o NAME | grep -v 'loop') 4)
for line in "${lines[@]}"; do
OUT_PUT_LINES ${line}
done
}
System_Messages_info()
{
TITL="System_Messages"
OUT_PUT_TITEL $TITL
mapfile -t lines < <(dmesg -T | tail -n 100)
for line in "${lines[@]}"; do
OUT_PUT_LINES ${line}
done
}
function Parse_salve_txt()
{
MASTER_UUID=$(cat tmp_slave_status.txt | grep -i "Master_UUID" |awk '{print $2}')
SLAVE_IO_STATE=$(cat tmp_slave_status.txt | grep -i "Slave_IO_State" |awk -F " " '{for (i=2;i<=NF;i++)printf("%s ", $i);print ""}')
READ_MASTER_POST=$(cat tmp_slave_status.txt | grep -i "Read_Master_Log_Pos" |awk '{print $2}')
Relay_Master_Log_File=$(cat tmp_slave_status.txt | grep -i "Relay_Master_Log_File"|awk '{print $2}')
EXEC_MASTER_POST=$(cat tmp_slave_status.txt | grep -i "Exec_Master_Log_Pos" |awk '{print $2}')
BEHIND_SECONDS=$(cat tmp_slave_status.txt | grep -i "Seconds_Behind_Master"|awk '{print $2}')
SLAVE_IO_RUNNING=$(cat tmp_slave_status.txt | grep -i "Slave_IO_Running" |awk '{print $2}')
SLAVE_SQL_RUNNING=$(cat tmp_slave_status.txt | grep -i "Slave_SQL_Running:" |awk '{print $2}')
REPLICATE_DO_DB=$(cat tmp_slave_status.txt | grep -i "Replicate_Do_DB" |awk '{print $2}')
SQLDELAY=$(cat tmp_slave_status.txt | grep -i "SQL_Delay" |awk '{print $2}')
SALVE_SQL_RUN_STATE=$(cat tmp_slave_status.txt | grep -i "Slave_SQL_Running_State" |awk -F " " '{for (i=2;i<=NF;i++)printf("%s ", $i);print ""}')
LAST_SQL_ERROR=$(cat tmp_slave_status.txt | grep -i "Last_IO_Errno"|awk '{print $2}')
LAST_IO_ERROR=$(cat tmp_slave_status.txt | grep -i "Last_SQL_Errno"|awk '{print $2}')
RETRIEVED_GTID=$(cat tmp_slave_status.txt | grep -i "retrieved_gtid_set" |awk -F " " '{for (i=2;i<=NF;i++)printf("%s ", $i);print ""}')
EXECUTED_GTID=$(cat tmp_slave_status.txt | grep -i "${MASTER_UUID}:" |grep -vi "retrieved_gtid_set")
SALVE_SQL_RUN_STATE=${SALVE_SQL_RUN_STATE// /_}
SLAVE_IO_STATE=${SLAVE_IO_STATE// /_}
}
##物理文件慢日志信息抓取
function SLOW_MysqlDB()
{
v_slow_log=`mysql -h $TARGET_DB_IP -P $TARGET_DB_PROT -u$TARGET_DB_USER -p$TARGET_DB_PASS -e "show variables like 'slow_query_log_file';" 2>/dev/null |grep slow_query_log_file|awk '{print $2}'`
if [ -f "$v_slow_log" ]; then
OUT_PUT_TABLE_HEAD
TITL="Message"
OUT_PUT_TITEL $TITL
tail -100 $v_slow_log| awk '{print "<tr> <th scope= class=\"awrc\" style=\"text-align:left;\" >", $0, "</th> </tr>";print "\n";}' >> ${CHECK_RESULT_FILE}
fi
}
##定义各个指标的子目录信息
Main_report_statistics_items=("System Statistics" "Database Statistics" "SQL Statistics" "Replication Statistics" "Initialization Parameters" "Performance Statistics" "Innodb Status")
function OUT_PUT_Main_report_Statistics() {
echo -e "<ul>" >> "${CHECK_RESULT_FILE}"
# 遍历数组,为每个元素生成一个列表项
for item in "${Main_report_statistics_items[@]}"; do
echo -e " <li><a href=\"#${item}\" style=\"color: brown;\"><b>${item}</b></a></li>" >> "${CHECK_RESULT_FILE}"
done
echo -e "</ul>" >> "${CHECK_RESULT_FILE}"
}
statistics_items=("Host Disk" "Host Memory" "Cpu info" "Iostat info" "System Messages")
function OUT_PUT_System_Statistics() {
echo -e "<ul>" >> "${CHECK_RESULT_FILE}"
# 遍历数组,为每个元素生成一个列表项
for item in "${statistics_items[@]}"; do
echo -e " <li><a href=\"#${item}\" style=\"color: brown;\"><b>${item}</b></a></li>" >> "${CHECK_RESULT_FILE}"
done
echo -e "</ul>" >> "${CHECK_RESULT_FILE}"
}
Database_statistics_items=("QPS" "TPS" "Top Schema" "Top Table" "Top Fage" "Not Primary Key Table" "Database Charset" "Table Charset" "Table Not Innodb")
function OUT_PUT_Database_Statistics() {
echo -e "<ul>" >> "${CHECK_RESULT_FILE}"
# 遍历数组,为每个元素生成一个列表项
for item in "${Database_statistics_items[@]}"; do
echo -e " <li><a href=\"#${item}\" style=\"color: brown;\"><b>${item}</b></a></li>" >> "${CHECK_RESULT_FILE}"
done
echo -e "</ul>" >> "${CHECK_RESULT_FILE}"
}
SQL_statistics_items=("SQL ordered by Elapsed Time" "SQL ordered by Lock Time" "SQL ordered by Numrows" "SQL ordered by Sent Rows" "SQL ordered by Sort Rows" "SQL ordered by Update Delete" "SQL ordered by Disk Temp Table" "SQL ordered by Not Ues Index" "SQL ordered by Logic Read" "SQL ordered by Big Trans")
function OUT_PUT_SQL_Statistics() {
echo -e "<ul>" >> "${CHECK_RESULT_FILE}"
# 遍历数组,为每个元素生成一个列表项
for item in "${SQL_statistics_items[@]}"; do
echo -e " <li><a href=\"#${item}\" style=\"color: brown;\"><b>${item}</b></a></li>" >> "${CHECK_RESULT_FILE}"
done
echo -e "</ul>" >> "${CHECK_RESULT_FILE}"
}
Performance_statistics_items=("Parameters Status" "Memory Info" "Host Info" "User Info" "File IO Info" "Wait Event Info" "Statistics INFO" "Statement INFO" "Current Process Info")
function OUT_PUT_Performance_Statistics() {
echo -e "<ul>" >> "${CHECK_RESULT_FILE}"
# 遍历数组,为每个元素生成一个列表项
for item in "${Performance_statistics_items[@]}"; do
echo -e " <li><a href=\"#${item}\" style=\"color: brown;\"><b>${item}</b></a></li>" >> "${CHECK_RESULT_FILE}"
done
echo -e "</ul>" >> "${CHECK_RESULT_FILE}"
}
##返回页首信息
function OUT_PUT_back_to_top() {
echo -e "<a class="noLink" href=\"#Main Report\" style=\"color: brown;\" ><b>Back to Top</b></a><p> " >> "${CHECK_RESULT_FILE}"
echo -e "<hr><p>" >> "${CHECK_RESULT_FILE}"
}
#================================================SQL Segments========================================================================
##数据库信息
#查看数据库启动时间,版本信息
MYSQL_UPTIME_SQL="select 'Mysql' AS 'Instance',1 AS 'InstNum',FROM_UNIXTIME(unix_timestamp(now()) - VARIABLE_VALUE, '%Y-%m-%d %H:%I:%s') AS 'StartupTime',VERSION() AS 'Release' FROM performance_schema.global_status WHERE VARIABLE_NAME = 'UPTIME';"
##events_statements_history =10000 没法保留1周
GET_TPS_SQL="
SELECT DATE_FORMAT(Per_Second,'%Y-%m-%d') as Per_DAY,SUM(TPS) AS TOTAL_TPS,AVG(TPS) AS AVG_TPS,MAX(TPS) AS MAX_TPS
FROM
(
select DATE_FORMAT(START_TIME,'%Y-%m-%d %H:%i:%S') as Per_Second,count(DIGEST) AS TPS
from
(
SELECT
FROM_UNIXTIME( (unix_timestamp(sysdate()) - (select variable_value from performance_schema.global_status where variable_name = 'Uptime')) + TIMER_START/1000000000000 ) AS START_TIME,
FROM_UNIXTIME( (unix_timestamp(sysdate()) - (select variable_value from performance_schema.global_status where variable_name = 'Uptime')) + TIMER_END/1000000000000 ) AS END_TIME,
DIGEST,DIGEST_TEXT,
TIMER_WAIT/1000000000000 AS RUN_SECONDS,
LOCK_TIME/1000000000000 AS LOCK_SECONDS,
SQL_TEXT,EVENT_NAME
FROM performance_schema.events_statements_history
WHERE EVENT_NAME in ('statement/sql/update','statement/sql/insert','statement/sql/delete')
) base1
where START_TIME between '${START_DATE}' and '${END_DATE}'
group by Per_Second,EVENT_NAME
) DAY1
GROUP BY Per_DAY
order by Per_DAY asc;"
##events_statements_history =10000 没法保留1周
GET_QPS_SQL="
SELECT DATE_FORMAT(Per_Second,'%Y-%m-%d') as Per_DAY,SUM(QPS) AS TOTAL_QPS,AVG(QPS) AS AVG_QPS,MAX(QPS) AS MAX_QPS
FROM
(
select DATE_FORMAT(START_TIME,'%Y-%m-%d %H:%i:%S') as Per_Second,count(DIGEST) AS QPS
from
(
SELECT
FROM_UNIXTIME( (unix_timestamp(sysdate()) - (select variable_value from performance_schema.global_status where variable_name = 'Uptime')) + TIMER_START/1000000000000 ) AS START_TIME,
FROM_UNIXTIME( (unix_timestamp(sysdate()) - (select variable_value from performance_schema.global_status where variable_name = 'Uptime')) + TIMER_END/1000000000000 ) AS END_TIME,
DIGEST,DIGEST_TEXT,
TIMER_WAIT/1000000000000 AS RUN_SECONDS,
LOCK_TIME/1000000000000 AS LOCK_SECONDS,
SQL_TEXT,EVENT_NAME
FROM performance_schema.events_statements_history
WHERE EVENT_NAME in ('statement/sql/select','statement/sql/update','statement/sql/insert','statement/sql/delete')
) base1
where START_TIME between '${START_DATE}' and '${END_DATE}'
group by Per_Second,EVENT_NAME
) DAY1
GROUP BY Per_DAY
order by Per_DAY asc;"
#统计数据库大小
TOP_SCHEMA_STATISTICS="select table_schema,ROUND(SUM(TABLE_ROWS),2) as ALLSIZE_ROWS,ROUND(SUM(DATA_LENGTH+INDEX_LENGTH+DATA_FREE)/1024/1024,2) as ALLSIZE_MB,ROUND(SUM(DATA_LENGTH)/1024/1024,2) AS DATASIZE_MB,ROUND(SUM(INDEX_LENGTH)/1024/1024,2) AS INDEXSIZE_MB
from information_schema.TABLES
GROUP BY table_schema order by DATASIZE_MB desc limit 10;"
#TOP表大小
TOP_TABLE_STATISTICS="select TABLE_NAME,ROUND(ALL_LENGTH/1024/1024,2) as ALLSIZE_MB,TABLE_ROWS,ROUND(DATA_LENGTH/1024/1024,2) AS DATASIZE_MB,ROUND(INDEX_LENGTH/1024/1024,2) AS INDEXSIZE_MB,frag_rate,avg_row_length
from(
select TABLE_NAME,TABLE_ROWS,DATA_LENGTH,INDEX_LENGTH,DATA_FREE, DATA_LENGTH+INDEX_LENGTH+DATA_FREE as ALL_LENGTH, RoUND(DATA_FREE/(DATA_LENGTH+INDEX_LENGTH+DATA_FREE)*100,2) AS frag_rate,avg_row_length
from information_schema.TABLES
where table_schema not in ('mysql','information_schema','performance_schema','sys')
order by ALL_LENGTH desc
limit 20) tmp;"
#TOP表碎片大小
TOP_FRAG_STATISTICS="
select TABLE_NAME,ROUND(ALL_LENGTH/1024/1024,2) as ALLSIZE_MB,ROUND(DATA_LENGTH/1024/1024,2) AS DATASIZE_MB,ROUND(INDEX_LENGTH/1024/1024,2) AS INDEXSIZE_MB,frag_rate,TABLE_ROWS,avg_row_length
from(
select TABLE_NAME,TABLE_ROWS,DATA_LENGTH,INDEX_LENGTH,DATA_FREE, DATA_LENGTH+INDEX_LENGTH+DATA_FREE as ALL_LENGTH, RoUND(DATA_FREE/(DATA_LENGTH+INDEX_LENGTH+DATA_FREE)*100,2) AS frag_rate,avg_row_length
from information_schema.TABLES
where table_schema not in ('mysql','information_schema','performance_schema','sys')
order by frag_rate desc
limit 10) tmp
where frag_rate >10;"
#没有主键表统计
NOT_PRIMAYRKEY_STATISTICS="select t.table_schema,t.table_name,t.table_rows,t.engine,t.data_length,t.index_length
from
information_schema.tables t
left join
information_schema.key_column_usage k
on t.table_schema = k.table_schema and t.table_name = k.table_name and k.constraint_name = 'PRIMARY'
where
t.table_schema not in ('mysql','information_schema','performance_schema','sys')
and k.constraint_name is null
and t.table_type = 'BASE TABLE'
order by t.table_rows desc;"
#数据库字符集
GET_SCHEMA_CHARSET_STATISTICS="select schema_name,default_character_set_name,default_collation_name
from information_schema.schemata
where default_character_set_name not in('utf8mb4','utf8')
and schema_name not in ('mysql','information_schema','performance_schema','sys') ;"
#表字符集
GET_TABLE_CHAR_SORT_STATISTICS="select TABLE_SCHEMA, TABLE_NAME,TABLE_COLLATION
from information_schema.tables
where TABLE_COLLATION not in('utf8mb4_general_ci','utf8mb4_0900_ai_ci','utf8_general_ci')
and table_schema not in ('mysql','information_schema','performance_schema','sys')
order by table_name;"
#不是存储引擎的表
GET_TABLE_NOT_INNODB_STATISTICS="SELECT TABLE_SCHEMA,TABLE_NAME,ENGINE FROM INFORMATION_SCHEMA.TABLES
WHERE ENGINE != 'innodb' AND TABLE_SCHEMA NOT IN ( 'mysql','information_schema','performance_schema','sys' );"
#总计执行时间最长的SQL语句
TOP_LONG_TIME_SQL="
SELECT SCHEMA_NAME,DIGEST_TEXT,COUNT_STAR, sys.format_time(SUM_TIMER_WAIT) AS SUM_TIME, sys.format_time(MIN_TIMER_WAIT) AS MIN_TIME, sys.format_time(AVG_TIMER_WAIT) AS AVG_TIME,sys.format_time(MAX_TIMER_WAIT) AS MAX_TIME,sys.format_time(SUM_LOCK_TIME) AS SUM_LOCK_TIME,SUM_ROWS_AFFECTED,SUM_ROWS_SENT,SUM_ROWS_EXAMINED
FROM performance_schema.events_statements_summary_by_digest
WHERE SCHEMA_NAME IS NOT NULL ORDER BY SUM_TIME DESC LIMIT 10;"
#数据库重要参数变量信息
MYSQL_GETVARIABLE_SQL="select VARIABLE_NAME,VARIABLE_VALUE from performance_schema.global_variables
where VARIABLE_NAME in (
'character_set_server','gtid_mode','enforce_gtid_consistency','lower_case_table_names','max_connections','read_only','super_read_only','max_connections',
'innodb_buffer_pool_size','innodb_buffer_pool_instances','innodb_log_file_size','log_bin',
'binlog_format','max_binlog_size','log-bin','expire_logs_days','log_slave_updates','binlog_expire_logs_seconds',
'master_info_repository','relay_log_info_repository','slave_parallel_type','slave_parallel_workers','binlog_group_commit_sync_delay','binlog_group_commit_sync_no_delay_count',
'rpl_semi_sync_master_enabled','rpl_semi_sync_slave_enabled','rpl_semi_sync_master_timeout',
'sort_buffer_size','join_buffer_size','read_buffer_size','read_rnd_buffer_size','bulk_insert_buffer_size'
) order by VARIABLE_NAME;"
#全局内存设置
GET_GOBAL_MEM_OPTION_SQL="
SELECT
ROUND(@@innodb_buffer_pool_size/1024/1024,2) as BUF_POOL ,
ROUND(@@innodb_log_buffer_size/1024/1024,2) as LOG_BUF,
ROUND(@@tmp_table_size/1024/1024,2) as TMP_TABLE,
ROUND(@@read_buffer_size/1024/1024,2) as READ_BUF,
ROUND(@@sort_buffer_size/1024/1024,2) as SORT_BUF,
ROUND(@@join_buffer_size/1024/1024,2) as JOIN_BUF,
ROUND(@@read_rnd_buffer_size/1024/1024,2) as READ_RND_BUF,
ROUND(@@binlog_cache_size/1024/1024,2) as BINLOG_CACHE,
ROUND(@@thread_stack/1024/1024,2) as THREAD_STACK,
(SELECT COUNT(host) FROM information_schema.processlist where command<>'Sleep') as active_connect;"
##TOP sql info
#TOP 10 平均执行时间最长的语句
GET_WEEK_TOP_AVGTIME_SQL="select SCHEMA_NAME,DIGEST_TEXT,COUNT_STAR,sys.format_time(SUM_TIMER_WAIT) as sum_time,sys.format_time(MIN_TIMER_WAIT)
as min_time,sys.format_time(AVG_TIMER_WAIT) as avg_time,sys.format_time(MAX_TIMER_WAIT) as max_time,sys.format_time(SUM_LOCK_TIME) as sum_lock_time,
SUM_ROWS_AFFECTED,SUM_ROWS_SENT,SUM_ROWS_EXAMINED from performance_schema.events_statements_summary_by_digest where SCHEMA_NAME is not null order by COUNT_STAR desc limit 10;"
#TOP 10 锁时间时间最长的语句
GET_WEEK_TOP_LOCKTIME_SQL="select SCHEMA_NAME,DIGEST_TEXT,COUNT_STAR,sys.format_time(SUM_TIMER_WAIT) as sum_time,sys.format_time(MIN_TIMER_WAIT)
as min_time,sys.format_time(AVG_TIMER_WAIT) as avg_time,sys.format_time(MAX_TIMER_WAIT) as max_time,sys.format_time(SUM_LOCK_TIME) as sum_lock_time,
SUM_ROWS_AFFECTED,SUM_ROWS_SENT,SUM_ROWS_EXAMINED from performance_schema.events_statements_summary_by_digest where SCHEMA_NAME is not null order by SUM_LOCK_TIME desc limit 10;"
#TOP 10 出检查行数最多的SQL语句
GET_WEEK_TOP_EXAMINEDROW_SQL="select SCHEMA_NAME,DIGEST_TEXT,COUNT_STAR,sys.format_time(SUM_TIMER_WAIT) as sum_time,sys.format_time(MIN_TIMER_WAIT)
as min_time,sys.format_time(AVG_TIMER_WAIT) as avg_time,sys.format_time(MAX_TIMER_WAIT) as max_time,sys.format_time(SUM_LOCK_TIME) as sum_lock_time,
SUM_ROWS_AFFECTED,SUM_ROWS_SENT,SUM_ROWS_EXAMINED from performance_schema.events_statements_summary_by_digest where SCHEMA_NAME is not null order by SUM_ROWS_EXAMINED desc limit 10;"
#TOP 10 返回行数最多的SQL语句
GET_WEEK_TOP_SENTROW_SQL="select SCHEMA_NAME,DIGEST_TEXT,COUNT_STAR,sys.format_time(SUM_TIMER_WAIT) as sum_time,sys.format_time(MIN_TIMER_WAIT)
as min_time,sys.format_time(AVG_TIMER_WAIT) as avg_time,sys.format_time(MAX_TIMER_WAIT) as max_time,sys.format_time(SUM_LOCK_TIME) as sum_lock_time,
SUM_ROWS_AFFECTED,SUM_ROWS_SENT,SUM_ROWS_EXAMINED from performance_schema.events_statements_summary_by_digest where SCHEMA_NAME is not null order by SUM_ROWS_SENT desc limit 10;"
#TOP 10排序行数最多的SQL语句
GET_WEEK_TOP_SORTROW_SQL="select SCHEMA_NAME,DIGEST_TEXT,COUNT_STAR,sys.format_time(SUM_TIMER_WAIT) as sum_time,sys.format_time(MIN_TIMER_WAIT)
as min_time,sys.format_time(AVG_TIMER_WAIT) as avg_time,sys.format_time(MAX_TIMER_WAIT) as max_time,sys.format_time(SUM_LOCK_TIME) as sum_lock_time,
SUM_ROWS_AFFECTED,SUM_ROWS_SENT,SUM_ROWS_EXAMINED from performance_schema.events_statements_summary_by_digest where SCHEMA_NAME is not null order by SUM_SORT_ROWS desc limit 10;"
#TOP 10 更新行数最多的SQL语句
GET_WEEK_TOP_AFFECTED_SQL="select SCHEMA_NAME,DIGEST_TEXT,COUNT_STAR,sys.format_time(SUM_TIMER_WAIT) as sum_time,sys.format_time(MIN_TIMER_WAIT)
as min_time,sys.format_time(AVG_TIMER_WAIT) as avg_time,sys.format_time(MAX_TIMER_WAIT) as max_time,sys.format_time(SUM_LOCK_TIME) as sum_lock_time,
SUM_ROWS_AFFECTED,SUM_ROWS_SENT,SUM_ROWS_EXAMINED from performance_schema.events_statements_summary_by_digest where SCHEMA_NAME is not null order by SUM_ROWS_AFFECTED desc limit 10;"
#TOP 10 磁盘临时表数最多的SQL语句
GET_WEEK_TOP_DISKTMP_SQL="select SCHEMA_NAME,DIGEST_TEXT,COUNT_STAR,sys.format_time(SUM_TIMER_WAIT) as sum_time,sys.format_time(MIN_TIMER_WAIT)
as min_time,sys.format_time(AVG_TIMER_WAIT) as avg_time,sys.format_time(MAX_TIMER_WAIT) as max_time,sys.format_time(SUM_LOCK_TIME) as sum_lock_time,
SUM_ROWS_AFFECTED,SUM_ROWS_SENT,SUM_ROWS_EXAMINED from performance_schema.events_statements_summary_by_digest where SCHEMA_NAME is not null order by SUM_CREATED_TMP_DISK_TABLES desc limit 10;"
#TOP 10 未使用索引最多的SQL语句
GET_WEEK_TOP_NO_INDEX_SQL="select SCHEMA_NAME,DIGEST_TEXT,COUNT_STAR,sys.format_time(SUM_TIMER_WAIT) as sum_time,sys.format_time(MIN_TIMER_WAIT)
as min_time,sys.format_time(AVG_TIMER_WAIT) as avg_time,sys.format_time(MAX_TIMER_WAIT) as max_time,sys.format_time(SUM_LOCK_TIME) as sum_lock_time,
SUM_ROWS_AFFECTED,SUM_ROWS_SENT,SUM_ROWS_EXAMINED from performance_schema.events_statements_summary_by_digest where SCHEMA_NAME is not null order by SUM_NO_INDEX_USED desc limit 10;"
#太多逻辑读的SQL 平均每次大于2万行
GET_WEEK_TOP_LOGIC_READ_SQL="SELECT SCHEMA_NAME,
DIGEST AS digest,
DIGEST_TEXT,
COUNT_STAR,
AVG_TIMER_WAIT,
ROUND(SUM_ROWS_AFFECTED/COUNT_STAR, 0) AS rows_affected_avg,
ROUND(SUM_ROWS_SENT/COUNT_STAR, 0) AS rows_sent_avg,
ROUND(SUM_ROWS_EXAMINED/COUNT_STAR, 0) AS rows_examined_avg,
FIRST_SEEN,
LAST_SEEN
FROM performance_schema.events_statements_summary_by_digest
where DIGEST_TEXT not like '%SHOW%'
and DIGEST_TEXT not like 'desc%'
and SCHEMA_NAME not in ('mysql','information_schema','performance_schema','sys')
and ROUND(SUM_ROWS_EXAMINED/COUNT_STAR, 0) >20000
and COUNT_STAR >200
and last_seen > date_sub(curdate(),interval 7 day)
order by ROUND(SUM_ROWS_EXAMINED/COUNT_STAR, 0) desc;"
#大事务影响行超过10万行
GET_WEEK_BIG_TRANS_SQL="SELECT SCHEMA_NAME,
DIGEST AS digest,
DIGEST_TEXT,
COUNT_STAR,
AVG_TIMER_WAIT,
ROUND(SUM_ROWS_AFFECTED/ COUNT_STAR, 0) AS rows_affected_avg,
ROUND(SUM_ROWS_SENT / COUNT_STAR, 0) AS rows_sent_avg,
ROUND(SUM_ROWS_EXAMINED / COUNT_STAR, 0) AS rows_examined_avg,
FIRST_SEEN,
LAST_SEEN
FROM performance_schema.events_statements_summary_by_digest
where DIGEST_TEXT not like '%SHOW%' and DIGEST_TEXT not like 'desc%'
and SCHEMA_NAME not in ('mysql','information_schema','performance_schema','sys')
and ROUND(SUM_ROWS_AFFECTED/ COUNT_STAR, 0) >100000
and COUNT_STAR >200
and last_seen > date_sub(curdate(),interval 8 day)
order by ROUND(SUM_ROWS_AFFECTED/ COUNT_STAR, 0) desc;"
###performance schema info
#MEMORY INFO
GET_TOTAL_MEMORY_SQL="SELECT sys.format_bytes(sum(CURRENT_NUMBER_OF_BYTES_USED)) AS MEMORY_USED FROM performance_schema.memory_summary_global_by_event_name LIMIT 250;"
GET_EVENT_MEMORY_SQL="SELECT event_name,sys.format_bytes(CURRENT_NUMBER_OF_BYTES_USED) AS MEMORY FROM performance_schema.memory_summary_global_by_event_name ORDER BY CURRENT_NUMBER_OF_BYTES_USED DESC LIMIT LIMIT 250;"
GET_INNODB_BUF_SCHEMA_SQL="select * from sys.innodb_buffer_stats_by_schema LIMIT 250;"
GET_INNODB_BUF_TABLE_SQL="select * from sys.innodb_buffer_stats_by_table LIMIT 250;"
GET_HOST_MEMORY_BYTES_SQL="select * from sys.memory_by_host_by_current_bytes LIMIT 250;"
GET_THREAD_MEMORY_BYTES_SQL="select * from sys.memory_by_thread_by_current_bytes LIMIT 250;"
GET_USER_CURRENT_MEMORY_BYTES_SQL="select * from sys.memory_by_user_by_current_bytes LIMIT 250;"
GET_EVENT_CURRENT_MEMEORY_BYTES_SQL="select * from sys.memory_global_by_current_bytes LIMIT 250;"
#HOST INFO
GET_HOST_SUMMARY_SQL="select * sys.from host_summary limit 10;"
GET_HOST_IO_SQL="SELECT * FROM sys.host_summary_by_file_io limit 10;"
GET_HOST_IO_TYPE_SQL="select * from sys.host_summary_by_file_io_type limit 10;"
GET_HOST_STAGES_SQL="select * from sys.host_summary_by_stages limit 10;"
GET_HOST_STATEMENT_SQL="select * from sys.host_summary_by_statement_latency limit 10;"
GET_HOST_STATEMENT_TYPE_SQL="select * from sys.host_summary_by_statement_type limit 10;"
#USER INFO
GET_USER_SUMMARY_SQL="select * from sys.user_summary limit 10;"
GET_USER_IO_SQL="select * from sys.user_summary_by_file_io limit 10;"
GET_USER_IO_TYPE="select * from sys.user_summary_by_file_io_type limit 10;"
GET_USER_STAGES_SQL="select * from sys.user_summary_by_stages limit 10;"
GET_USER_STATEMENT_SQL="select * from sys.user_summary_by_statement_latency limit 10;"
GET_USE_STATEMENT_TYPE_SQL="select * from sys.user_summary_by_statement_type limit 10;"
GET_THREAD_IO_SQL="select * from sys.io_by_thread_by_latency limit 10;"
#FILE INFO
GET_FILE_IO_BYTES_SQL="select * from sys.io_global_by_file_by_bytes LIMIT 250;"
GET_FILE_IO_TIME_SQL="select * from sys.io_global_by_file_by_latency LIMIT 250;"
GET_FILE_IO_SUMMARY_BYTES_SQL="select * from sys.io_global_by_wait_by_bytes LIMIT 250;"
GET_FILE_IO_SUMMARY_TIME_SQL="select * from sys.io_global_by_wait_by_latency;"
GET_NEW_IO_SQL="select * from sys.latest_file_io ORDER BY LATENCY DESC LIMIT 250;"
#WAIT EVENT INFO
GET_WAIT_EVENT_SQL="select * from sys.wait_classes_global_by_avg_latency LIMIT 250;"
GET_HOST_WAIT_SQL="select * from sys.waits_by_host_by_latency LIMIT 250;"
GET_USER_WAIT_SQL="select * from sys.waits_by_user_by_latency LIMIT 250;"
GET_GLOBAL_WAIT_SQL="select * from sys.waits_global_by_latency LIMIT 250;"
GET_LOCK_WAIT_SQL="select * from sys.innodb_lock_waits LIMIT 250;"
#STATISTICS INFO
GET_AUTO_INCREMENT_SQL="select * from sys.schema_auto_increment_columns where table_schema not in ('mysql','information_schema','performance_schema','sys') limit 20;"
GET_INDEXS_STATIS_SQL="select * from sys.schema_index_statistics where table_schema not in ('mysql','information_schema','performance_schema','sys') limit 10;"
GET_REDUN_INDEX_SQL="select * from sys.schema_redundant_indexes where table_schema not in ('mysql','information_schema','performance_schema','sys') limit 10;"
GET_TABLE_STATIS_SQL="select * from sys.schema_table_statistics where table_schema not in ('mysql','information_schema','performance_schema','sys') limit 10;"
GET_BUF_HOT_TABLE_SQL="select * from sys.schema_table_statistics_with_buffer where table_schema not in ('mysql','information_schema','performance_schema','sys') limit 10;"
GET_UNUSED_INDEX_SQL="SELECT * FROM sys.schema_unused_indexes where OBJECT_SCHEMA not in ('mysql','information_schema','performance_schema','sys') limit 10;"
#SQL INFO
GET_FULL_TABLE_SCAN_SQL="select * from sys.schema_tables_with_full_table_scans where OBJECT_SCHEMA not in ('mysql','information_schema','performance_schema','sys') limit 10;"
GET_STATEMENT_ANLAYZ_SQL="select * from sys.statement_analysis where db not in ('mysql','information_schema','performance_schema','sys') limit 10;"
GET_FULL_SCAN_STATEMENT_SQL="select * from sys.statements_with_full_table_scans where db not in ('mysql','information_schema','performance_schema','sys') limit 10;"
GET_FILESORT_STATEMENT_SQL="select * from sys.statements_with_sorting where db not in ('mysql','information_schema','performance_schema','sys') limit 10;"
GET_TEMP_STATEMENT_SQL="select * from sys.statements_with_temp_tables where db not in ('mysql','information_schema','performance_schema','sys') limit 10;"
#SESSION INFO
GET_PROCESSLIST_SQL="select date_format(now(),'%Y-%m-%d %H:%i:%s') as 'CURRENT_TIME',ID,USER,HOST,DB,COMMAND,TIME,STATE,INFO from information_schema.PROCESSLIST where COMMAND<>'Sleep';"
GET_SESSION_SQL="select date_format(now(),'%Y-%m-%d %H:%i:%s') as 'CURRENT_TIME',user,SUBSTRING_INDEX(host,':',1) as ip , count(*) from information_schema.processlist group by user,ip order by 4 desc;"
GET_CURRENT_TABLE_LOCK_WAIT_SQL="select * from sys.schema_table_lock_waits;"
#REPLICATION INFO
GET_SLAVES_SQL="SHOW SLAVES;"
GET_REPLICAS_SQL="SHOW REPLICAS;"
#GET SLAVE INFO
GET_SLAVE_INFO_SQL="show slave status \G;"
#GET ENGINE INNODB STATUS
GET_ENGINE_INNODB_SQL="show engine innodb status \G;"
#============================================================HTML SEGMETN DISPLAY BEGIN===================================================================
if [[ ! -f ${CHECK_RESULT_FILE} ]] ; then
touch ${CHECK_RESULT_FILE}
fi
CREATE_HTML_HEAD
Target_MysqlDB $MYSQL_UPTIME_SQL
OUT_PUT_NEW_LINE
OUTPUT_TITLE "Main Report"
OUT_PUT_Main_report_Statistics
OUT_PUT_NEW_LINE
OUT_PUT_back_to_top
##system info
OUTPUT_TITLE "System Statistics"
OUT_PUT_NEW_LINE
OUT_PUT_System_Statistics
OUT_PUT_NEW_LINE
OUT_PUT_back_to_top
OUTPUT_TITLE_02 "Host Disk"
OUT_PUT_TABLE_HEAD
disk_info
OUT_PUT_TABLE_TAIL
OUTPUT_TITLE_02 "Host Memory"
OUT_PUT_TABLE_HEAD
OUT_PUT_TITEL "TYPE TOTAL USED FREE SHARED BUFF AVAILABLE"
OUT_PUT_LINES "$(free -m |tail -2|grep Mem )"
OUT_PUT_LINES "$(free -m |tail -2|grep Swap)"
OUT_PUT_LINES "$(free -mt |tail -2|grep Total)"
OUT_PUT_TABLE_TAIL
OUTPUT_TITLE_02 "Cpu info"
OUT_PUT_TABLE_HEAD
sar_cpu
OUT_PUT_TABLE_TAIL
OUTPUT_TITLE_02 "Iostat info"
OUT_PUT_TABLE_HEAD
iostat_info
OUT_PUT_TABLE_TAIL
OUTPUT_TITLE_02 "System Messages"
OUT_PUT_TABLE_HEAD
System_Messages_info
OUT_PUT_TABLE_TAIL
OUT_PUT_NEW_LINE
OUT_PUT_back_to_top
##database info
OUTPUT_TITLE "Database Statistics"
OUT_PUT_NEW_LINE
OUT_PUT_Database_Statistics
OUT_PUT_NEW_LINE
OUT_PUT_back_to_top
OUTPUT_TITLE_02 "QPS"
Target_MysqlDB $GET_QPS_SQL
OUT_PUT_NEW_LINE
OUTPUT_TITLE_02 "TPS"
Target_MysqlDB $GET_TPS_SQL
OUT_PUT_NEW_LINE
OUTPUT_TITLE_02 "Top Schema"
Target_MysqlDB $TOP_SCHEMA_STATISTICS
OUT_PUT_NEW_LINE
OUTPUT_TITLE_02 "Top Table"
Target_MysqlDB $TOP_TABLE_STATISTICS
OUT_PUT_NEW_LINE
OUTPUT_TITLE_02 "Top Fage"
Target_MysqlDB $TOP_FRAG_STATISTICS
OUT_PUT_NEW_LINE
OUTPUT_TITLE_02 "Not Primary Key Table"
Target_MysqlDB $NOT_PRIMAYRKEY_STATISTICS
OUT_PUT_NEW_LINE
OUTPUT_TITLE_02 "Database Charset"
Target_MysqlDB $GET_SCHEMA_CHARSET_STATISTICS
OUT_PUT_NEW_LINE
OUTPUT_TITLE_02 "Table Charset"
Target_MysqlDB $GET_TABLE_CHAR_SORT_STATISTICS
OUT_PUT_NEW_LINE
OUTPUT_TITLE_02 "Table Not Innodb"
Target_MysqlDB $GET_TABLE_NOT_INNODB_STATISTICS
OUT_PUT_NEW_LINE
OUT_PUT_back_to_top
##sql info
OUTPUT_TITLE "SQL Statistics"
OUT_PUT_NEW_LINE
OUT_PUT_SQL_Statistics
OUT_PUT_NEW_LINE
OUT_PUT_back_to_top
OUTPUT_TITLE_02 "SQL ordered by Elapsed Time"
Target_MysqlDB $GET_WEEK_TOP_AVGTIME_SQL
OUT_PUT_NEW_LINE
OUTPUT_TITLE_02 "SQL ordered by Lock Time"
Target_MysqlDB $GET_WEEK_TOP_LOCKTIME_SQL
OUT_PUT_NEW_LINE
OUTPUT_TITLE_02 "SQL ordered by Numrows"
Target_MysqlDB $GET_WEEK_TOP_EXAMINEDROW_SQL
OUT_PUT_NEW_LINE
OUTPUT_TITLE_02 "SQL ordered by Sent Rows"
Target_MysqlDB $GET_WEEK_TOP_SENTROW_SQL
OUT_PUT_NEW_LINE
OUTPUT_TITLE_02 "SQL ordered by Sort Rows"
Target_MysqlDB $GET_WEEK_TOP_SORTROW_SQL
OUT_PUT_NEW_LINE
OUTPUT_TITLE_02 "SQL ordered by Update Delete"
Target_MysqlDB $GET_WEEK_TOP_AFFECTED_SQL
OUT_PUT_NEW_LINE
OUTPUT_TITLE_02 "SQL ordered by Disk Temp Table"
Target_MysqlDB $GET_WEEK_TOP_DISKTMP_SQL
OUT_PUT_NEW_LINE
OUTPUT_TITLE_02 "SQL ordered by Not Ues Index"
Target_MysqlDB $GET_WEEK_TOP_NO_INDEX_SQL
OUT_PUT_NEW_LINE
OUTPUT_TITLE_02 "SQL ordered by Logic Read"
Target_MysqlDB $GET_WEEK_TOP_LOGIC_READ_SQL
OUT_PUT_NEW_LINE
OUTPUT_TITLE_02 "SQL ordered by Big Trans"
Target_MysqlDB $GET_WEEK_BIG_TRANS_SQL
OUT_PUT_NEW_LINE
OUT_PUT_back_to_top
##replication info
OUTPUT_TITLE "Replication Statistics"
OUT_PUT_NEW_LINE
OUTPUT_TITLE_02 "Replication Hosts"
Target_MysqlDB "$GET_SLAVES_SQL"
Target_MysqlDB "$GET_REPLICAS_SQL"
OUT_PUT_NEW_LINE
OUTPUT_TITLE_02 "Replication Status"
SALVE_MysqlDB $GET_SLAVE_INFO_SQL
Parse_salve_txt
OUT_PUT_TABLE_HEAD
OUT_PUT_TITEL "KEY VAULE"
OUT_PUT_LINES "MASTER_UUID ${MASTER_UUID}"
OUT_PUT_LINES "SLAVE_IO_STATE ${SLAVE_IO_STATE}"
OUT_PUT_LINES "READ_MASTER_POST ${READ_MASTER_POST}"
OUT_PUT_LINES "Relay_Master_Log_File ${Relay_Master_Log_File}"
OUT_PUT_LINES "EXEC_MASTER_POST ${EXEC_MASTER_POST}"
OUT_PUT_LINES "BEHIND_SECONDS ${BEHIND_SECONDS}"
OUT_PUT_LINES "SLAVE_IO_RUNNING ${SLAVE_IO_RUNNING}"
OUT_PUT_LINES "SLAVE_SQL_RUNNING ${SLAVE_SQL_RUNNING}"
OUT_PUT_LINES "REPLICATE_DO_DB ${REPLICATE_DO_DB}"
OUT_PUT_LINES "SQLDELAY ${SQLDELAY}"
OUT_PUT_LINES "SALVE_SQL_RUN_STATE ${SALVE_SQL_RUN_STATE}"
OUT_PUT_LINES "LAST_SQL_ERROR ${LAST_SQL_ERROR}"
OUT_PUT_LINES "LAST_IO_ERROR ${LAST_IO_ERROR}"
OUT_PUT_LINES "RETRIEVED_GTID ${RETRIEVED_GTID}"
OUT_PUT_LINES "EXECUTED_GTID ${EXECUTED_GTID}"
OUT_PUT_TABLE_TAIL
OUT_PUT_NEW_LINE
OUT_PUT_back_to_top
##Initialization Parameters info
OUTPUT_TITLE "Initialization Parameters"
OUT_PUT_NEW_LINE
OUTPUT_TITLE_02 "Parameters Status"
Target_MysqlDB "$MYSQL_GETVARIABLE_SQL"
OUT_PUT_NEW_LINE
OUT_PUT_back_to_top
##Performance info
OUTPUT_TITLE "Performance Statistics"
OUT_PUT_NEW_LINE
OUT_PUT_Performance_Statistics
OUT_PUT_NEW_LINE
OUT_PUT_back_to_top
OUTPUT_TITLE_02 "Parameters Status"
Target_MysqlDB "$GET_GOBAL_MEM_OPTION_SQL"
OUT_PUT_NEW_LINE
OUTPUT_TITLE_02 "Memory Info"
Target_MysqlDB "$GET_TOTAL_MEMORY_SQL"
OUT_PUT_NEW_LINE
Target_MysqlDB "$GET_EVENT_MEMORY_SQL"
OUT_PUT_NEW_LINE
Target_MysqlDB "$GET_INNODB_BUF_SCHEMA_SQL"
OUT_PUT_NEW_LINE
Target_MysqlDB "$GET_INNODB_BUF_TABLE_SQL"
OUT_PUT_NEW_LINE
Target_MysqlDB "$GET_HOST_MEMORY_BYTES_SQL"
OUT_PUT_NEW_LINE
Target_MysqlDB "$GET_THREAD_MEMORY_BYTES_SQL"
OUT_PUT_NEW_LINE
Target_MysqlDB "$GET_USER_CURRENT_MEMORY_BYTES_SQL"
OUT_PUT_NEW_LINE
Target_MysqlDB "$GET_EVENT_CURRENT_MEMEORY_BYTES_SQL"
OUT_PUT_NEW_LINE
OUTPUT_TITLE_02 "Host Info"
Target_MysqlDB "$GET_HOST_SUMMARY_SQL"
OUT_PUT_NEW_LINE
Target_MysqlDB "$GET_HOST_IO_SQL"
OUT_PUT_NEW_LINE
Target_MysqlDB "$GET_HOST_IO_TYPE_SQL"
OUT_PUT_NEW_LINE
Target_MysqlDB "$GET_HOST_STAGES_SQL"
OUT_PUT_NEW_LINE
Target_MysqlDB "$GET_HOST_STATEMENT_SQL"
OUT_PUT_NEW_LINE
Target_MysqlDB "$GET_HOST_STATEMENT_TYPE_SQL"
OUT_PUT_NEW_LINE
OUTPUT_TITLE_02 "User Info"
Target_MysqlDB "$GET_USER_SUMMARY_SQL"
OUT_PUT_NEW_LINE
Target_MysqlDB "$GET_USER_IO_SQL"
OUT_PUT_NEW_LINE
Target_MysqlDB "$GET_USER_IO_TYPE"
OUT_PUT_NEW_LINE
Target_MysqlDB "$GET_USER_STAGES_SQL"
OUT_PUT_NEW_LINE
Target_MysqlDB "$GET_USER_STATEMENT_SQL"
OUT_PUT_NEW_LINE
Target_MysqlDB "$GET_USE_STATEMENT_TYPE_SQL"
OUT_PUT_NEW_LINE
Target_MysqlDB "$GET_THREAD_IO_SQL"
OUT_PUT_NEW_LINE
OUTPUT_TITLE_02 "File IO Info"
Target_MysqlDB "$GET_FILE_IO_BYTES_SQL"
OUT_PUT_NEW_LINE
Target_MysqlDB "$GET_FILE_IO_TIME_SQL"
OUT_PUT_NEW_LINE
Target_MysqlDB "$GET_FILE_IO_SUMMARY_BYTES_SQL"
OUT_PUT_NEW_LINE
Target_MysqlDB "$GET_FILE_IO_SUMMARY_TIME_SQL"
OUT_PUT_NEW_LINE
Target_MysqlDB "$GET_NEW_IO_SQL"
OUT_PUT_NEW_LINE
OUTPUT_TITLE_02 "Wait Event Info"
Target_MysqlDB "$GET_WAIT_EVENT_SQL"
OUT_PUT_NEW_LINE
Target_MysqlDB "$GET_HOST_WAIT_SQL"
OUT_PUT_NEW_LINE
Target_MysqlDB "$GET_USER_WAIT_SQL"
OUT_PUT_NEW_LINE
Target_MysqlDB "$GET_GLOBAL_WAIT_SQL"
OUT_PUT_NEW_LINE
Target_MysqlDB "$GET_LOCK_WAIT_SQL"
OUT_PUT_NEW_LINE
OUTPUT_TITLE_02 "Statistics INFO"
Target_MysqlDB "$GET_AUTO_INCREMENT_SQL"
OUT_PUT_NEW_LINE
Target_MysqlDB "$GET_INDEXS_STATIS_SQL"
OUT_PUT_NEW_LINE
Target_MysqlDB "$GET_REDUN_INDEX_SQL"
OUT_PUT_NEW_LINE
Target_MysqlDB "$GET_TABLE_STATIS_SQL"
OUT_PUT_NEW_LINE
Target_MysqlDB "$GET_BUF_HOT_TABLE_SQL"
OUT_PUT_NEW_LINE
Target_MysqlDB "$GET_UNUSED_INDEX_SQL"
OUT_PUT_NEW_LINE
OUTPUT_TITLE_02 "Statement INFO"
Target_MysqlDB "$GET_FULL_TABLE_SCAN_SQL"
OUT_PUT_NEW_LINE
Target_MysqlDB "$GET_STATEMENT_ANLAYZ_SQL"
OUT_PUT_NEW_LINE
Target_MysqlDB "$GET_FULL_SCAN_STATEMENT_SQL"
OUT_PUT_NEW_LINE
Target_MysqlDB "$GET_FILESORT_STATEMENT_SQL"
OUT_PUT_NEW_LINE
Target_MysqlDB "$GET_TEMP_STATEMENT_SQL"
OUT_PUT_NEW_LINE
OUTPUT_TITLE_02 "Current Process Info"
Target_MysqlDB "$GET_PROCESSLIST_SQL"
OUT_PUT_NEW_LINE
Target_MysqlDB "$GET_SESSION_SQL"
OUT_PUT_NEW_LINE
Target_MysqlDB "$GET_CURRENT_TABLE_LOCK_WAIT_SQL"
OUT_PUT_NEW_LINE
OUTPUT_TITLE_02 "Slow Log File"
SLOW_MysqlDB
OUT_PUT_TABLE_TAIL
OUT_PUT_NEW_LINE
OUT_PUT_back_to_top
##deadlock info
OUTPUT_TITLE "Innodb Status"
Target_MysqlDB "$GET_ENGINE_INNODB_SQL"
OUT_PUT_NEW_LINE
OUT_PUT_back_to_top
echo " End of Report " >>${CHECK_RESULT_FILE}
CREATE_HTML_END
sed -i 's/<TH>/<TH class="awrbg" scope="col">/g' ${CHECK_RESULT_FILE}
#============================HTML SGMENT END==============================
【备注】
如果自己需要添加内容的话,参考:
https://www.modb.pro/db/633746