def bd_stats_flow(c, key):
    a = []
    rs_bps = 0
    rs_flow = 0
    utc = datetime.timedelta(hours=8)
    yesterday_start = yesterday()[0]
    yesterday_end = yesterday()[1]
    yesterday_start = yesterday_start - utc
    yesterday_end = yesterday_end - utc
    start_time = yesterday_start.strftime('%Y-%m-%d' + "T" + '%H:%M:%S' + "Z")
    end_time = yesterday_end.strftime('%Y-%m-%d' + "T" + '%H:%M:%S' + "Z")
    param = CdnStatsParam(start_time=start_time,
                          end_time=end_time,
                          key_type=0,
                          period=300,
                          groupBy="")
    param.key = key
    param.metric = 'flow'
    param.level = 'all'
    response = c.get_domain_stats(param)
    load_list = response.details
    for i in range(0, len(load_list)):
        bps = load_list[i].bps
        flow = load_list[i].flow
        timestamp = load_list[i].timestamp
        timestamp = datetime.datetime.strptime(
            str(timestamp), '%Y-%m-%d' + "T" + '%H:%M:%S' + "Z")
        timestamp = timestamp + utc
        timestamp = timestamp.strftime('%Y-%m-%d' + "T" + '%H:%M:%S' + "Z")
        dic = {"bandwidth": float(bps), "timestamp": timestamp}
        a.append(dic)
        rs_flow += flow
    rs = sorted(a, key=lambda x: x["bandwidth"], reverse=True)
    rs = rs[0]
    return (rs, rs_flow)
Exemple #2
0
def test_get_domain_stats_flow(c):
    """
    test_get_domain_stats_flow
    """
    param = CdnStatsParam(start_time='2019-05-26T00:00:00Z',
                          end_time='2019-05-26T01:00:00Z',
                          key_type=0,
                          key=['www.example.com'],
                          period=300,
                          groupBy='')
    param.metric = 'flow'
    param.level = 'edge'
    response = c.get_domain_stats(param)
    print(response)