#!/usr/local/bin/python2.2 import os,re,sys,time FILERS = { 'nas1': '10.1.30.218', 'nas2': '10.1.30.219' } print 'generating report at %s' % time.ctime() print '' print '---] qtree usage report [------------------------------------------------------' print '%-6s %-5s %-12s %-20s %s' % ('filer', 'vol', 'qtree', 'Disk Usage(gb)', 'Inodes') print '-------------------------------------------------------------------------------' WARN = [] V = {} VU = {} F = {} FU = {} Q = {} filers = FILERS.keys() filers.sort() for filer in filers: d = os.popen('rsh %s quota report | sed -e "s/ +/ /"' % FILERS[filer]) d.readline() d.readline() d.readline() F[filer] = [long(0),long(0)] FU[filer] = [long(0),long(0)] for l in d.readlines(): l = re.split(r'\s*', l.strip()) if l[0] != 'user' and l[0] != 'tree': continue if len(l) == 9: l = l[:-1] type,id,volume,tree,Kused,Klimit,Fused,Flimit = l Kused = long(Kused) Klimit = long(Klimit) Kper = float(Kused)/Klimit*100 Kper = '%0.2f' % Kper K = '%s/%s (%s%%)' % (Kused/1024/1024,Klimit/1024/1024,Kper) I = '%s/%s' % (Fused,Flimit) print '%-6s %-5s %-12s %-20s %s' % (filer, volume, tree, K, I) if not Q.has_key( (filer, volume) ): Q[(filer, volume)] = 0 Q[(filer, volume)] += long(Klimit) if float(Kper) >= 95.0: WARN.append('WARNING: qtree %s:%s is almost at quota.' % (filer, tree)) for line in os.popen('rsh %s df' % FILERS[filer]).readlines()[1:]: line = re.split(r'\s*', line) item, total, used = line[0], line[1], line[2] if not V.has_key(filer): V[filer] = {} if not VU.has_key(filer): VU[filer] = {} if not item.endswith('.snapshot'): V[filer][item] = [long(total), long(used)] VU[filer][item] = [long(total), long(used)] F[filer][0] += long(total) FU[filer][0] += long(total) F[filer][1] += long(used) FU[filer][1] += long(used) else: snap_per = long(line[4][:-1]) if snap_per >= 100: WARN.append('WARNING: snapshot usage is over reserve for %s:%s' % (filer, item)) item = item[:-9] V[filer][item][0] += long(total) V[filer][item][1] += long(used) F[filer][0] += long(total) F[filer][1] += long(used) print '' print '---] volume usage - usable (gb) [----------------------------------------------' print '%-6s %-20s %s' % ('filer', 'volume', 'usage') filers = VU.keys() filers.sort() for filer in filers: for vol in VU[filer].keys(): print '%-6s %-20s %s/%s (%%%0.2f)' % (filer, vol, VU[filer][vol][1]/1024/1024, VU[filer][vol][0]/1024/1024, float(VU[filer][vol][1])/VU[filer][vol][0]*100 ) print '' print '---] volume usage - raw (gb) [-------------------------------------------------' print '%-6s %-20s %s' % ('filer', 'volume', 'usage') filers = V.keys() filers.sort() for filer in filers: for vol in V[filer].keys(): print '%-6s %-20s %s/%s (%%%0.2f)' % (filer, vol, V[filer][vol][1]/1024/1024, V[filer][vol][0]/1024/1024, float(V[filer][vol][1])/V[filer][vol][0]*100 ) print '' print '---] volume allocation totals (gb) [-------------------------------------------' fvs = Q.keys() fvs.sort() for filer, volume in fvs: print '%-20s %s/%s (%%%0.2f)' % ('%s:%s'%(filer, volume), Q[(filer, volume)]/1024/1024,VU[filer]['/vol/'+volume+'/'][0]/1024/1024, float(Q[(filer, volume)])/VU[filer]['/vol/'+volume+'/'][0]*100) if Q[(filer, volume)] > (0.90*VU[filer]['/vol/'+volume+'/'][0]): WARN.append('WARNING: %s:%s is over-allocated by around %s GB!' % (filer, volume,long(Q[(filer, volume)]-(0.90*VU[filer]['/vol/'+volume+'/'][0]))/1024/1024)) print '' print '---] filer usage (all volumes) - usable (gb) [---------------------------------' print '%-6s %s' % ('filer', 'usage') filers = FU.keys() filers.sort() for filer in filers: print '%-6s %s/%s (%%%0.2f)' % (filer, FU[filer][1]/1024/1024, FU[filer][0]/1024/1024, float(FU[filer][1])/FU[filer][0]*100 ) print '' print '---] filer usage (all volumes) - raw (gb) [------------------------------------' print '%-6s %s' % ('filer', 'usage') filers = F.keys() filers.sort() for filer in filers: print '%-6s %s/%s (%%%0.2f)' % (filer, F[filer][1]/1024/1024, F[filer][0]/1024/1024, float(F[filer][1])/F[filer][0]*100 ) print '' print '---] warnings [-----------------------------------------------------------------' for l in WARN: print l print ''