def check_disk(disk_parts_data, disks_data): """监测硬盘""" for part, usage in disk_parts_data.items(): percent = usage.percent if percent > settings.DISK_MAX_PERCENT: common.logger.warn(u"分区", part, u"使用率超过设定值: ", usage.percent, "%") elif usage.free < settings.DISK_MIN_SIZE * 1024 * 1024 * 1024: common.logger.warn(u"分区", part, u"剩余容量小于设定值: ", usage.free, "B") else: common.logger.info(u"分区", part, u"使用率", usage.percent, "%") # 硬盘读写 for name, data in disks_data.items(): common.logger.info(u"物理硬盘: ", name) common.logger.info( u" 读字节: ", common.bytes2human(data.read_bytes), u" 读次数: ", data.read_count, u" 时间: ", data.read_time, "ms", ) common.logger.info( u" 写字节: ", common.bytes2human(data.write_bytes), u" 写次数: ", data.write_count, u" 时间: ", data.write_time, "ms", )
def check_net(net_data): """监测网络""" recv_speed = net_data.bytes_recv / net_data.time sent_speed = net_data.bytes_sent / net_data.time if recv_speed > settings.NET_RECV * 1024: common.logger.warn(u"下载网速超过设定值: ", common.bytes2human(recv_speed)) else: common.logger.info(u"下载网度: ", common.bytes2human(recv_speed)) if sent_speed > settings.NET_SENT * 1024: common.logger.warn(u"上传网速超过设定值: ", common.bytes2human(sent_speed)) else: common.logger.info(u"上传网速: ", common.bytes2human(sent_speed))
def render(draw, width, height): df = psutil.disk_usage("/") margin = 3 title_text(draw, margin, width, text="Disk") draw.text((margin, 20), text="Used:", font=tiny_font, fill="white") draw.text((margin, 35), text="Free:", font=tiny_font, fill="white") draw.text((margin, 45), text="Total:", font=tiny_font, fill="white") right_text(draw, 20, width, margin, text="{0:0.1f}%".format(df.percent)) right_text(draw, 35, width, margin, text=bytes2human(df.free, "{0:0.0f}")) right_text(draw, 45, width, margin, text=bytes2human(df.total, "{0:0.0f}"))
def render(draw, width, height): mem = psutil.virtual_memory() swap = psutil.swap_memory() mem_used_pct = (mem.total - mem.available) * 100.0 / mem.total margin = 3 title_text(draw, margin, width, text="Memory") draw.text((margin, 20), text="Used:", font=tiny_font, fill="white") draw.text((margin, 35), text="Phys:", font=tiny_font, fill="white") draw.text((margin, 45), text="Swap:", font=tiny_font, fill="white") right_text(draw, 20, width, margin, text="{0:0.1f}%".format(mem_used_pct)) right_text(draw, 35, width, margin, text=bytes2human(mem.used)) right_text(draw, 45, width, margin, text=bytes2human(swap.used))