用python监控Linux,CPU,内存,硬盘
#!/usr/local/bin/python3.5
#coding:utf-8
import mailll, linecache, re, socket, os, time hostname = socket.gethostname()
ip = socket.gethostbyname(hostname) def cpu_status():
with open("/proc/loadavg", 'rt') as f:
data = f.read().split()
if float(data[2]) > 0.7:
with open("/home/cpustatus.txt", 'wt') as f:
print("notice : \n Hostname : %s\n IP : %s\n\n The CPU loadavg will overload : %s" % (hostname, ip, data[2]), file = f)
mailll.send_mail("/home/cpustatus.txt") def memory_status():
theline = linecache.getline(r'/proc/meminfo', 2)
mem_free_num = "".join(re.findall(r"[0-9]", theline)) if (int(mem_free_num) / 1000) < 100:
with open("/home/memory.txt", 'wt') as f:
print("notice : \n Hostname : %s\n IP : %s\n\n Insufficient free memory : %s" % (hostname, ip, str(int(mem_free_num) / 1000) + "M"), file = f)
mailll.send_mail("/home/memory.txt") def disk_status():
os.system("df -hT |grep ext4 |awk -F '[ %]+' ' {if($6 >= 70) print $6}' |wc -l > /home/diskstatus.txt")
diskcount = int(linecache.getline(r'/home/diskstatus.txt', 1))
if diskcount >= 1 : with open("/home/diskstatus.txt", 'wt') as f:
print("notice : \n Hostname : %s\n IP : %s\n" % (hostname, ip), file = f)
os.system("echo 'Hard disk capacity is insufficient :' >> /home/diskstatus.txt")
os.system("df -hT |grep 'ext4\|Filesystem' >> /home/diskstatus.txt")
mailll.send_mail('/home/diskstatus.txt') try:
cpu_status()
time.sleep(2)
memory_status()
time.sleep(2)
disk_status()
except Exception as e:
print("program is error!!!")
新手,自我感觉就是功能实现了,代码实在不怎么样,但是还是记录下来,希望大家多多指出不足,以后随着学习的深入,希望能做的更好!
END!!!
用python监控Linux,CPU,内存,硬盘的更多相关文章
- jmeter监控linux cpu 内存 网络 IO
下载地址:http://jmeter-plugins.org/downloads/all/ PerfMon: 用来监控Server的CPU.I/O.Memory等情况 ServerAgent-2.2. ...
- Linux 性能监控之CPU&内存&I/O监控Shell脚本2
Linux 性能监控之CPU&内存&I/O监控Shell脚本2 by:授客 QQ:1033553122 思路: 捕获数据->停止捕获数据->提取数据 备注:一些命令的输 ...
- Linux 性能监控之CPU&内存&I/O监控Shell脚本1
Linux 性能监控之CPU&内存&I/O监控Shell脚本1 by:授客 QQ:1033553122 #!/bin/bash # 获取要监控的本地服务器IP地址 IP=`if ...
- 第6章:使用Python监控Linux系统
1.Python编写的监控工具 1).多功能系统资源统计工具dstat dstat是一个用Python编写的多功能系统资源统计工具,用来取代Linux下的vmstat,iostat,netstat和i ...
- VPS性能测试:CPU内存,硬盘IO读写,带宽速度,UnixBench和压力测试
现在便宜的VPS主机越来越多了,一些美国的VPS主机甚至给出1美元一月的VPS,堪比虚拟主机还要便宜,巨大的价格优势吸引不少人购买和使用,而近些年来国内的主机商也开始意识到便宜的VPS对草根站长的诱惑 ...
- Windows 性能监视器的基本指标说明(CPU,内存,硬盘参数)
[转]Windows 性能监视器的基本指标说明(CPU,内存,硬盘参数) 作为一个系统工程师来说,要看懂监控的数据至关重要,关系着优化和分析出现的问题.我是在运维过程中要用到的.因此,今天给出Wind ...
- Windows 性能监视器的基本指标(CPU,内存,硬盘参数)
转载:http://kms.lenovots.com/kb/article.php?id=7045 Windows 性能监视器的基本指标(CPU,内存,硬盘参数) 作为一个系统工程师来说,要看懂监控的 ...
- 一个统计 CPU 内存 硬盘 使用率的shell脚本
一个统计 CPU 内存 硬盘 使用率的shell脚本,供大家学习参考 #!/bin/bash #This script is use for describle CPU Hard Memery Uti ...
- 使用Python监控Linux系统
一.Python编写的监控工具 一.多功能系统资源统计工具dstat 1.dstat介绍 dstat是一个用Python语言实现的多功能系统资源统计工具,用来取代Linux下的vmstat.iosta ...
- linux cpu内存利用率获取
有了这么好的工具,我们还需要自己造轮子么? 两种情况,如果有复杂的监控需求,而且愿意花时间学习,我们可以使用nmon:但如果监控需求特殊比如说还要监控单个进程的情况,这时候就需要自己动手实现了.自己动 ...
随机推荐
- Spring 学习总结 使用静态工厂创建Bean
创建Bean时,class属性必须指定,此时为静态工厂类. factory-method指定静态工厂方法名. 接口: public interface Being { public void test ...
- 【netty】Netty系列之Netty百万级推送服务设计要点
1. 背景 1.1. 话题来源 最近很多从事移动互联网和物联网开发的同学给我发邮件或者微博私信我,咨询推送服务相关的问题.问题五花八门,在帮助大家答疑解惑的过程中,我也对问题进行了总结,大概可以归纳为 ...
- C#中获取服务器IP,客户端IP以及网卡物理地址
客户端ip: Request.ServerVariables.Get("Remote_Addr").ToString(); 客户端主机名: Request.ServerVariab ...
- ios实现屏幕旋转的方法
1.屏蔽AppDelegate下面的屏幕旋转方法 #pragma mark - 屏幕旋转的 //- (UIInterfaceOrientationMask)application:(UIApplica ...
- Navicat(连接) -1之SSH 设置
SSH 设置 Secure SHell (SSH) 是一个通过网络登录其他计算机的程序,在远程服务器运行命令,和从一台机器移动文件到另一台.在不安全的网络中,它提供两台主机之间强大认证和安全加密的的通 ...
- sublime plugin emmet toolkit
[简写规则]1. E 代表HTML标签.2. E#id 代表id属性.3. E.class 代表class属性.4. E[attr=foo] 代表某一个特定属性.5. E{foo} 代表标签包含的内容 ...
- 鸟哥的Linux私房菜第零章
CPU从主存中读取数据通过微指令集控制和进行计算.主存储器内的数据则是从输入单元所传输进来,而CPU处理完毕的数据也必须要先写回主存储器中, 最后数据才从主存储器传输到输出单元.内存又称主存,是CPU ...
- day6_1
一.加密模块 1.hashlib >>> data=hashlib.md5() >>> data.update(b'hello') >>> pri ...
- 68. Longest Common Prefix
Longest Common Prefix Write a function to find the longest common prefix string amongst an array of ...
- CultureInfo 类
https://msdn.microsoft.com/zh-cn/library/system.globalization.cultureinfo(VS.80).aspx 区域性名称 区域性标识符 语 ...