1 Star 3 Fork 2

ywlianghang / mycheck

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
contribute
Sync branch
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README
Apache-2.0

MySQL 实例深度巡检


Introductory

 您是否遇到过如下困扰:
   1)某一天业务反馈插入数据失败,经过排查自增id的数据类型溢出了,严重影响业务,而表数据量又很大,操作时间长,导致领导层震荡,小兵遭殃
   2)当前业务库下有多少个表字符集不是utf8或utf8mb4?
   3)当前业务库中有多少表引擎是非innodb?
   4)当前业务库是否存在冗余索引,存在多少?
   5)当前还有多少表没有自增主键,多少库还在用存储过程或触发器等?
   6)一些影响性能或安全的动态参数是否被修改,导致重启后或压力大时造成故障?
   7)当前业务库中存在哪些大表、表空间多大,表平均行度多大,是否需要通知业务进行大表的数据处理
   8)在出现重大节日保障、节庆促销、日常巡检(早高峰、下班后)时我们如何了解当前业务库是否能抗住压力不出现问题,让领导放心,让媳妇开心?
   等等
 针对如上问题,我开始针对MySQL实例中特定的检测项(影响安全与性能)进行分层次梳理,制定相应检查项的检测方法,为了减少重复性工作,减少手动巡检所浪费的时间开始使用go进行编写解放双手的工具,做一名合格的农民工。

1)目前支持的检测项功能:
  1.1 数据库环境检查
      由于还在考虑,数据库环境是否需要检查,该检查哪些项,暂时还未实现该功能,不过接口以预留

  1.2 数据库配置检查
    1.2.01 双一是否设置  (sync_binlog、innodb_flush_log_at_trx_commit)
    1.2.02 只读权限是否关闭(tx_read_only、transaction_read_only、innodb_read_only、read_only、super_read_only)
    1.2.03 binlog格式是否为row(binlog_format=row)
    1.2.04 server端字符集是否为utf8(character_set_server=utf8)
    1.2.05 默认的密码认证插件是否为mysql_native_passwor(default_authentication_plugin)
    1.2.06 默认存储引擎及临时表的存储引擎是否为innodb(default_storage_engine、default_tmp_storage_engine、internal_tmp_disk_storage_engine)
    1.2.07 innodb脏页刷盘方式是否为O_DIRECT(innodb_flush_method)
    1.2.08 是否开启了死锁检测(innodb_deadlock_detect)
    1.2.09 查询缓存是否关闭(query_cache_type)
    1.2.10 与从库中继日志相关的参数(relay_log_purge=on,relay_log_recovery=on)
    1.2.11 检查当前事务隔离级别(transaction_isolation=READ-COMMITTED,tx_isolation=READ-COMMITTED)
    1.2.12 检查当前数据库的时区(system_time_zone=CTS,time_zone=system)
    1.2.13 检查是否开启了主键索引和唯一索引的重复行校验(unique_checks=on)

  1.3 数据库性能检查
    1.3.01 检测binlog落盘时使用磁盘的利用率(巡检项:binlogDiskUsageRate)
    1.3.02 历史最大连接数占最大连接数限制的百分比(巡检项:historyConnectionMaxUsageRate)
    1.3.03 创建临时磁盘表使用率(巡检项:tmpDiskTableUsageRate)
    1.3.04 创建临时磁盘文件使用率(巡检项:tmpDiskfileUsageRate)
    1.3.05 innodb buffer pool使用率(巡检项:innodbBufferPoolUsageRate)
    1.3.06 当前innodb buffer pool中脏页比例(巡检项:innodbBufferPoolUsageRate)
    1.3.07 当前innodb buffer pool命中率(巡检项:innodbBufferPoolHitRate)
    1.3.08 数据库文件句柄使用率(巡检项:openFileUsageRate)
    1.3.09 数据库表缓存率(巡检项:openTableCacheUsageRate)
    1.3.10 数据库表缓存溢出率(巡检项:openTableCacheOverflowsUsageRate)
    1.3.11 数据库全表扫描占比率(巡检项:selectScanUsageRate)
    1.3.12 数据库join语句全表扫描占比率(巡检项:selectfullJoinScanUsageRate)
    1.3.13 数据库表自增主键使用率(判断有符号及无符号int类型)(巡检项:tableAutoPrimaryKeyUsageRate)
    1.3.14 单表行数大于500w,且平均行长大于10KB(巡检项:tableRows)
    1.3.15 单表大于6G,并且碎片率大于30%(巡检项:diskFragmentationRate)
    1.3.16 单表行数大于1000W,且表空间大于30G(巡检项:bigTable)
    1.3.17 检查一个星期内未更新的表(巡检项:coldTable)

  1.4 数据库基线检查
    1.4.01 检查表字符集(输出非utf8或utf8mb4的表)(巡检项:tableCharset)
    1.4.02 检查引擎不是innodb的表(巡检项:tableEngine)
    1.4.03 检查表是否有外键关联(巡检项:tableForeign)
    1.4.04 检查表是否有自增主键(巡检项:tableNoPrimaryKey)
    1.4.05 检查主键自增列是否为bigint(巡检项:tableAutoIncrement)
    1.4.05 检查表中是否存在大字段blob、text、varchar(8099)、timestamp数据类型(巡检项:tableBigColumns)
    1.4.06 检查索引列是否允许为空(巡检项:indexColumnIsNull)
    1.4.07 检查索引列是否建立在enum或set类型上(巡检项:indexColumnIsEnumSet)
    1.4.08 检查索引列是否建立在blob或text上(巡检项:indexColumnIsBlobText)
    1.4.09 检查表中是否存在冗余索引(左匹配包含)(巡检项:tableIncludeRepeatIndex)
    1.4.10 检查库中是否存在存储过程(巡检项:tableProcedure)
    1.4.11 检查库中是否存在存储函数(巡检项:tableFunc)
    1.4.12 检查库中是否存在触发器(巡检项:tableTrigger)

  1.5 数据库安全检查
    1.5.01 检查实例是否存在匿名用户(巡检项:anonymousUsers)
    1.5.02 检查实例是否存在空密码用户(巡检项:emptyPasswordUser)
    1.5.03 检查实例是否存在root用户是否允许远端登录(root@%)(巡检项:rootUserRemoteLogin)
    1.5.04 检查实例是否存在普通用户无访问ip限制(user@%)(巡检项:normalUserConnectionUnlimited)
    1.5.05 检查实例是否存在密码相同的用户(巡检项:userPasswordSame)
    1.5.06 检查实例是否存在普通用户所有库表权限(on *.*)(巡检项:normalUserDatabaseAllPrivilages)
    1.5.07 检查实例是否存在普通用户supr权限(WITH GRANT OPTION)(巡检项:normalUserSuperPrivilages)
    1.5.08 检查实例是否使用默认端口(3306)(巡检项:databasePort)

2)mycheck下个版本改动(已完成):
(1)将配置参数检查外放,通过配置文件可进行自定义参数检测
(2)将巡检项进行外放,通过配置文件可进行巡检项控制(通过false、true选择是否检测该项)
(3)将巡检项阈值进行外放,通过配置文件可进行阈值调整(超过阈值才会出现在pdf巡检报告中)

3)mycheck后续功能更新
(1)增加数据库环境检查项
(2)新添巡检结果输出方式,html格式
(3)其他待续

4)问题反馈
  如果在使用中有什么问题,或者有什么好的建议及想法,欢迎随时发送到邮箱ywlianghang@gmail.com或ywlianghang@163.com或xing.liang@greatdb.com
  注:如果新添巡检功能或巡检项,请写出巡检方法,巡检阈值及巡检意义

Download

你可以从 这里 下载二进制可执行文件,我已经在ubuntu、centos、redhat、windows x64下测试过


Usage

工具使用说明

[root@lh-2 mycheck-linux-1.0]# ./mycheck -h
NAME:
    mycheck - In-depth inspection of MySQL for system guarantee and daily inspection during major festivals

USAGE:
    mycheck [global options] command [command options] [arguments...]

VERSION:
    1.0

AUTHOR:
    lianghang <ywlianghang@gmail.com>

COMMANDS:
    help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
    --config value, -c value  Loading a Configuration File. for example: --config /tmp/mycheck.ymal (default: "nil")
    --help, -h                show help
    --version, -v             print the version

Examples

 1) 执行巡检命令方式一
 shell> ./mycheck --config mycheck.ymal
 2)执行巡检命令方式二
 shell> ./mycheck --config /tmp/mycheck.ymal

Building

mycheck needs go version > 1.12 for go mod

shell> git clone https://github.com/ywlianghang/mycheck.git
shell> cd main
shell> go build -o mycheck main.go
shell> chmod +x mycheck
shell> mv mycheck /usr/bin

Requirements

巡检数据库实例必须为MySQL实例

Author

lianghang ywlianghang@gmail.com

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

No description expand collapse
Go
Apache-2.0
Cancel

Releases (2)

All

Contributors

All

Activities

Load More
can not load any more
Go
1
https://gitee.com/ywlianghang/mycheck.git
git@gitee.com:ywlianghang/mycheck.git
ywlianghang
mycheck
mycheck
master

Search