#!/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系统运行状态的更多相关文章

  1. shell脚本监控Linux系统性能指标

    2016-11-04 22:41 原作者不详 分类: Linux(7) 在服务器运维过程中,经常需要对服务器的各种资源进行监控, 例如:CPU的负载监控,磁盘的使用率监控,进程数目监控等等,以在系统出 ...

  2. 用shell脚本监控进程是否存在 不存在则启动的实例

    用shell脚本监控进程是否存在 不存在则启动的实例,先上代码干货: #!/bin/shps -fe|grep processString |grep -v grepif [ $? -ne 0 ]th ...

  3. linux shell脚本监控进程是否存在

    用shell脚本监控进程是否存在 不存在则启动的实例,先上代码干货:    #!/bin/shps -fe|grep processString |grep -v grepif [ $? -ne 0 ...

  4. Linux简单Shell脚本监控MySQL、Apache Web和磁盘空间

    Linux简单Shell脚本监控MySQL.Apache Web和磁盘空间 1. 目的或任务 当MySQL数据库.Apache Web服务器停止运行时,重新启动运行,并发送邮件通知: 当服务器磁盘的空 ...

  5. shell脚本监控网站状态

    shell脚本监控网站状态 #!/bin/sh date=`date +"%Y%m%d-%H%M"` title="status" contentFail=&q ...

  6. Shell脚本监控专线Network并SendEmail报警

    Much effort, much prosperity. 配置服务器监控专线网络 项目介绍: 配置一台服务器监控专线网络的情况,(由于公司业务的原因需要用到专线进行与客户对接)实时监控专线的状态,如 ...

  7. 用shell脚本监控MySQL主从同步

    企业面试题1:(生产实战案例):监控MySQL主从同步是否异常,如果异常,则发送短信或者邮件给管理员.提示:如果没主从同步环境,可以用下面文本放到文件里读取来模拟:阶段1:开发一个守护进程脚本每30秒 ...

  8. shell脚本监控MySQL服务是否正常

    监控MySQL服务是否正常,通常的思路为:检查3306端口是否启动,ps查看mysqld进程是否启动,命令行登录mysql执行语句返回结果,php或jsp程序检测(需要开发人员开发程序)等等: 方法1 ...

  9. Linux/Unix shell 脚本监控磁盘可用空间

    Linux下监控磁盘的空闲空间的shell脚本,对于系统管理员或DBA来说,必不可少.下面是给出的一个监控磁盘空间空间shell脚本的样本,供大家参考. 1.监控磁盘的空闲空间shell脚本 robi ...

  10. shell 脚本监控linux

    [root@dn3 data]# cat monitor.sh #!/bin/bash cpu_idle=$(top -n2|grep 'Cpu'|tail -n 1|awk '{print $8}' ...

随机推荐

  1. python菜鸟学习: 8. 集合基础知识

    # -*- coding: utf-8 -*-# 列表的特性:1,去重:2.关系测试list1 = [1, 4, 6, 8, 7, 8, 9]# 集合去重list2 = set(list1)print ...

  2. 解决vue 移动端项目“切换页面,页面置顶”后报错为:"TypeError: Cannot set property 'scrollTop' of null"

    参考原代码链接:https://www.cnblogs.com/wayneliu007/p/11932204.html 报错截图:  解决方法: 导入的getScrollParent为真返回的null ...

  3. uiautomator2自动化工具的下载与安装

    前言: 相信很多使用appium做过APP自动化的人都深有感触: 1,安装麻烦,配置环境可能会难道不少人 2,appium运行慢.时间长 3,uiautomatorviewer定位元素时得关掉appi ...

  4. epoll 基本知识与使用

    https://blog.csdn.net/qq_35721743/article/details/86742508 epoll 最大的好处在于它不会随着监听 fd 数目的增长而降低效率. epoll ...

  5. Python模块——os模块详解

  6. C 语言 scanf 格式化输入函数

    C 语言 scanf 格式化输入函数 函数概要 scanf 函数从标准输入流中读取格式化字符串.与 printf 格式化输出函数相反,scanf 函数是格式化输入函数. 函数原型 #include & ...

  7. 创建sqlSession对象操作数据库

    1.加载核心配置文件 //加载mybatis核心配置文件,获取SqlSessionFactory String resource = "mybatis-config.xml"; I ...

  8. oracle 用户连接数查询

    oracle 用户连接数查询 --当前的连接数 select count(*) from v$session; --数据库允许的最大连接数 select value from v$parameter ...

  9. Android 自定义View (三)

    一.前言 上节 讲解了旋转圆环基本的实现方法.本文将在此基础上进一步改进,在属性文件中自定义控件属性,避免代码中显式调用setXXX() 方法. 二.流程 首先,在资源文件 values 中新建一个 ...

  10. Spring AOP @before@after@around@afterreturning@afterthrowing执行顺序

    public Object aop(Method method,Object object) { try { try { /*doAround start*/ doBefore(); method.i ...