• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >linux shell > Linux shell脚本实现CPU预警

Linux shell脚本实现CPU预警

作者:hebedich 字体:[增加 减小] 来源:互联网

hebedich 通过本文主要向大家介绍了linux shell脚本,linux shell脚本攻略,linux shell脚本实例,linux常用shell脚本,linux编写shell脚本等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

如果CPU占用率持续达到80以上则调用打印java线程占用率堆栈的脚本,见https://github.com/oldratlee/useful-shells/blob/master/show-busy-java-threads.sh,具体用法见他的github wiki!

#!/bin/bash
#cpu idle percent
cpu_idle=`top -b -d 1 -n 2 | grep Cpu | awk 'NR>1{print $5}' | cut -f 1 -d "."`
 
if [ -d "/opt/scripts/log" ]
then
  cd /opt/scripts
else
  mkdir /opt/scripts/log
fi
 
count=0
condition=true
while condition
do
    if [ $cpu_idle -le 20 ]
    then
      pids=`top -b -d 1 -n 1 | grep java | awk '{if($9 > 80) print $1}'`
      for ((a = 1; a < 10; a++))
      do
       for pid in $pids
       doi
         #involve jdk existence check later
         date=`date +%Y%m%d%H%M`
         sh showstack.sh -c 30 -p $pid > log/stack_$pid_$date.log
         jstat -gcutil $pid > log/gc_$pid_$date.log
       done
      done
      for pid in $pids
      do
       date=`date +%Y%m%d%H%M`
       jmap -heap $pid > log/heap_$pid_$date.log
      done
      count++
      cpu_idle=`top -b -d 1 -n 2 | grep Cpu | awk 'NR>1{print $5}' | cut -f 1 -d "."`
      if [ $count -ge 3]
      then
       #send emaili
       #server ip address
       ip=`ifconfig eth0 | grep "inet addr" | cut -f 2 -d ":" | cut -f 1 -d " "`
       condition=false
       count=0
      fi
    else
      condition=false
      count=0
    fi
done
</div>

以上所述就是本文给大家分享的全部内容了,希望大家能够喜欢。

</div>

您可能想查找下面的文章:

  • 使用Linux shell脚本实现FTP定时执行批量下载指定文件
  • Linux shell脚本输出日志笔记整理(必看篇)
  • shell脚本 自动创建用户详解及实例代码
  • Linux Shell中三种引号的用法及区别
  • linux脚本判断条件总结(必看)
  • linux shell发送Email邮件的方法详解
  • Linux shell 之 提取文件名和目录名的一些方法总结
  • shell脚本实现输入密码显示星号
  • linux shell在while中用read从键盘输入的实现
  • shell脚本通过expect实现自动单边无密登录功能

相关文章

  • 一个简单的防CC攻击Shell脚本分享
  • shell脚本实现批量采集爱站关键词库
  • CentOS 6.0 启动时出现fstab错误时的修复方法
  • Shell脚本中实现更新PHP5
  • 查找目录下同名但不同后缀名文件的shell脚本代码
  • linux修改目录和文件权限的简单命令解释
  • Shell脚本中实现把输入的密码转换为*(星号)的方法
  • Shell编程中的特殊变量之位置变量介绍
  • Shell脚本调快调慢系统时间(测试服务器时使用)
  • shell脚本中取消重定向的方法实例

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • linux修改tomcat默认访问项目的具体步骤(必看篇)
    • Log4j 日志文件Linux/Mac/Windows通用存放位置设置方法
    • 利用linux的timerfd_create实现计时器示例分享
    • Shell脚本中判断输入变量或者参数是否为空的方法
    • linux用户与文件基础命令介绍(1)
    • Shell实现系统时间和BIOS时间同步校准脚本分享
    • Shell脚本监控网站页面正常打开情况
    • VPS自动备份数据库到FTP的脚本代码
    • 自动化下载并检测ftp文件备份的shell脚本
    • 使用Linux shell脚本实现FTP定时执行批量下载指定文件

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有