-
Notifications
You must be signed in to change notification settings - Fork 93
/
Copy pathcdn_get_bandwidth_data.c
78 lines (66 loc) · 2.21 KB
/
cdn_get_bandwidth_data.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "../qiniu/cdn.h"
#include "debug.h"
int main(int argc, char **argv) {
Qiniu_Client client;
Qiniu_CDN_BandwidthRet ret;
Qiniu_Error error;
int i, j;
char *accessKey = getenv("QINIU_ACCESS_KEY");
char *secretKey = getenv("QINIU_SECRET_KEY");
Qiniu_Mac mac;
mac.accessKey = accessKey;
mac.secretKey = secretKey;
//urls to refresh
char *domains[] = {
"csdk.qiniudn.com",
"javasdk.qiniudn.com"
};
int domainsCount = 2;
char *startDate = "2017-08-01";
char *endDate = "2017-08-09";
char *g = "day";
//init
Qiniu_Zero(ret);
Qiniu_Client_InitMacAuth(&client, 1024, &mac);
error = Qiniu_CDN_GetBandwidthData(&client, &ret, startDate, endDate, g, domains, domainsCount);
if (error.code != 200) {
printf("get domain bandwidth error.\n");
debug_log(&client, error);
} else {
printf("get domain bandwidth success.\n\n");
printf("Code: %d\n", ret.code);
printf("Error: %s\n", ret.error);
printf("Domains: %d\n", ret.domainsCount);
printf("-----------\n");
for (i = 0; i < ret.timeCount; i++) {
printf("%s\t", ret.time[i]);
}
printf("\n");
//data
for (i = 0; i < ret.domainsCount; i++) {
printf("Domain:%s\n", domains[i]);
Qiniu_CDN_BandwidthData bandData = ret.data[i];
if (bandData.chinaCount == 0) {
printf("China: no bandwidth data\n");
} else {
printf("China: bandwidth data\n");
for (j = 0; j < bandData.chinaCount; j++) {
printf("%lld\t", bandData.china[j]);
}
printf("\n");
}
if (bandData.overseaCount == 0) {
printf("Oversea: no bandwidth data\n");
} else {
printf("Oversea: bandwidth data\n");
for (j = 0; j < bandData.overseaCount; j++) {
printf("%lld\t", bandData.oversea[j]);
}
printf("\n");
}
printf("-----------\n");
}
Qiniu_Free_CDNBandwidthRet(&ret);
}
Qiniu_Client_Cleanup(&client);
}