日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > 数据库 >内容正文

数据库

mysql 5.7巡检脚本_mysql自动化巡检脚本生成html报告

發(fā)布時(shí)間:2025/3/20 数据库 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql 5.7巡检脚本_mysql自动化巡检脚本生成html报告 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

一、 前言

1、之前出了一篇oracle自動(dòng)巡檢腳本生成html報(bào)告和一篇Linux服務(wù)器系統(tǒng)自動(dòng)巡檢腳本生成html報(bào)告,本篇文章出一篇mysql自動(dòng)巡檢腳本生成html報(bào)告。

2、腳本只提供部分簡(jiǎn)單的巡檢內(nèi)容,如binlog信息、數(shù)據(jù)庫(kù)運(yùn)行信息,還有些mysql的一些重要參數(shù)配置,其他的巡檢內(nèi)容大家根據(jù)實(shí)際需要編輯修改,增加符合自己需求的巡檢內(nèi)容。

3、項(xiàng)目已經(jīng)上傳到我的github上

項(xiàng)目地址:mywatch.git

二、注意事項(xiàng)與報(bào)告部分截圖

注意閱讀git上的README.md說(shuō)明

三、README.md

1、需要使用root用戶執(zhí)行

2、使用說(shuō)明

多實(shí)例下運(yùn)行此腳本時(shí),要注意區(qū)分不同實(shí)例的root用戶密碼與對(duì)應(yīng)端口號(hào)

myuser="root"

mypasswd="XXXXX"

myip="localhost"

myport="3306"

3、執(zhí)行完巡檢之后,將在腳本所在的路徑下生成html巡檢結(jié)果報(bào)告,如下192.168.35.244os_mysql_simple_summary.html

4、巡檢項(xiàng)信息如下(其他統(tǒng)計(jì)項(xiàng)可根據(jù)實(shí)際需要自行添加)

0)、巡檢ip信息

1)、數(shù)據(jù)庫(kù)基本信息與binlog參數(shù)信息

2)、數(shù)據(jù)庫(kù)運(yùn)行狀況信息

3)、數(shù)據(jù)庫(kù)一些重要參數(shù)配置信息

四、腳本內(nèi)容

#!/bin/bash

ipaddress=`ip a|grep "global"|awk '{print $2}' |awk -F/ '{print $1}'`

file_output=${ipaddress}'os_mysql_simple_summary.html'

td_str=''

th_str=''

myuser="root"

mypasswd="XXXXX"

myip="localhost"

myport="3306"

mysql_cmd="mysql -u${myuser} -p${mypasswd} -h${myip} -P${myport} --protocol=tcp --silent"

#yum -y install bc sysstat net-tools

create_html_css(){

echo -e "

body {font:12px Courier New,Helvetica,sansserif; color:black; background:White;}

table,tr,td {font:12px Courier New,Helvetica,sansserif; color:Black; background:#FFFFCC; padding:0px 0px 0px 0px; margin:0px 0px 0px 0px;}

th {font:bold 12px Courier New,Helvetica,sansserif; color:White; background:#0033FF; padding:0px 0px 0px 0px;}

h1 {font:bold 12pt Courier New,Helvetica,sansserif; color:Black; padding:0px 0px 0px 0px;}

}

create_html_head(){

echo -e "

$1

"

}

create_table_head1(){

echo -e "

}

create_table_head2(){

echo -e "

}

create_td(){

td_str=`echo $1 | awk 'BEGIN{FS="|"}''{i=1; while(i<=NF) {print "

"$i"";i++}}'`

}

create_th(){

th_str=`echo $1|awk 'BEGIN{FS="|"}''{i=1; while(i<=NF) {print "

"$i"";i++}}'`

}

create_tr1(){

create_td "$1"

echo -e "

$td_str

" >> $file_output

}

create_tr2(){

create_th "$1"

echo -e "

$th_str

" >> $file_output

}

create_tr3(){

echo -e "

`cat $1`

" >> $file_output

}

create_table_end(){

echo -e "

"

}

create_html_end(){

echo -e ""

}

NAME_VAL_LEN=12

name_val () {

printf "%+*s | %s\n" "${NAME_VAL_LEN}" "$1" "$2"

}

get_netinfo(){

echo "interface | status | ipadds | mtu | Speed | Duplex" >>/tmp/tmpnet_h1_`date +%y%m%d`.txt

for ipstr in `ifconfig -a|grep ": flags"|awk '{print $1}'|sed 's/.$//'`

do

ipadds=`ifconfig ${ipstr}|grep -w inet|awk '{print $2}'`

mtu=`ifconfig ${ipstr}|grep mtu|awk '{print $NF}'`

speed=`ethtool ${ipstr}|grep Speed|awk -F: '{print $2}'`

duplex=`ethtool ${ipstr}|grep Duplex|awk -F: '{print $2}'`

echo "${ipstr}" "up" "${ipadds}" "${mtu}" "${speed}" "${duplex}"\

|awk '{print $1,"|", $2,"|", $3,"|", $4,"|", $5,"|", $6}' >>/tmp/tmpnet1_`date +%y%m%d`.txt

done

}

my_base_info(){

${mysql_cmd} -e "select now(),current_user(),version()\G"

${mysql_cmd} -e "show global variables like 'autocommit';"|grep -i ^auto|awk '{print $1,":",$2}'

${mysql_cmd} -e "show variables like '%binlog%';"|awk '{print $1,":",$2}'

${mysql_cmd} -e "show variables like 'innodb_flush%';"|awk '{print $1,":",$2}'

}

my_stat_info(){

${mysql_cmd} -e status >>/tmp/tmpmy_stat_`date +%y%m%d`.txt

}

my_param_info(){

echo "Variable_name|Value" >>/tmp/tmpmy_param_h1_`date +%y%m%d`.txt

${mysql_cmd} -e "show global variables"|egrep -w "innodb_buffer_pool_size|innodb_file_per_table|innodb_flush_log_at_trx_commit|innodb_io_capacity|\

innodb_lock_wait_timeout|innodb_data_home_dir|innodb_log_file_size|innodb_log_files_in_group|log_slave_updates|long_query_time|lower_case_table_names|\

max_connections|max_connect_errors|max_user_connections|query_cache_size|query_cache_type |server_id|slow_query_log|slow_query_log_file|innodb_temp_data_file_path|\

sql_mode|gtid_mode|enforce_gtid_consistency|expire_logs_days|sync_binlog|open_files_limit|myisam_sort_buffer_size|myisam_max_sort_file_size"\

|awk '{print $1,"|",$2}' >>/tmp/tmpmy_param_t1_`date +%y%m%d`.txt

}

create_html(){

rm -rf $file_output

touch $file_output

create_html_css >> $file_output

create_html_head "Network Info Summary" >> $file_output

create_table_head1 >> $file_output

get_netinfo

while read line

do

create_tr2 "$line"

done < /tmp/tmpnet_h1_`date +%y%m%d`.txt

while read line

do

create_tr1 "$line"

done < /tmp/tmpnet1_`date +%y%m%d`.txt

create_table_end >> $file_output

create_html_head "Basic Database && binlog Information" >> $file_output

create_table_head1 >> $file_output

my_base_info >>/tmp/tmpmy_base_`date +%y%m%d`.txt

sed -i -e '1d' -e 's/:/|/g' /tmp/tmpmy_base_`date +%y%m%d`.txt

while read line

do

create_tr1 "$line"

done

create_table_end >> $file_output

create_html_head "Running Status of Database" >> $file_output

create_table_head1 >> $file_output

my_stat_info

create_tr3 "/tmp/tmpmy_stat_`date +%y%m%d`.txt"

create_table_end >> $file_output

create_html_head "Important Parameters" >> $file_output

create_table_head1 >> $file_output

my_param_info

while read line

do

create_tr2 "$line"

done < /tmp/tmpmy_param_h1_`date +%y%m%d`.txt

while read line

do

create_tr1 "$line"

done < /tmp/tmpmy_param_t1_`date +%y%m%d`.txt

create_table_end >> $file_output

create_html_end >> $file_output

sed -i 's/BORDER=1/width="68%" border="1" bordercolor="#000000" cellspacing="0px" style="border-collapse:collapse"/g' $file_output

rm -rf /tmp/tmp*_`date +%y%m%d`.txt

}

# This script must be executed as root

RUID=`id|awk -F\( '{print $1}'|awk -F\= '{print $2}'`

if [ ${RUID} != "0" ];then

echo"This script must be executed as root"

exit 1

fi

PLATFORM=`uname`

if [ ${PLATFORM} = "HP-UX" ] ; then

echo "This script does not support HP-UX platform for the time being"

exit 1

elif [ ${PLATFORM} = "SunOS" ] ; then

echo "This script does not support SunOS platform for the time being"

exit 1

elif [ ${PLATFORM} = "AIX" ] ; then

echo "This script does not support AIX platform for the time being"

exit 1

elif [ ${PLATFORM} = "Linux" ] ; then

echo -e "

###########################################################################################

#Make sure that the following parameters at the beginning of the script are correct.

#myuser="root" (Database Account)

#mypasswd="XXXXXX" (Database password)

#myip="localhost" (Database native IP)

#myport="3306" (Database port)

#--> Otherwise, the script cannot be executed properly.

#GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' identified by 'XXXXX' WITH GRANT OPTION;

#flush privileges;

###########################################################################################

"

create_html

fi

總結(jié)

以上是生活随笔為你收集整理的mysql 5.7巡检脚本_mysql自动化巡检脚本生成html报告的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。