mysql自动化巡检_mysql自动化巡检脚本生成html报告
一、 前言
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
来源:51CTO
作者:love8度幸福
链接:https://blog.51cto.com/8355320/2584913
mysql自动化巡检_mysql自动化巡检脚本生成html报告相关推荐
- mysql 5.7巡检脚本_mysql自动化巡检脚本生成html报告
一. 前言 1.之前出了一篇oracle自动巡检脚本生成html报告和一篇Linux服务器系统自动巡检脚本生成html报告,本篇文章出一篇mysql自动巡检脚本生成html报告. 2.脚本只提供部分简 ...
- Linux服务器系统自动巡检脚本生成html报告
一. 前言 1.在上一篇文章里给大家介绍oracle自动巡检脚本生成html报告,这篇文章介绍linux服务巡检脚本生成html报告. 2.脚本依然是简单脚本语句的堆积,方便大家二次编辑使用. 3.项 ...
- mysql 自动化 安装_mysql自动化安装
MySQL安装一般使用RPM或者源码安装的方式. RPM安装的优点是快速,方便.缺点是不能自定义安装目录.如果需要调整数据文件和日志文件的存放位置,还需要进行一些手动调整. 源码安装的优点是可以自定义 ...
- 执行jmeter脚本生成html报告解读
我么执行脚本之后,会生成result结果文件,我们在服务器里面打包之后下载下来,打开查看分析结果 一.执行脚本 1.首先我们得在本地,也就是客户端调试好脚本之后,放在服务器上上面跑 就是图片中保存文件 ...
- mysql 自动化 安装_MySQL自动化安装脚本
注:因官方MySQL下载较慢,请先自行上传mysql安装包至/usr/local/src目录 #!/bin/bash #This shell script can be used to install ...
- 开源mysql执行平台_MySQL自动化审核平台部署说明
背景: 关于MySQL的审核的重要性就不说明了,本文的自动化审核是通过Inception和SQLAdvisor实现的,具体的使用可以看它们各自的说明文档.这里大致介绍下如何部署和使用它们,其实该文章也 ...
- mysql数据库数据恢复_Mysql数据库delete删除后数据恢复报告
数据库环境部署与故障原因: 本次恢复的数据库安装在客户本地服务器上,服务器操作系统为windows2008 r2 .在当前环境内安装有mysql5.6单实例,引擎类型为innodb,表内数据存储所使用 ...
- java解析jtl_在linux底下搭建JDK+jmeter环境,并执行脚本生成聚合报告.jtl文件到本地查看...
linux环境下搭建jdk 1.可本地直接上传压缩包,直接使用tar zxvf 安装包名称 解压缩(ps:在上传文件之前可先另外新建一个文件夹,一般是上传到当前文件夹) 2.可直接通过wget命令在 ...
- palapaweb的mysql无法运行_Mysql 服务无法启动 服务没有报告任何错误
今天以zip模式在windows10 64位环境下安装mysql5.7,到最后一步提示mysql服务无法启动. 安装步骤如下: 1.配置环境变量 我的电脑->属性->高级->环境变量 ...
最新文章
- 【树莓派】制作树莓派最小镜像:img裁剪瘦身
- oracle net manager没有orcl_Oracle-数据库基础知识
- 重视B/S架构系统的发展和开发设计理念
- 命令 / Linux / 常用的解压缩的命令
- 工作多年的.NET程序员,是否建立了自己的开发知识库?分享制作电子书的经验...
- jzoj6290-倾斜的线【计算几何,贪心】
- mysql中创建唯一索引的关键字_mysql中唯一索引的关键字是什么
- Ubuntu中Python3找不到_sqlite3模块
- 特斯拉又烧一辆!车库里起火 所幸无人受伤
- jquery.validate动态更改校验规则
- 软考-软件设计师 知识点整理(一篇就过了 建议收藏)
- 视易收银系统怎样连接服务器,视易收银系统操作方法
- kuangbin14数论解析
- Android手势密码解锁设计
- Pygame做一期吃豆子游戏
- pyimagesearch-5 霍比特人和直方图 - 使用Python构建您的第一个图像搜索引擎的操作指南
- java聊天室类图怎么画,UML课程设计(java web网上聊天室附源码)
- 【文件类型转换】.mat后缀文件 转化为 .xml后缀文件
- 【每日分享】我做程序员那些年犯下的罪,此时此刻我自己的笑出猪叫~
- Poisoning Deep Learning based Recommender Model in Federated Learning Scenarios
热门文章
- MFC 给非控件添加ToolTip
- 宿主程序Crash与Lua是动态库还是静态库有关?
- Python学习笔记(四)—生成随机数
- selenium定位php,selenium之元素定位
- 大数据平台安全问题有哪些
- 大数据技术得发展方向如何
- 南开大学计算机学院夏令营,2022保研夏令营:南开大学计算机学院云端夏令营通知...
- php开源路由器,路由 - Symfony开源 - Symfony中国
- java bridge 模式_学习:java设计模式—Bridge模式
- echart单击后获取横坐标值_新、老、离职员工名单只要刷新一下就能轻松获取|Excel125...