统计与日志接口
更新时间:2023-05-16
获取访问日志
public void getDomainLog(CdnClient client) {
String domain = "my.test.com";
// 用法1: 查询指定域名过去两个小时的访问日志
GetDomainLogResponse response = client.getDomainLog(domain, new Date(new Date().getTime() - 3600*2000), new Date());
// 用法2: 查询指定域名某个时间段的访问日志
String startTime = "2019-03-04T00:00:00Z";
String endTime = "2019-03-04T23:00:00Z";
GetDomainLogResponse response = client.getDomainLog(domain, startTime, endTime);
System.out.println(response);
}
获取多个域名日志
public void getDomainListLog(CdnClient client){
String domain = "my.test.com";
GetDomainListLogRequest request = new GetDomainListLogRequest()
.withType(2L)
.withStartTime("2020-03-04T00:00:00Z")
.withEndTime("2020-03-04T23:00:00Z")
.withPageNo(1)
.withPageSize(1000)
.withDomains(Arrays.asList(domain));
GetDomainListLogResponse response = cdnClient.getDomainListLog(request);
System.out.println(response);
}
统计查询接口(新版)
public void getStatMetricData(CdnClient client) throws Exception {
String domain = "my.test.com";
/**
* 具体metric请参考官网API接口文档:https://cloud.baidu.com/doc/CDN/s/5jwvyf8zn
* flow: 查询流量、带宽
* avg_speed: 查询平均速率
* avg_speed_region: 客户端访问分布查询平均速率
* pv: pv/qps查询
* pv_protocol: pv/qps https协议查询
* pv_src: 回源pv/qps查询
*/
String metricName = "flow";
GetStatMetricRequest request = new GetStatMetricRequest()
.withMetric(metricName)
.withStartTime("2019-03-19T06:00:00Z")
.withEndTime("2019-03-19T06:10:00Z")
.withKey(Arrays.asList(domain));
GetMetricStatResponse response = client.getStatMetricData(request);
System.out.println(response);
}
**注意: metric具体类型以官方文档为准 https://cloud.baidu.com/doc/CDN/s/5jwvyf8zn#默认请求体(request-body)
查询月95峰值带宽
public void getMonth95Data(CdnClient client) throws Exception {
String domain = "my.test.com";
GetMonth95Request request = new GetMonth95Request()
.withType("peak95")
.withStartTime("2019-03-19T06:00:00Z")
.withEndTime("2019-03-19T06:10:00Z")
.withDomains(domain);
GetMonth95Response response = client.getMonth95Data(request);
System.out.println(response);
}
TopN查询接口
public void getTopStatData(CdnClient client) throws Exception {
String domain = "my.test.com";
GetStatMetricRequest request = new GetStatMetricRequest()
.withMetric("top_urls")
.withStartTime("2022-03-19T06:00:00Z")
.withEndTime("2022-03-19T06:40:00Z")
.withKeyType(0)
.withKey(domain);
GetTopStatResponse response = client.getTopStatData(request);
System.out.println(response);
}
**注意: metric具体类型以官方文档为准 https://cloud.baidu.com/doc/CDN/s/5jwvyf8zn#topn查询接口
查询 IPV6 数据接口
public void getStatIpv6Data(CdnClient client) throws Exception {
String domain = "my.test.com";
GetIpv6StatRequest request = new GetIpv6StatRequest()
.withStartTime("2022-03-19T06:00:00Z")
.withEndTime("2022-03-19T06:40:00Z")
.withPeriod(3600)
.withKeys(Arrays.asList(domain));
GetIpv6StatResponse response = client.getStatIpv6Data(request);
System.out.println(response);
}
查询 IPV6 分区域数据接口
public void getStatIpv6Data(CdnClient client) throws Exception {
String domain = "my.test.com";
GetIpv6StatRequest request = new GetIpv6StatRequest()
.withStartTime("2022-03-19T06:00:00Z")
.withEndTime("2022-03-19T06:40:00Z")
.withPeriod(3600)
.withProv("广东")
.withIsp("电信")
.withKeys(Arrays.asList(domain));
GetIpv6RegionStatResponse response = client.getStatRegionIpv6Data(request);
System.out.println(response);
}
查询错误状态码数
public void getErrorCodeStatData(CdnClient client) throws Exception {
String domain = "my.test.com";
GetIpv6StatRequest request = new GetIpv6StatRequest()
.withStartTime("2022-03-19T06:00:00Z")
.withEndTime("2022-03-19T06:40:00Z")
.withPeriod(3600)
.withProv("广东")
.withIsp("电信")
.withKeys(Arrays.asList(domain));
GetIpv6RegionStatResponse response = client.getErrorCodeStatData(request);
System.out.println(response);
}
查询上行流量
public void getUploadStatData(CdnClient client) throws Exception {
String domain = "my.test.com";
GetUploadStatRequest request = new GetUploadStatRequest()
.withStartTime("2022-03-19T06:00:00Z")
.withEndTime("2022-03-19T06:40:00Z")
.withPeriod(300)
.withDomains(Arrays.asList(domain))
.withBandwidth(true);
GetUploadStatResponse response = cdnClient.getUploadStatData(request);
System.out.println(response);
}
查询上行流量峰值
public void getUploadPeakStatData(CdnClient client) throws Exception {
String domain = "my.test.com";
GetUploadStatRequest request = new GetUploadStatRequest()
.withStartTime("2022-03-19T06:00:00Z")
.withEndTime("2022-03-19T06:40:00Z")
.withPeriod(300)
.withDomains(Arrays.asList(domain));
GetUploadStatResponse response = cdnClient.getUploadPeakStatData(request);
System.out.println(response);
}
查询xcdn统计
public void getXcdnStatData(CdnClient client) throws Exception {
String domain = "my.test.com";
GetXcdnStatMetricRequest request = new GetXcdnStatMetricRequest()
.withMetric("flow")
.withStartTime("2022-03-19T06:00:00Z")
.withEndTime("2022-03-19T06:40:00Z")
.withKeys(Arrays.asList(domain));
GetXcdnStatMetricResponse response = cdnClient.getXcdnStatData(request);
System.out.println(response);
}