Shell脚本监控Centos 7系统运行状态
#!/usr/bin/bash
## @date: 2021-08-17
## This is a script for security operation indicator monitoring! export LANG="zh_CN.UTF-8" ##当前系统时间 DATE_time=$(date -d "0 day" +%Y年%m月%d日%H时%M分%S秒) ##服务器IP地址 IP_addr=$(ifconfig eth0 | grep inet | grep -v inet6 | awk '{print $2}') ##CPU占用率 CPU=100.0
CPU_free=$(top -b -n 1 | grep Cpu | awk '{print $8}')
CPU_used=$(awk 'BEGIN{printf "%.1f%\n",'$CPU' - '$CPU_free'}')
sleep 2
##内存使用率 RAM_total=$(free -m | grep Mem | awk '{print $2}')
RAM_used=$(free -m | grep Mem | awk '{print $3}')
RAM_percent=$(awk 'BEGIN{printf "%.1f%\n",('$RAM_used'/'$RAM_total')*100}')
sleep 2 ##磁盘使用率 Disk_totalSpace=$(df -m | sed '1d;/ /!N;s/\n//;s/ \+/ /;' | awk '{totalSpace+=$2} END{print totalSpace}')
Disk_used=$(df -m | sed '1d;/ /!N;s/\n//;s/ \+/ /;' | awk '{used+=$3} END{print used}')
Disk_percent=$(awk 'BEGIN{printf "%.1f%\n",('$Disk_used'/'$Disk_totalSpace')*100}')
sleep 2 ##带宽使用率 ##执行查看带宽命令,10秒内执行5次,取平均值 i=1
Receive_result=0.000
Transmit_result=0.000
while(($i<=5))
do
Receive_before=$(cat /proc/net/dev | grep 'eth' | tr : " " | awk '{print $2}')
Transmit_before=$(cat /proc/net/dev | grep 'eth' | tr : " " | awk '{print $10}')
sleep 2
Receive_after=$(cat /proc/net/dev | grep 'eth' | tr : " " | awk '{print $2}')
Transmit_after=$(cat /proc/net/dev | grep 'eth' | tr : " " | awk '{print $10}') Receive_bandwidth=$(awk 'BEGIN{printf "%.3f\n",('$Receive_after'-'$Receive_before')/1024/1024/2*8}')
Transmit_bandwidth=$(awk 'BEGIN{printf "%.3f\n",('$Transmit_after'-'$Transmit_before')/1024/1024/2*8}') Receive_result=$(awk 'BEGIN{printf "%.3f\n",('$Receive_result'+'$Receive_bandwidth')}')
Transmit_result=$(awk 'BEGIN{printf "%.3f\n",('$Transmit_result'+'$Transmit_bandwidth')}') let "i++"
done Receive_average=$(awk 'BEGIN{printf "%.3fMbps\n",('$Receive_result'/5)}')
Transmit_average=$(awk 'BEGIN{printf "%.3fMbps\n",('$Transmit_result'/5)}')
Shell脚本监控Centos 7系统运行状态的更多相关文章
- shell脚本监控Linux系统性能指标
2016-11-04 22:41 原作者不详 分类: Linux(7) 在服务器运维过程中,经常需要对服务器的各种资源进行监控, 例如:CPU的负载监控,磁盘的使用率监控,进程数目监控等等,以在系统出 ...
- 用shell脚本监控进程是否存在 不存在则启动的实例
用shell脚本监控进程是否存在 不存在则启动的实例,先上代码干货: #!/bin/shps -fe|grep processString |grep -v grepif [ $? -ne 0 ]th ...
- linux shell脚本监控进程是否存在
用shell脚本监控进程是否存在 不存在则启动的实例,先上代码干货: #!/bin/shps -fe|grep processString |grep -v grepif [ $? -ne 0 ...
- Linux简单Shell脚本监控MySQL、Apache Web和磁盘空间
Linux简单Shell脚本监控MySQL.Apache Web和磁盘空间 1. 目的或任务 当MySQL数据库.Apache Web服务器停止运行时,重新启动运行,并发送邮件通知: 当服务器磁盘的空 ...
- shell脚本监控网站状态
shell脚本监控网站状态 #!/bin/sh date=`date +"%Y%m%d-%H%M"` title="status" contentFail=&q ...
- Shell脚本监控专线Network并SendEmail报警
Much effort, much prosperity. 配置服务器监控专线网络 项目介绍: 配置一台服务器监控专线网络的情况,(由于公司业务的原因需要用到专线进行与客户对接)实时监控专线的状态,如 ...
- 用shell脚本监控MySQL主从同步
企业面试题1:(生产实战案例):监控MySQL主从同步是否异常,如果异常,则发送短信或者邮件给管理员.提示:如果没主从同步环境,可以用下面文本放到文件里读取来模拟:阶段1:开发一个守护进程脚本每30秒 ...
- shell脚本监控MySQL服务是否正常
监控MySQL服务是否正常,通常的思路为:检查3306端口是否启动,ps查看mysqld进程是否启动,命令行登录mysql执行语句返回结果,php或jsp程序检测(需要开发人员开发程序)等等: 方法1 ...
- Linux/Unix shell 脚本监控磁盘可用空间
Linux下监控磁盘的空闲空间的shell脚本,对于系统管理员或DBA来说,必不可少.下面是给出的一个监控磁盘空间空间shell脚本的样本,供大家参考. 1.监控磁盘的空闲空间shell脚本 robi ...
- shell 脚本监控linux
[root@dn3 data]# cat monitor.sh #!/bin/bash cpu_idle=$(top -n2|grep 'Cpu'|tail -n 1|awk '{print $8}' ...
随机推荐
- Myeclipse导入项目提示已存在(Some projects cannot be imported because they already exist in the workspace)
原因:在项目空间的文件夹中没有删除干净之前的项目,之前的项目和要导入的项目的名字相同,所以导致无法将项目导入.需要在项目空间中将有关的旧文件都清理干净. 1.将项目空间文件夹中的项目删除. 2.到:\ ...
- 严重 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.StandardContext.listenerStart Error configuring application listener of class com.titan.extend.SpringContextLoaderListener
08-Jun-2022 10:05:21.119 严重 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.StandardConte ...
- 1903021126 申文骏 Java 第二周作业 代码编写及运行
项目 内容 课程班级博客链接 19级信计班(本) 作业要求链接 Java第二周作业 博客名称 1903021126 申文骏 Java 第二周作业 代码编写及运行 要求 每道题要有题目,代码(使用插入代 ...
- tomcat 重启脚本
1 创建脚本后将脚本放到tomcat/bin目录下并授权,就可以通过此脚本一键重启拉! #!/bin/bash tomcat_path1="$( cd "$( dirname &q ...
- uniapp里面设置onlaunch以后在加载页面调接口
main.js 里面 Vue.prototype.$onLaunched = new Promise(resolve => { Vue.prototype.$isResolve = resolv ...
- 上分之路 VP Codeforces Round #744 (Div. 3) ABDE
VP情况 4 / 8 AC: A,B,D,E1 60 minutes WA: C 4 127 +00:02 +00:28 -7 +00:58 +00:39 手速还在线 D pair排个 ...
- 实验8 python库应用编程与体验
3.实验任务3 from turtle import * def square(size=50, rgb='orange'): '''绘制正方形 参数size指定边长 参数rgb指定画笔颜色 如果没有 ...
- Python爬虫之用Selenium做爬虫
我们在用python做爬虫的时候,除了直接用requests的架构,还有Scrapy.Selenium等方式可以使用,那么今天我们就来聊一聊使用Selenium如何实现爬虫. Selenium是什么? ...
- go tour 笔记 day1
go get 访问github太慢需要配置代理,设置环境变量 http_proxy=http://127.0.0.1:xxxx 算是比较方便的一种 ref: https://blog.csdn.net ...
- 12.7 linux学习第十四天
今天老刘开始讲第10章,主要讲Ahache服务和SELinux安全子系统 10.1 网站服务程序 1970年,作为互联网前身的ARPANET(阿帕网)已初具雏形,并开始向非军用部门开放,许多大学和商业 ...