一、 前言

1、之前出了一篇oracle自动巡检脚本生成html报告和一篇Linux服务器系统自动巡检脚本生成html报告,本篇文章出一篇mysql自动巡检脚本生成html报告。

2、脚本只提供部分简单的巡检内容,如binlog信息、数据库运行信息,还有些mysql的一些重要参数配置,其他的巡检内容大家根据实际需要编辑修改,增加符合自己需求的巡检内容。

3、项目已经上传到我的github上

项目地址:mywatch.git

二、注意事项与报告部分截图

注意阅读git上的README.md说明

三、README.md

1、需要使用root用户执行

2、使用说明

多实例下运行此脚本时,要注意区分不同实例的root用户密码与对应端口号

myuser="root"

mypasswd="XXXXX"

myip="localhost"

myport="3306"

3、执行完巡检之后,将在脚本所在的路径下生成html巡检结果报告,如下192.168.35.244os_mysql_simple_summary.html

4、巡检项信息如下(其他统计项可根据实际需要自行添加)

0)、巡检ip信息

1)、数据库基本信息与binlog参数信息

2)、数据库运行状况信息

3)、数据库一些重要参数配置信息

四、脚本内容

#!/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

mysql 5.7巡检脚本_mysql自动化巡检脚本生成html报告相关推荐

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

    一. 前言 1.之前出了一篇oracle自动巡检脚本生成html报告和一篇Linux服务器系统自动巡检脚本生成html报告,本篇文章出一篇mysql自动巡检脚本生成html报告. 2.脚本只提供部分简 ...

  2. mysql巡检脚本_mysql 服务器巡检脚本

    #! /bin/bash ### AUTHOR: cenliang ### EMAIL: xuanniaoxi@sina.com ### DATE:2018/03/22### REV:3.0# 数据库 ...

  3. ubuntu mysql自动补全_mysql自动化安装脚本(ubuntu and centos64)

    Ubuntu Mysql自动化安装脚本 #/bin/bash function hasDpkg { r=`dpkg -l | grep "$1"` if [ -n "$r ...

  4. python代替shell脚本_自动化shell脚本except与python的pexpect模块

    expect脚本 expect是什么 expect是一个免费的编程工具,用来实现自动的交互式任务,而无需人为干预.说白了,expect就是一套用来实现自动交互功能的软件. 在实际工作中,我们运行命令. ...

  5. python+requests+excel+unittest+ddt接口自动化数据驱动并生成html报告(二)

    可以参考 python+requests接口自动化完整项目设计源码(一)https://www.cnblogs.com/111testing/p/9612671.html 原文地址https://ww ...

  6. mysql 增量备份脚本_MySQL自动化(全量+增量)备份脚本

    一.MySQL的日常备份方案: 全备+增量备份: 1.周日凌晨三点进行全备: 2.周一到周日增量备份. 不是往常的周日全备份,周一到周六增量备份,这样如果周日数据库在完全备份前出问题,恢复完成后,会少 ...

  7. mysql数据库巡检方案_Mysql数据库巡检

    DBA需要经常的对数据库进行一些检查,如数据库磁盘的占用量,缓存的命中率,内存的分配等,目的为简化频繁输入这些繁琐的命令. #!/bin/bash ########################## ...

  8. mysql 自动化 安装_MySQL自动化安装脚本

    注:因官方MySQL下载较慢,请先自行上传mysql安装包至/usr/local/src目录 #!/bin/bash #This shell script can be used to install ...

  9. mysql.server 文件是什么_mysql的启动脚本mysql.server及示例配置文件

    以MySQL-server-4.0.14-0.i3862881064151.rpm为例,放在/data目录下 cd /data rpm -ivh MySQL-server-4.0.14-0.i386. ...

最新文章

  1. zookeeper和duboo 没用
  2. youtube根据channelId抓取栏目
  3. AI:2020年6月22日北京智源大会演讲分享之11:30-12:20Jorge教授《Zero-Order Optimization Methods with Applications to RL》
  4. 海南电网全力支持新能源发展
  5. IE内置的WebBrowser控件之--WEB打印
  6. Python-Numpy的tile函数
  7. 代码单元测试工具:gmock
  8. java模拟连接超时_Java:使用Toxiproxy模拟各种连接问题
  9. 架构师一般做到多少岁_《迷茫中的我们该如何突破瓶颈——成长为一名架构师》...
  10. c# 智能升级程序代码(1)
  11. Java thread(4)
  12. 社交系统ThinkSNS可以运营什么?可以应用于什么场景?
  13. 关于蓝桥杯竞赛考试的一些信息~
  14. 数据库建模工具PowerDesigner的基本使用方法
  15. Ubuntu安装搜 狗输入法,最完整的步骤
  16. YOLOv5电车识别 电瓶车识别
  17. 华为智选 720 全效空气净化器 评测
  18. Docker安装Kong
  19. apache Ignite 节点生命周期事件例子
  20. 5G网络的NSA与SA

热门文章

  1. React.js核心原理实现:首次渲染机制
  2. 剑指 offer set 19 翻转单词顺序 字符串左旋
  3. JFace中Dialog类的使用方法
  4. mac os 升级为Mountain Lion后,eclipse找不到JRE的问题
  5. C#中判断某软件是否已安装
  6. [图示]做人36字诀:二)形象塑造 ——教你品格高雅
  7. 微软超融合私有云测试28-SCDPM2016部署之SCDPM基础配置(添加备份介质、推送代理)...
  8. 国产Dhyana禅定x86处理器开始启动生产
  9. window.print只打印了1页的原因
  10. 基于Vue.js的精选壁纸推荐单页应用