Python 监控脚本(硬盘、cpu、内存、网卡、进程)
#磁盘使用率
disk = psutil.disk_partitions()
for i in disk:
print "磁盘:%s 分区格式:%s"%(i.device,i.fstype)
disk_use = psutil.disk_usage(i.device)
print "使用了:%sM,空闲:%sM,总共:%sM,使用率\033[1;31;42m%s%%\033[0m,"%(disk_use.used/1024/1024,disk_use.free/1024/1024,disk_use.total/1024/1024,disk_use.percent)
#网络使用率
1. 监控服务器cpu使用率
def cpu():
while True:
time.sleep(1)
cpu_liyonglv = psutil.cpu_percent()
print "当前cpu利用率:\033[1;31;42m%s%%\033[0m"%cpu_liyonglv
if cpu_liyonglv >15.0:
baojing()
def baojing():
i = 0
while i < 10 :
i += 1
time.sleep(0.5)
winsound.PlaySound("ALARM8",winsound.SND_ALIAS)
cpu()
2. 监控服务器内存使用率
memory = psutil.virtual_memory()
print memory.used
print memory.total
ab = float(memory.used)/float(memory.total)*100
print "%.2f%%"%ab
print psutil.swap_memory()
3. 监控服务器网卡使用率
#网络使用率
count = psutil.net_io_counters()
print "发送字节数:\033[1;31;42m%s\033[0mbytes,接收字节数:\033[1;31;42m%s\033[0mbytes,发送包数:%s,接收包数%s"%(count.bytes_sent,count.bytes_recv,count.packets_sent,count.packets_recv)
users = psutil.users()
print "当前登录用户:",users[0].name
#时间
curent_time = psutil.boot_time()
curent_time_1 = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(curent_time))
print curent_time_1
4. 进程监控
脚本如下:
#读取进程pid,名称,可执行路径
pid = psutil.pids()
for k,i in enumerate(pid):
try:
proc = psutil.Process(i)
print k,i,"%.2f%%"%(proc.memory_percent()),"%",proc.name(),proc.exe() except psutil.AccessDenied :
print "psutil.AccessDenied"
Python 监控脚本(硬盘、cpu、内存、网卡、进程)的更多相关文章
- 用python监控Linux,CPU,内存,硬盘
#!/usr/local/bin/python3.5 #coding:utf-8 import mailll, linecache, re, socket, os, time hostname = s ...
- Python 监控脚本
Python 监控脚本 整体通过psutil模块动态获取资源信息.下为示例图: #!/usr/bin/env python # -*- coding: utf-8 -*- # @Time: 2019- ...
- 性能测试分析过程(三)linux下查看最消耗CPU/内存的进程
linux下查看最消耗CPU 内存的进程 1.CPU占用最多的前10个进程: ps auxw|head -1;ps auxw|sort -rn -k3|head -10 2.内存消耗最多的前10 ...
- linux系统中的基础监控(硬盘,内存,系统负载,CPU,网络等)
Linux系统常见日常监控 系统信息 查看 CentOS 版本号:cat /etc/redhat-release 综合监控 nmon 系统负载 命令:w(判断整体瓶颈) 12:04:52 up 1 ...
- python glances来监控linux服务器CPU 内存 IO使用
什么是 Glances? Glances 是一个由 Python 编写,使用 psutil 库来从系统抓取信息的基于 curses 开发的跨平台命令行系统监视工具. 通过 Glances,我们可以监视 ...
- 实用脚本:检查高 CPU / 内存消耗进程
1 检查高 CPU 消耗进程在 Linux 上运行了多长时间的 Bash 脚本 该脚本将帮助你确定高 CPU 消耗进程在 Linux 上运行了多长时间. # vi /opt/scripts/long- ...
- python定时脚本判断服务器内存
经常我们会发现服务器跑着跑着内存使用率达到了百分之八九十,或者有时候直接挂掉,在我们还没定位是哪块代码有问题导致内存占用很大的时候,可以先写个定时脚本,当服务器内存使用率达到一定值的时候,就重启一起服 ...
- python3 系统监控脚本(CPU,memory,网络,disk等)
#!/usr/bin/env python3 #create at 2018-11-30 'this is a system monitor scripts' __author__="yjt ...
- 轻量级监控平台之java进程监控脚本
轻量级监控平台之java进程监控脚本 #!/bin/bash #进程监控脚本 #功能需求: 上报机器Java进程的进程ID,对应的端口号service tcp端口号,tomcat http 端口号,以 ...
随机推荐
- DevExpress换肤
procedure TForm1.cxComboBox1PropertiesChange(Sender: TObject); begin // 这个地方必须是UserSkin,不然不会起作用 dxSk ...
- 下载以及安装VMware Player Pro 64位
1.下载地址:https://download3.vmware.com/software/wkst/file/VMware-workstation-full-14.0.0-6661328.exe 2. ...
- Redis入门到高可用(九)——无序set
一.结构 特点:无序,无重复,支持集合间操作 二.主要API smembers : 无序:(会阻塞)小心使用,可用sscan代替 spop: 从集合中弹出元素,每次只能弹出一个: 三.实战 抽奖系统 ...
- Windows下安装centOS7双系统总结
首先,按照网络教程,使用硬盘安装模式(失败): 一.使用分盘工具(easeUS Partion Master)分出一块未使用的空间,为安装centOS和保存镜像文件作准备. 二.将分出来的一部分空格, ...
- 1A
#include <iostream> using namespace std; int main() { long long n, m, a, r, c; cin>>n> ...
- Oracle查看用户密码过期,修改永不过期
01.查看当前open用户 select username,account_status,expiry_date,profile from dba_users; 02.查看目前的密码过期策略 sele ...
- 一个基于JRTPLIB的轻量级RTSP客户端(myRTSPClient)——实现篇:(九)以g711-mulaw为例添加新的编码格式解析支持
一.myRtspClient音频解析架构 AudioTypeBase是处理解析各种编码的音频数据的接口类.处理MPA数据的MPEG_Audio类和处理g711-mulaw的PCMU_Audio类均从A ...
- Linux-nmon系统性能监控工具的使用及报表产出
在进行性能测试的时候,需要获取服务器的各项指标,例如 CPU.MEM.I/O.DISK 等.网上有很多的监控工具,nmon 就是其中的一个,其可与 JMeter结合使用,测试系统的性能.其概要的介绍, ...
- 服务器非root安装gcc 4.8.5
1.下载gcc-4.8.5: $ wget ftp://ftp.gnu.org/gnu/gcc/gcc-4.8.5/gcc-4.8.5.tar.gz 2.解压gcc: $ tar zxvf gcc-. ...
- iOS LeftMenu抽屉效果与ScrollView共存时的手势冲突
公司有个项目,需要做左侧滑动,首页是ScrollView嵌套TableView.首页是一个ScrollView,所以当contentOffset是0.0的时候,无法直接滑动出抽屉效果,用户体验感非常差 ...