#!/usr/bin/python3
'''
统计lvm 超分比例
'''
import os
import socket
h=socket.getfqdn()
a='''
lvs --nohead --units k| awk '$3 ~ "^Vw" {sum[$5] +=$4};END{for(i in sum){print i}}'
'''
b='''
lvs --nohead --units k | awk '$3 ~ "^Vw" {sum["%s"] +=$4};END{for(i in sum){print i,sum[i]}}'
'''
c='''
lvs --nohead --units k --select lv_name=%s|awk '{print $1,$4}'
'''
info = []
for i in os.popen(a).read().split():
_temp={}
_i=os.popen(c%i).read().split()
_temp['hostname']=h
_temp['lvname']=i
_temp['totalsize']=_i[1][0:-1]
_i=os.popen(b%i).read().split()
_temp['requestsize']=_i[1]
_temp['rate']=str(float(_temp['requestsize'])//float(_temp['totalsize'])) + '%'
info.append(_temp)
# allinone mysql1 12288.00 2109440 171.0%
# allinone mysql 73728.00 2109440 28.0%
for i in info:
print(i['hostname'],i['lvname'],i['totalsize'],i['requestsize'],i['rate'])
标签:totalsize,temp,--,sum,超分,print,lvm,os,统计
From: https://www.cnblogs.com/wangend/p/17123120.html