#!/usr/bin/python2.2 import ensimapplpath import vh3.db.bandwidth as bandwidthdb import sys import time def get_version(): f = open('/usr/lib/opcenter/VERSION', 'r') v = f.readline() info = [] info = v.strip().split('.') # maj, minor, patch, release return info[0:3] version = get_version info = {} info['domain'] = sys.argv[1] info['startdate'] = time.strftime('%Y-%m-01', time.localtime()) bw_usage_ref = [] total_bw = 0 if version > 3: bw_usage_ref, total_bw = bandwidthdb.get_bw_site_svc_totals_all( sys.argv[1], bandwidthdb.current_svc_totals_sql, info ) else: bw_usage_ref, total_bw = bandwidthdb.get_bw_site_svc_totals(sys.argv[1]) total_bw /= (1024 * 1024) bw_usage = bw_usage_ref[0] start_date = bw_usage[5] if version > 3: start_date = info['startdate'] # bandwidth.threshold, # bandwidth_services.name, # siteinfo.domain # sum(bandwidth_log.in_bytes) # sum(bandwidth_log.out_bytes) # bandwidth_spans.begindate # bandwidth_spans.enddate print """ Total BW: %d MB/month Start date: %s Site name: %s GB/month: %-.3f MB in: %-.3f MB out: %-.3f """ % ( total_bw, start_date, bw_usage[0], ((bw_usage[1]+.000001)/(1024*1024*1000)), ((bw_usage[2]+.000001)/(1024*1024)), ((bw_usage[3]+.000001)/(1024*1024)) ) svc_usage = bw_usage[4] len = 0 for item in svc_usage.keys(): if item.__len__() > len: len = item.__len__() print "%-*s %8s %9s %-s" % (len, "Service", "IN MB", "OUT MB", "Total MB") print "=====================================================================" for item in svc_usage.keys(): inb = (svc_usage[item]['in'] + .00000001)/(1024*1024) outb = (svc_usage[item]['out'] + .00000001)/(1024*1024) if inb <= .00000001 and outb <= .00000001: continue print "%-*s %8.3f %8.3f %8.3f" % ( len, item, inb, outb, inb + outb) print "====================================================================="