用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:但如果监控需求特殊比如说还要监控单个进程的情况,这时候就需要自己动手实现了.自己动 ...
随机推荐
- JQuery AJAX 解析获得的JSON数据
下面的解析的Json是一个二级循环. <!DOCTYPE html> <html> <head> <script src="https://code ...
- 用vs2010编译和调试多个arx版本的arx项目
翻译自dev guide<Compile and Debug Mixed-mode projects> 默认vs2010是使用ARX2014,开发AutoCAD2014使用的ARX, ...
- SQLServer2012中用于记录数据操作时刻的附加字段使用datetime2(3)就可以了
datetime2(3)精确到毫秒(听说),约等于2005时代的datetime类型.实际上后者是精确到3.33毫秒(也是听说). ) = GETDATE(); ) = GETDATE(); ) = ...
- Node调试之道-----JSHint
Node调试之道-----JSHint Node的优势我就不再乱吹捧了,它让javascript统一web的前后台成为了可能.但是对于新手来说,server端的JS代码可能不像client端的代码那么 ...
- 53. Minimum Window Substring
Minimum Window Substring Given a string S and a string T, find the minimum window in S which will co ...
- VC中GBK与UTF8转化
void ConvertGBKToUtf8(CString& strGBK) { int len=MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)strG ...
- weblogic 优化设置 http://wenku.baidu.com/view/c42e7a5bbe23482fb4da4cf2.html
引自:http://wenku.baidu.com/view/c42e7a5bbe23482fb4da4cf2.html
- windows 装 Crypto.Cipher
python 2.7 先去官网下载,https://www.dlitz.net/software/pycrypto/ 回来装这个,http://download.csdn.net/download/d ...
- Oracle 表分区
从以下几个方面来整理关于分区表的概念及操作: 表空间及分区表的概念 表分区的具体作用 表分区的优缺点 表分区的几种类型及操作方法 对表分区的维护性操作 1.表空间及分区表的概念 表空间: 是一个或多个 ...
- JQuery的Ajax跨域请求原理概述及实例
今天在项目中需要做远程数据加载并渲染页面,直到开发阶段才意识到ajax跨域请求的问题,隐约记得Jquery有提过一个ajax跨域请求的解决方式,于是即刻翻出Jquery的API出来研究,发 JQuer ...