统计lvm 超分情况

#!/usr/bin/python3
'''
统计lvm 超分比例
'''
import os
import socket
h=socket.getfqdn()

# lvm 名称
lv_name='''
lvs --nohead --units k| awk '$3 ~ "^Vw" {sum[$5] +=$4};END{for(i in sum){print i}}'
'''

# 已分配求和
lv_requests='''
lvs --nohead --units k | awk '$3 ~ "^Vw" {if($5=="%s"){sum["%s"] +=$4}};END{for(i in sum){print i,sum[i]}}'
'''

# 总量
lv_total='''
lvs --nohead --units k --select lv_name=%s|awk '{print $1,$4}'
'''

info = []
for i in os.popen(lv_name).read().split():
    _temp={}
    _i=os.popen(lv_total%i).read().split()
    _temp['hostname']=h
    _temp['lvname']=i
    _temp['totalsize']=_i[1][0:-1]
    
    _i=os.popen(lv_requests%(i,i)).read().split()
    _temp['requestsize']=_i[1]
    _temp['rate']=str(round(float(_temp['requestsize'])/float(_temp['totalsize'])*100,2)) + '%'
    info.append(_temp)
    
for i in info:
  print(i['hostname'],i['lvname'],i['totalsize'],i['requestsize'],i['rate'])
[root@allinone tmp]# python3 1.py 
allinone mysql1 12288.00 1048576 8533.33%
allinone mysql 73728.00 1060864 1438.89%
posted @ 2023-02-15 15:08  mingtian是吧  阅读(14)  评论(0编辑  收藏  举报