目前自己能理解的一些简单的Python脚本,理解不是自己写的脚本确实有点困难.
这个是把nginx的日志的内容作为输入源,经过筛选,展示最近访问nginx的前10位的IP,但是我这里只有三台实验机器。。。所以,只有三个柱子

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time : 2020/3/22
# @Author : TRIPPAL
# @Site :
# @File : nginx10.py
# @Software: PyCharm
import matplotlib.pyplot as plt
#
nginx_file = 'nginx.log'
ip = {}
# 筛选nginx日志文件中的ip
with open(nginx_file) as f:
for i in f.readlines():
s = i.strip().split()[0]
lengh = len(ip.keys())
# 统计每个ip的访问量以字典存储
if s in ip.keys():
ip[s] = ip[s] + 1
else:
ip[s] = 1
#以ip出现的次数排序返回对象为list
ip = sorted(ip.items(), key=lambda e:e[1], reverse=True)
#取列表前十
newip = ip[0:10:1]
tu = dict(newip)
x = []
y = []
for k in tu:
x.append(k)
y.append(tu[k])
plt.title('ip access')
plt.xlabel('ip address')
plt.ylabel('PV')
#x轴项的翻转角度
plt.xticks(rotation=0)
#显示每个柱状图的值
for a,b in zip(x,y):
plt.text(a, b, '%.0f' % b, ha='center', va= 'bottom',fontsize=9)
plt.bar(x,y)
plt.legend()
plt.show()


Python脚本2
调用Python的一个库IPy
根据你在脚本里写的子网网段,计算该网段内一共多少个主机地址,并且展示所有IP地址
这个太简单了,一看就明白


Python脚本3
判断一个目录是否存在。。。好吧这个其实没必要,我用shell也能写出来


脚本4
#!/usr/bin/env python3
#-*- coding:utf-8 -*-
#@Time: 2020/3/22 10:46
#@Author: trippal
#@Site: shenzhen
#@File: mendisk.py
#Software:PyCharm
import psutil
def memcheck():
print('the information of memory :')
mem = psutil.virtual_menmory()
memtotal = mem.total/1024/1024
memused = mem.used/1024/1024
membaifen = str(men.used/mem.total*100)+'%'
print('%.2fMB' % memused)
print('%.2fMB' % memtotal)
print(membaifen)
def diskcheck():
print('the information of disk :')
disk = psutil.disk_partitions()
diskuse = psutil.disk_usage('/')
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)
memcheck()
print('>>>>>>>>>>>>>>>>>>>>>>>>>>')
diskcheck()