判断是否是一个目录
#!/usr/bin/env python3
-- coding: utf-8 --
@Time : 2018-12-18 15:16
@Author : opsonly
@Site :
@File : opsUse.py
@Software: PyCharm
import os
dir = “/var/www/html/EnjoyCarApi/”
if os.path.isdir(dir):
print(’%s is a dir’ % dir)
else:
print(’%s is not a dir’ % dir)
系统内存与磁盘检测
#!/usr/bin/env python3
-- coding: utf-8 --
@Time : 2018-12-17 17:16
@Author : opsonly
@Site :
@File : systemissue.py
@Software: PyCharm
import psutil
def memissue():
print(‘内存信息:’)
mem = psutil.virtual_memory()
单位换算为MB
memtotal = mem.total/1024/1024
memused = mem.used/1024/1024
membaifen = str(mem.used/mem.total100) + ‘%’
print(’%.2fMB’ % memused)
print(’%.2fMB’ % memtotal)
print(membaifen)
def cuplist():
print(‘磁盘信息:’)
disk = psutil.disk_partitions()
diskuse = psutil.disk_usage(’/’)
#单位换算为GB
diskused = diskuse.used / 1024 / 1024 / 1024
disktotal = diskuse.total / 1024 / 1024 / 1024
diskbaifen = diskused / disktotal * 100
print(’%.2fGB’ % diskused)
print(’%.2fGB’ % disktotal)
print(’%.2f’ % diskbaifen)
memissue()
print(’******************’)
cuplist()
统计nginx日志前十ip访问量并以柱状图显示
#!/usr/bin/env python3
-- coding: utf-8 --
@Time : 2018-12-18 15:49
@Author : opsonly
@Site :
@File : nginx_ip.py
@Software: PyCharm
import matplotlib.pyplot as plt
nginx_file = ‘nginx2018-12-18_07:45:26’
ip = {}