统计top n的日志组或日志流流量
功能介绍
统计top n的日志组或日志流流量
调用方法
请参见如何调用API。
URI
POST /v2/{project_id}/lts/topn-traffic-statistics
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
项目ID,获取方式请参见:获取项目ID,获取账号ID,日志组ID、日志流ID 缺省值:None |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
X-Auth-Token |
是 |
String |
从IAM服务获取的用户Token,获取方式请参见:获取用户Token |
Content-Type |
是 |
String |
该字段填为:application/json;charset=UTF-8。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
end_time |
是 |
Long |
结束时间时间戳,毫秒时间 |
is_desc |
是 |
Boolean |
是否降序 true / false |
resource_type |
是 |
String |
资源类型,log_group / log_stream / tenant log_group:日志组 log_stream :日志流 tenant:租户 |
sort_by |
是 |
String |
排序依据,index/write/storage/basicTransfer/seniorTransfer/coldStorage,必须是search_list中存在的数据 index:索引 write:读写 storage:存储 basicTransfer:基础转储 seniorTransfer:高级转储 coldStorage:冷存储量 |
start_time |
是 |
Long |
开始时间时间戳,毫秒时间,最多支持30天范围内的查询 |
topn |
是 |
Integer |
查询前多少数据,范围1~100 |
filter |
是 |
Map<String,String> |
过滤条件 { "log_group_id": "xxxxxx" }过滤器,为一个map结构,键为过滤属性,值为属性值,不支持模糊匹配 |
search_list |
是 |
Array of strings |
查询数据类型,字符串数组可多种搭配,只能在index/write/storage/basicTransfer/seniorTransfer/coldStorage中选填 index:索引 write:读写 storage:存储 basicTransfer:基础转储 seniorTransfer:高级转储 coldStorage:冷存储量 |
响应参数
状态码: 200
参数 |
参数类型 |
描述 |
---|---|---|
results |
Array of ResultsTopnBody objects |
响应结果 |
参数 |
参数类型 |
描述 |
---|---|---|
index_traffic |
Double |
索引流量,byte, 查询数据类型中包含index时返回 |
storage |
Double |
存储量,byte, 查询数据类型中包含storage时返回 |
write_traffic |
Double |
写入流量,byte, 查询数据类型中包含write时返回 |
log_group_id |
String |
日志组id,资源类型为日志组时返回 |
log_group_name |
String |
日志组名称,资源类型为日志组时返回 |
log_stream_id |
String |
日志流id,资源类型为日志流时返回 |
log_stream_name |
String |
日志流名称,资源类型为日志流时返回 |
basic_transfer |
Double |
基础转储流量,byte, 查询数据类型中包含basicTransfer时返回 |
senior_transfer |
Double |
基础转储流量,byte, 查询数据类型中包含seniorTransfer时返回 |
is_agency_transfer |
Boolean |
不是委托转储,true,是委托转储,则前端资源统计展示的流不能跳 |
cold_storage |
Double |
冷存储量 |
状态码: 400
参数 |
参数类型 |
描述 |
---|---|---|
errorCode |
String |
错误码 |
errorMessage |
String |
错误描述 |
状态码: 500
参数 |
参数类型 |
描述 |
---|---|---|
errorCode |
String |
错误码 |
errorMessage |
String |
错误描述 |
请求示例
统计top n的日志组或日志流流量
/v2/2a473356cca5487f8373be891bffc1cf/lts/topn-traffic-statistics { "sort_by" : "storage", "is_desc" : true, "resource_type" : "log_stream", "filter" : { }, "start_time" : 1668668183969, "end_time" : 1669272983969, "search_list" : [ "index", "write", "storage" ], "topn" : 100 }
响应示例
状态码: 200
查询资源成功
{ "results" : [ { "index_traffic" : 0, "log_stream_id" : "6fd93d47-7630-4284-a622-311d0082f6bb", "log_stream_name" : "cmdb-cce-cluster", "storage" : 59810657587, "write_traffic" : 0 }, { "index_traffic" : 0, "log_stream_id" : "504ec3dd-ac28-4783-babb-22a49f36afe3", "log_stream_name" : "CMSkaifatest", "storage" : 20033606015, "write_traffic" : 0 }, { "index_traffic" : 6825703991, "log_stream_id" : "a14dacb0-5a13-43a8-89a3-ea5424d95133", "log_stream_name" : "ELB", "storage" : 15659303771, "write_traffic" : 1.3651407982E9 }, { "index_traffic" : 302172889, "log_stream_id" : "25fe7494-7395-438e-8340-647613673ffa", "log_stream_name" : "LTStest-916-statefulset", "storage" : 316552589, "write_traffic" : 6.04345778E7 }, { "index_traffic" : 0, "log_stream_id" : "956586fc-b828-44be-8672-0a323962a8fa", "log_stream_name" : "mongodb_slow", "storage" : 0, "write_traffic" : 0 } ] }
状态码: 400
BadRequest 非法请求建议根据error_msg直接修改该请求
{ "errorCode" : "LTS.0208", "errorMessage" : "The log stream does not existed" }
状态码: 500
表明服务端能被请求访问到,但是服务内部出错
{ "errorCode" : "LTS.0203", "errorMessage" : "Internal Server Error" }
SDK代码示例
SDK代码示例如下。
统计top n的日志组或日志流流量
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 |
package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.lts.v2.region.LtsRegion; import com.huaweicloud.sdk.lts.v2.*; import com.huaweicloud.sdk.lts.v2.model.*; import java.util.List; import java.util.ArrayList; import java.util.Map; import java.util.HashMap; public class ListTopnTrafficStatisticsSolution { public static void main(String[] args) { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment String ak = System.getenv("CLOUD_SDK_AK"); String sk = System.getenv("CLOUD_SDK_SK"); String projectId = "{project_id}"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); LtsClient client = LtsClient.newBuilder() .withCredential(auth) .withRegion(LtsRegion.valueOf("<YOUR REGION>")) .build(); ListTopnTrafficStatisticsRequest request = new ListTopnTrafficStatisticsRequest(); TopnRequstBody body = new TopnRequstBody(); List<String> listbodySearchList = new ArrayList<>(); listbodySearchList.add("index"); listbodySearchList.add("write"); listbodySearchList.add("storage"); body.withSearchList(listbodySearchList); body.withTopn(100); body.withStartTime(1668668183969L); body.withSortBy("storage"); body.withResourceType("log_stream"); body.withIsDesc(true); body.withEndTime(1669272983969L); request.withBody(body); try { ListTopnTrafficStatisticsResponse response = client.listTopnTrafficStatistics(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } } |
统计top n的日志组或日志流流量
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 |
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdklts.v2.region.lts_region import LtsRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdklts.v2 import * if __name__ == "__main__": # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = LtsClient.new_builder() \ .with_credentials(credentials) \ .with_region(LtsRegion.value_of("<YOUR REGION>")) \ .build() try: request = ListTopnTrafficStatisticsRequest() listSearchListbody = [ "index", "write", "storage" ] request.body = TopnRequstBody( search_list=listSearchListbody, topn=100, start_time=1668668183969, sort_by="storage", resource_type="log_stream", is_desc=True, end_time=1669272983969 ) response = client.list_topn_traffic_statistics(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) |
统计top n的日志组或日志流流量
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 |
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" lts "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/lts/v2" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/lts/v2/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/lts/v2/region" ) func main() { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak := os.Getenv("CLOUD_SDK_AK") sk := os.Getenv("CLOUD_SDK_SK") projectId := "{project_id}" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := lts.NewLtsClient( lts.LtsClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.ListTopnTrafficStatisticsRequest{} var listSearchListbody = []string{ "index", "write", "storage", } request.Body = &model.TopnRequstBody{ SearchList: listSearchListbody, Topn: int32(100), StartTime: int64(1668668183969), SortBy: "storage", ResourceType: "log_stream", IsDesc: true, EndTime: int64(1669272983969), } response, err := client.ListTopnTrafficStatistics(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
200 |
查询资源成功 |
400 |
BadRequest 非法请求建议根据error_msg直接修改该请求 |
500 |
表明服务端能被请求访问到,但是服务内部出错 |
错误码
请参见错误码。