#磁盘使用率
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、内存、网卡、进程)的更多相关文章

  1. 用python监控Linux,CPU,内存,硬盘

    #!/usr/local/bin/python3.5 #coding:utf-8 import mailll, linecache, re, socket, os, time hostname = s ...

  2. Python 监控脚本

    Python 监控脚本 整体通过psutil模块动态获取资源信息.下为示例图: #!/usr/bin/env python # -*- coding: utf-8 -*- # @Time: 2019- ...

  3. 性能测试分析过程(三)linux下查看最消耗CPU/内存的进程

    linux下查看最消耗CPU  内存的进程 1.CPU占用最多的前10个进程:  ps auxw|head -1;ps auxw|sort -rn -k3|head -10  2.内存消耗最多的前10 ...

  4. linux系统中的基础监控(硬盘,内存,系统负载,CPU,网络等)

      Linux系统常见日常监控 系统信息 查看 CentOS 版本号:cat /etc/redhat-release 综合监控 nmon 系统负载 命令:w(判断整体瓶颈) 12:04:52 up 1 ...

  5. python glances来监控linux服务器CPU 内存 IO使用

    什么是 Glances? Glances 是一个由 Python 编写,使用 psutil 库来从系统抓取信息的基于 curses 开发的跨平台命令行系统监视工具. 通过 Glances,我们可以监视 ...

  6. 实用脚本:检查高 CPU / 内存消耗进程

    1 检查高 CPU 消耗进程在 Linux 上运行了多长时间的 Bash 脚本 该脚本将帮助你确定高 CPU 消耗进程在 Linux 上运行了多长时间. # vi /opt/scripts/long- ...

  7. python定时脚本判断服务器内存

    经常我们会发现服务器跑着跑着内存使用率达到了百分之八九十,或者有时候直接挂掉,在我们还没定位是哪块代码有问题导致内存占用很大的时候,可以先写个定时脚本,当服务器内存使用率达到一定值的时候,就重启一起服 ...

  8. python3 系统监控脚本(CPU,memory,网络,disk等)

    #!/usr/bin/env python3 #create at 2018-11-30 'this is a system monitor scripts' __author__="yjt ...

  9. 轻量级监控平台之java进程监控脚本

    轻量级监控平台之java进程监控脚本 #!/bin/bash #进程监控脚本 #功能需求: 上报机器Java进程的进程ID,对应的端口号service tcp端口号,tomcat http 端口号,以 ...

随机推荐

  1. Redis入门到高可用(七)——Hash

    一.结构 Mapmap结构: filed 不能相同,value可以相同. 二.重要指令 ♦️ HSET  ♦️ HGET  ♦️ HDEL ♦️ Hlen  ♦️ HEXISTS ♦️HGETALL  ...

  2. 遮罩层出现后不能滚动 添加事件@touchmove.prevent

    <div class="maskshow" @click="hidden_video" @touchmove.prevent></div> ...

  3. 一个基于JRTPLIB的轻量级RTSP客户端(myRTSPClient)——实现篇:(六)RTP音视频传输解析层之音视频数据传输格式

    一.差异 本地音视频数据格式和用来传输的音视频数据格式存在些许差异,由于音视频数据流到达客户端时,需要考虑数据流的数据边界.分包.组包顺序等问题,所以传输中的音视频数据往往会多一些字节. 举个例子,有 ...

  4. [LeetCode] 34. Find First and Last Position of Element in Sorted Array == [LintCode] 61. Search for a Range_Easy tag: Binary Search

    Description Given a sorted array of n integers, find the starting and ending position of a given tar ...

  5. check process id exists

    kill -0 pid sending the signal 0 to a given PID just checks if any process with the given PID is run ...

  6. python mysql program

    //test.py #!/usr/bin/python # -*- coding: UTF-8 -*- import MySQLdb # 打开数据库连接 db = MySQLdb.connect(&q ...

  7. Jenkins自动化构建(一)执行selenium+python脚本

    Jenkins执行python写的selenium自动化脚本,通常会遇到,执行打不开浏览器,查看jenkins构建Console Output控制台输出信息,发现脚本是执行了的,但是出错了,打开浏览器 ...

  8. 在window下搭建Vue.Js开发环境

    nodejs官网http://nodejs.cn/下载安装包,无特殊要求可本地傻瓜式安装,这里选择2017-5-2发布的 v6.10.3,也可选择阿里云镜像https://npm.taobao.org ...

  9. ACM-彩票

    题目描述 OMeGa 兄弟最近赢了巨奖!但当他们在分彩票奖金的时候却遇到了一些问题.他们两兄弟对一切偶数都痴迷不已,以至于在分奖金的时候,他们两个都希望自己分到的钱是偶数(即便两人分的钱不一样也没关系 ...

  10. vue搭建环境并创建项目

    1.>npm install @vue/cli -g 2.创建项目A a.>vue ui b.在弹出的管理界面创建项目 或 a.npm install -g @vue/cli-init b ...