前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >shell实现脚本监控服务器及web应用

shell实现脚本监控服务器及web应用

作者头像
菲宇
发布2019-06-13 11:01:36
8990
发布2019-06-13 11:01:36
举报
文章被收录于专栏:菲宇

实际工作中我们需要知道部署在服务器上的应用有没有问题,但是人为的操作太麻烦有咩有简单的方式呢shell来监控我们服务器运行状态以及服务器上部署的应用,如果出现异常就会自动发送一个邮件给我们,开始搞起。。。 老套路,先梳理思路 监控apache web服务 监控mysql数据库 监控服务器硬盘使用情况 监控服务器的内存使用 1.apache web 服务器 !/bin/bash # 表示请求链接3秒钟,不要返回的测试数据 nc -w 3 localhost 80 &>/dev/null if [ $? -eq 0 ];then str="apache web status Running!" else str="apache web status Shuting!" fi # 发送的主题,邮件地址 echo str|mail -s 'apache web server' admin@lampym.com 2.监控mysql !/bin/bash # 表示请求链接3秒钟,不要返回的测试数据 nc -w 3 localhost 3306 &>/dev/null if [ $? -eq 0 ];then str="mysql server status Running!" else str="mysql server status Shuting!" fi # 发送的主题,邮件地址 echo str|mail -s 'mysql server status' admin@lampym.com 3.监控服务器disk #!/bin/bash :<<! NR表示行数,$5表示第5列,具体的自己根据实际调整 ! ds=`df |awk '{if(NR==4){print int($5)}}'` # 这里45根据实际需要更改 if [ $ds -lt 45 ];then str="disk space is less then!!!" else str="disk space is greate than 45%!!!" fi echo $str|mailx -s 'linux server disk space' admin@lampym.com 4.监控服务器monery  #!/bin/bash mery=`df |awk '{if(NR==2){print int($3*100/$2)}}'` if [ $mery -lt 50 ];then str="mery space is less then 50%!!!" else str="mery space is greate than 50%!!!" fi echo $str|mailx -s 'linux server mery space' admin@lampym.com  整合一下 #!/bin/bash # 功能:监控资源 # apache 应用服务 apache_web(){ nc -w 3 localhost 80 &>/dev/null   if [ $? -eq 0 ];then str="apache web status Running!"   else str="apache web status Shuting!"   fi     # 发送的主题,邮件地址   echo str|mail -s 'apache web server' admin@lampym.com } # mysql 服务 mysql_db(){ nc -w 3 localhost 3306 &>/dev/null if [ $? -eq 0 ];then str="mysql server status Running!" else str="mysql server status Shuting!" fi # 发送的主题,邮件地址 echo str|mail -s 'mysql server status' admin@lampym.com } # 磁盘使用情况 disk_mnt(){ ds=`df |awk '{if(NR==4){print int($5)}}'` # 这里45根据实际需要更改 if [ $ds -lt 45 ];then str="disk space is less then!!!" else str="disk space is greate than 45%!!!" fi echo $str|mailx -s 'linux server disk space' admin@lampym.com } # 内存使用情况 meny_mnt(){ mery=`df |awk '{if(NR==2){print int($3*100/$2)}}'` if [ $mery -lt 50 ];then str="mery space is less then 50%!!!" else str="mery space is greate than 50%!!!" fi echo $str|mailx -s 'linux server mery space' admin@lampym.com } min(){ apache_web() mysql_db() disk_mnt() meny_mnt() }

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019年01月09日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 SQL Server
腾讯云数据库 SQL Server (TencentDB for SQL Server)是业界最常用的商用数据库之一,对基于 Windows 架构的应用程序具有完美的支持。TencentDB for SQL Server 拥有微软正版授权,可持续为用户提供最新的功能,避免未授权使用软件的风险。具有即开即用、稳定可靠、安全运行、弹性扩缩等特点。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档