Esempio n. 1
0
def get_mon_data(dateFrom, dateTo, tenant_id):
    data = []
    domain_data = []
    domain_id_list = [
        i.domain_id for i in Domain.objects.filter(tenant_id=tenant_id)
        if i.domain_id is not None
    ]
    report_class = ReportManage()
    ReportForm = reportApi.ReportForm(dateFrom,
                                      dateTo,
                                      reportType='fiveminutes')
    d = {}
    IO = {}
    for i in domain_id_list:
        ret = report_class.getFlowReport(ReportForm, i)
        flowPoints = ret.getFlowPoints()
        if flowPoints is not None:
            for j in flowPoints:
                domain_data.append([
                    j.point.strftime("%Y-%m-%d"),
                    float('%0.2f' % (float(j.flow)))
                ])
            for k, v in domain_data:
                d[k] = d.setdefault(k, 0.0) + float(v)
                IO[k] = IO.setdefault(k, []) + [v]
    for k in sorted(d):
        io = max(IO[k]) * 8 / (5 * 60)
        data.append(MonData(date=k, top_io=io, total_flow=d[k]))
    return data
Esempio n. 2
0
def get_hit_report(dateFrom, dateTo):
    '''请求数统计算法'''
    Hit = 0
    domain_hit = 0
    Kwag2 = {}
    report = ReportManage()
    ReportForm = reportApi.ReportForm(dateFrom=dateFrom,
                                      dateTo=dateTo,
                                      reportType='daily')
    tenant_list = [i.tenant_id for i in Domain.objects.all()]
    tenant_set = set(tenant_list)
    for i in tenant_set:
        domain_id_list = [
            j.domain_id for j in Domain.objects.filter(tenant_id=i)
            if j.domain_id is not None
        ]
        for p in domain_id_list:
            ret = report.getHitReport(ReportForm, p)
            hit_list = ret.getHitPoints()
            if hit_list is not None:
                for k in hit_list:
                    domain_hit += int(k.hit)
                Hit += domain_hit
        Kwag2[i] = Hit
    return Kwag2
Esempio n. 3
0
def get_tenant_flow(dateFrom, dateTo, tenant_id=None):
    FLOW_DATA = 0.0
    Kwag1 = {}
    report = ReportManage()
    ReportForm = reportApi.ReportForm(dateFrom=dateFrom,
                                      dateTo=dateTo,
                                      reportType='daily')
    domain_id_list = [
        j.domain_id for j in Domain.objects.filter(tenant_id=tenant_id)
        if j.domain_id is not None
    ]
    for i in domain_id_list:
        ret = report.getFlowReport(ReportForm, i)
        flowPoints = ret.flowSummary
        if flowPoints is not None:
            FLOW_DATA += float(flowPoints)
        Kwag1[i] = FLOW_DATA
    return Kwag1
Esempio n. 4
0
def get_flow_report(dateFrom, dateTo, tenant_domain_list_dict):
    '''流量统计算法'''
    Flow = 0
    midd = 0
    Kwag1 = {}
    report = ReportManage()
    ReportForm = reportApi.ReportForm(dateFrom=dateFrom,
                                      dateTo=dateTo,
                                      reportType='daily')
    for k, v in tenant_domain_list_dict.iteritems():
        for p in v:
            ret = report.getFlowReport(ReportForm, p)
            if ret:
                for i in ret:
                    midd += i.flowSummary
            Flow += float(midd)
        Kwag1[k] = Flow
    return Kwag1
Esempio n. 5
0
def get_tenant_hit(dateFrom, dateTo, tenant_id=None):
    Hit = 0
    domain_hit = 0
    Kwag2 = {}
    report = ReportManage()
    ReportForm = reportApi.ReportForm(dateFrom=dateFrom,
                                      dateTo=dateTo,
                                      reportType='daily')
    domain_id_list = [
        j.domain_id for j in Domain.objects.filter(tenant_id=tenant_id)
        if j.domain_id is not None
    ]
    for i in domain_id_list:
        ret = report.getHitReport(ReportForm, i)
        hit_list = ret.getHitPoints()
        if hit_list is not None:
            for k in hit_list:
                domain_hit += int(k.hit)
        Hit += domain_hit
        Kwag2[i] = Hit
    return Kwag2
Esempio n. 6
0
def get_hit_report(dateFrom, dateTo, tenant_domain_list_dict):
    '''请求数统计算法'''
    Hit = 0
    midd = []
    domain_hit = 0
    Kwag2 = {}
    report = ReportManage()
    ReportForm = reportApi.ReportForm(dateFrom=dateFrom,
                                      dateTo=dateTo,
                                      reportType='daily')
    for k, v in tenant_domain_list_dict.iteritems():
        for s in v:
            ret = report.getHitReport(ReportForm, s)
            for i in ret:
                midd += i.getHitPoints()
            if midd:
                for p in midd:
                    domain_hit += int(p.hit)
                Hit += domain_hit
        Kwag2[k] = Hit
    return Kwag2
Esempio n. 7
0
def get_flow_report(dateFrom, dateTo):
    '''流量统计算法'''
    Flow = 0
    Kwag1 = {}
    report = ReportManage()
    ReportForm = reportApi.ReportForm(dateFrom=dateFrom,
                                      dateTo=dateTo,
                                      reportType='daily')
    tenant_list = [i.tenant_id for i in Domain.objects.all()]
    tenant_set = set(tenant_list)
    for i in tenant_set:
        domain_id_list = [
            j.domain_id for j in Domain.objects.filter(tenant_id=i)
            if j.domain_id is not None
        ]
        for p in domain_id_list:
            ret = report.getFlowReport(ReportForm, p)
            flowPoints = ret.flowSummary
            if flowPoints is not None:
                Flow += float(flowPoints)
        Kwag1[i] = Flow
    return Kwag1
Esempio n. 8
0
def get_mon_data(dateFrom, dateTo, domain_id):
    data = []
    flowPoints = []
    hitPoints = []
    report_class = ReportManage()
    ReportForm = reportApi.ReportForm(dateFrom,
                                      dateTo,
                                      reportType='fiveminutes')
    d_flow = {}
    d_hit = {}
    ret_flow = report_class.getFlowReport(ReportForm, domain_id)
    for g in ret_flow:
        flowPoints += g.getFlowPoints()
    ret_hit = report_class.getHitReport(ReportForm, domain_id)
    for s in ret_hit:
        hitPoints += s.getHitPoints()
    if flowPoints:
        flow_clean_data = [[
            j.point.strftime("%Y-%m-%d"),
            float('%0.2f' % (float(j.flow)))
        ] for j in flowPoints]
        for i in flow_clean_data:
            d_flow[i[0]] = d_flow.setdefault(i[0], []) + [i[1]]
    if hitPoints:
        hit_clean_data = [[k.point.strftime("%Y-%m-%d"),
                           int(str(k.hit))] for k in hitPoints]
        for l in hit_clean_data:
            d_hit[l[0]] = d_hit.setdefault(l[0], 0) + l[1]
    for k in d_flow:
        io = max(d_flow[k]) * 8 / (5 * 60)
        flow = sum(d_flow[k])
        requests = d_hit[k]
        data.append(
            MonData(date=k,
                    top_io=io,
                    total_flow=flow,
                    total_requests=requests))
    return data