# total_monitor **Repository Path**: icefairy/total_monitor ## Basic Information - **Project Name**: total_monitor - **Description**: 无侵入性的统一监控服务 - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 3 - **Forks**: 0 - **Created**: 2021-12-28 - **Last Updated**: 2025-07-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # total_moitor使用说明 ## TODO -[x] 组件列表 -[x] 活跃接口 -[x] 维护手册 -[ ] 稳定性分析 ## 使用说明 + 登录后台配置好后可以直接访问免登陆的页面快速查看各组件状态,地址为`/list.html` ![](./docs/snipaste_20211228_125045.jpeg) ## 状态检测说明 + 脚本方式运行环境依赖Bash和curl,绝大多数linux发行版中都默认安装了,Windows服务器需要安装Git程序或者其他类似cygwin的bash仿真环境。 + 为防止接口被未授权调用,需要在curl请求时候带上指定的header和value,具体值在application.yml的tm段进行配置。 + 根据不同应用可以分别使用包括但不限于如下方式进行检测 + 根据curl访问特定端口,然后过滤特定的标志字符来确定状态(注意要设置超时时间) + 根据log文件中最后内容的时间与当前时间的差值来确定状态 + 根据进程是否存在来确定状态 + 根据网络端口监听状态来确定状态 + active接口还支持`note`和`extra`两个字段可以提交长文本的内容(只做最新版本的存储) ### 通用日志类检测 ```bash #根据是否有前一分钟的日志来确定状态 logf=logs/info_`date -I`.log checktime=`date -d "-1minute" +"%Y-%m-%d %H:%M"` res=`cat $logf | grep "$checktime" | wc -l` status=0 if [ $res -gt 0 ];then status=1; fi apihost='http://127.0.0.1:8081/monitor/active' id=8 #submit status curl -v $apihost -H "tmkey:tmvalue" --connect-timeout 3 -m 2 -F id=${id} -F status=${status} ``` ### 检测kafka状态 ```bash apihost='http://127.0.0.1:8081/monitor/active' id=2 status=`netstat -anop|grep LISTEN|grep ":9092 "|wc -l` #submit status curl -v $apihost -H "tmkey:tmvalue" --connect-timeout 3 -m 2 -F id=${id} -F status=${status} ``` ### 检测MariaDB状态(兼容Mysql mysql_native_password认证方式) ```bash apihost='http://127.0.0.1:8081/monitor/active' id=4 status=`curl --connect-timeout 3 -m 2 http://127.0.0.1:3306 |grep mysql_native_password|wc -l` #submit status curl -v $apihost -H "tmkey:tmvalue" --connect-timeout 3 -m 2 -F id=${id} -F status=${status} ``` ### 检测Mysql8状态(默认采用caching_sha2_password认证插件) ```bash apihost='http://127.0.0.1:8081/monitor/active' id=5 status=`curl --connect-timeout 3 -m 2 http://127.0.0.1:3307 |grep caching_sha2_password|wc -l` #submit status curl -v $apihost -H "tmkey:tmvalue" --connect-timeout 3 -m 2 -F id=${id} -F status=${status} ``` ### 根据实际查询检测mysql/mariadb状态 ```bash #此方法额外依赖mysql命令行 apihost='http://127.0.0.1:8081/monitor/active' id=5 status=`mysql -uthisisuser -pthisispassword -e "select 'test'" --skip-column-names|grep test|wc -l` #submit status curl -v $apihost -H "tmkey:tmvalue" --connect-timeout 3 -m 2 -F id=${id} -F status=${status} ``` ### 检测Redis状态(有密码) ```bash apihost='http://127.0.0.1:8081/monitor/active' id=1 status=`curl --connect-timeout 3 -m 1 http://127.0.0.1:6379 |grep NOAUTH|wc -l` #submit status curl -v $apihost -H "tmkey:tmvalue" --connect-timeout 3 -m 2 -F id=${id} -F status=${status} ``` ### 检测ElasticSearch状态 ```bash apihost='http://127.0.0.1:8081/monitor/active' id=5 #这里自行决定green为正常还是yellow也可以算正常 status=`curl --connect-timeout 3 -m 1 http://127.0.0.1:9200 |grep green|wc -l` #submit status curl -v $apihost -H "tmkey:tmvalue" --connect-timeout 3 -m 2 -F id=${id} -F status=${status} ``` ### 检测Postgresql状态 ```bash apihost='http://127.0.0.1:8081/monitor/active' id=2 status=`netstat -anop|grep LISTEN|grep ":5432 "|wc -l` #submit status curl -v $apihost -H "tmkey:tmvalue" --connect-timeout 3 -m 2 -F id=${id} -F status=${status} ``` ### 根据实际查询检测Postgresql/GreenPlum/MatrixDB状态 ```bash #此脚本一般在postgres用户下执行,且需要在pg_hba.conf中设置好local的免密登录,设置内容一般为`local all all trust` apihost='http://127.0.0.1:8081/monitor/active' id=2 status=`psql -c "select 'test'"|grep test|wc -l` #submit status curl -v $apihost -H "tmkey:tmvalue" --connect-timeout 3 -m 2 -F id=${id} -F status=${status} ``` ## 编译jar后手工复制依赖 `mvn dependency:copy-dependencies -DoutputDirectory=target\lib -DincludeScope=compile`