def get_onedomain_lastday_cdnflows(domainId): api = reportApi.ReportApi("syscloudcdn", "491fbc7ac81e48544660") TempDate = datetime.date.today() - datetime.timedelta(days=1) LastDate = TempDate.strftime('%Y-%m-%d') reportForm = reportApi.ReportForm() reportForm.dateFrom = "%s 00:00:00" % LastDate reportForm.dateTo = "%s 23:59:59" % LastDate reportForm.reportType = reportApi.REPORT_TYPE_DAILY result = api.getFlowReport(reportForm, domainId) flows = result.getFlowPoints() amount = 0 if flows is None: return 0 for each in flows: #print each.point,each.flow,each.getFlow(); tmp = string.atof(each.flow.encode()) amount += tmp return int(amount / 1024)
def get_onedomain_lastday_bandwidth(domainId): api = reportApi.ReportApi("syscloudcdn", "491fbc7ac81e48544660") TempDate = datetime.date.today() - datetime.timedelta(days=1) LastDate = TempDate.strftime('%Y-%m-%d') reportForm = reportApi.ReportForm() reportForm.dateFrom = "%s 00:00:00" % LastDate reportForm.dateTo = "%s 23:59:59" % LastDate reportForm.reportType = reportApi.REPORT_TYPE_5_MINUTES result = api.getFlowReport(reportForm, domainId) flows = result.getFlowPoints() amount = 0 bandwidth = [] if flows is None: return 0 for each in flows: #print each.point,each.flow;#each.getFlow(); tmp = string.atof(each.flow.encode()) bandwidth.append(tmp) return max(bandwidth)
def get_onedomain_lastmonth_cdnflows(domainId): api = reportApi.ReportApi("syscloudcdn", "491fbc7ac81e48544660") Lastmonth_first = str( datetime.date(datetime.date.today().year, datetime.date.today().month - 1, 1)) Lastmonth_last = str( datetime.date(datetime.date.today().year, datetime.date.today().month, 1) - datetime.timedelta(1)) reportForm = reportApi.ReportForm() reportForm.dateFrom = "%s 00:00:00" % Lastmonth_first reportForm.dateTo = "%s 23:59:59" % Lastmonth_last reportForm.reportType = reportApi.REPORT_TYPE_DAILY result = api.getFlowReport(reportForm, domainId) flows = result.getFlowPoints() amount = 0 if flows is None: return 0 for each in flows: tmp = string.atof(each.flow.encode()) amount += tmp return amount
#_*_ coding: gbk -*- import sys reload(sys) if __name__ == '__main__': pass import logging import api.reportApi as reportApi logging.basicConfig(level = logging.DEBUG) api = reportApi.ReportApi("syscloudcdn", "491fbc7ac81e48544660") #cname=hjdbh1802goaxl.wscloudcdn.com, domainId=1228328, domainNam=downloads.phoneunet.com domainId = "1228328" reportForm = reportApi.ReportForm() reportForm.dateFrom = "2015-09-01 01:00:00" reportForm.dateTo = "2015-09-06 12:00:00" #reportForm.dateFrom = "2013-10-01 01:00:00" #reportForm.dateTo = "2013-10-18 12:00:00" reportForm.reportType = reportApi.REPORT_TYPE_DAILY #logging.debug("获取全部域名的流量报表") #print ("获取全部域名的流量报表") #result = api.getFlowReport(reportForm) #print 'result:', result.getRet(), result.getMsg(), result.getXCncRequestId() #print 'flowPoints:', result.getFlowPoints() #exit(0);
Created on 2013-10-18 @author: zzh ''' import sys reload(sys) if __name__ == '__main__': pass import logging import api.reportApi as reportApi logging.basicConfig(level=logging.DEBUG) api = reportApi.ReportApi("{username}", "{API_KEY}") domainId = "193382" reportForm = reportApi.ReportForm() reportForm.dateFrom = "2013-10-01 01:00:00" reportForm.dateTo = "2013-10-18 12:00:00" reportForm.reportType = reportApi.REPORT_TYPE_DAILY logging.debug("获取全部域名的流量报表") result = api.getFlowReport(reportForm) print 'result:', result.getRet(), result.getMsg(), result.getXCncRequestId() print 'flowPoints:', result.getFlowPoints() logging.debug("获取某域名的流量报表") result = api.getFlowReport(reportForm, domainId)