用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:但如果监控需求特殊比如说还要监控单个进程的情况,这时候就需要自己动手实现了.自己动 ...
随机推荐
- Android学习五:Content Provider 使用
1ContentProvider相关知识1.1在安卓应用中,通过文件方式对外共享数据,需要进行文件操作读写数据:采用sharedpreferences共享数据,需要使用sharedpreference ...
- Zookeeper安装指南
第一步:修改conf目录下面的 zoo_sample.cfg修改为zoo.cfg tickTime=2000 # The number of ticks that the initial # sync ...
- HDU3487 play with chain
题目大意:给出1到n的有序数列,现在有两个操作: 1.CUT a b c 把第a到第b个数剪切下来,放到剩下的第c个数的后边. 2.FLIP a b 把第a到第b个数反转. 经过总共m次操作后,求现 ...
- asm createdisk时提示没有权限
[root@linux Packages]# /etc/init.d/oracleasm createdisk asm1 /dev/sdg1Marking disk "asm1" ...
- 手把手教你接口自动化测试 – SoapUI & Groovy
手把手教你接口自动化测试 – SoapUI & Groovy http://www.cnblogs.com/wade-xu/p/4236295.html 关键词:SoapUI接口测试,接口自动 ...
- JAVA设计模式之桥梁模式
在阎宏博士的<JAVA与模式>一书中开头是这样描述桥梁(Bridge)模式的: 桥梁模式是对象的结构模式.又称为柄体(Handle and Body)模式或接口(Interface)模式. ...
- Change the Windows 7 Taskbar Thumbnail and List Mode
Manually in Registry Editor 1. Open the Start Menu, then type regedit in the search boxand press Ent ...
- INI 文件的读写操作
在C#中对INI文件进行读写操作,在此要引入using System.Runtime.InteropServices; 命名空间,具体方法如下: #region 变量 private static r ...
- 【SSM 1】SpringMVC、Spring和Struts的区别
导读:近期做到的项目中,用到的框架师SSM(SpringMVC+Spring+Mybatis),那么在这之前用过SSH,这里主要是区分一下SpringMVC和Struts,但是由于SpringMVC和 ...
- Backbone笔记(续)
Backbone Bockbone 总览 Backbone 与 MVC 模式:解决某一类问题的通用方案 - 套路 MVC:一种架构模式,解耦代码,分离关注点 M(Model) - 数据模型 V(Vie ...