日志管理
更新时间:2024-10-14
日志管理
查询慢日志明细
使用以下代码查询慢日志明细。
public void getSlowLog(RdsClient rdsClient){
RdsSlowLogRequest request = new RdsSlowLogRequest();
//实例ID,可选
request.setInstanceId("rds-N5CfquAn");
//开始时间,可选
request.setStartTime(DATE_FORMAT.parse("2024-07-01T00:00:00Z"));
//结束时间,可选
request.setEndTime(DATE_FORMAT.parse("2024-07-12T00:00:00Z"));
//开始页数,可选
request.setPageNo(0);
//每页行数 ,默认为10,可选
request.setPageSize(10);
List<String> dbs = new ArrayList<>();
//默认为:数据库名称,可选
dbs.add("db_123");
request.setDbName(dbs);
List<String> ips = new ArrayList<>();
//主机名,可选
ips.add("localhost");
request.setHostIp(ips);
List<String> names = new ArrayList<>();
//用户名,可选
names.add("testName");
request.setUserName(names);
//sql语句,可选
request.setSql("sleep(1)");
RdsSlowLogResponse slowLogResponse = rdsClient.getSlowLog(request);
print("getSlowLog", slowLogResponse);
}
查询慢日志列表
使用以下代码可以查询指定实例的慢日志列表。
public void getSlowLogDownloadTaskList(RdsClient rdsClient) {
RdsSlowLogDownloadTasksRequest request = new RdsSlowLogDownloadTasksRequest();
//实例ID,必选
request.setInstanceId("rds-N5CfquAn");
//慢日志时间,必选
request.setDatetime("2024-07-11T19:48:05Z");
RdsSlowLogDownloadTasksResponse response = rdsClient.getSlowLogDownloadTaskList(request);
print("getSlowLogDownloadTaskList", response);
}
查询慢日志下载详情
使用以下代码可以查询慢日志下载详情。
public void getSlowLogDownloadDetail(RdsClient rdsClient) {
RdsSlowLogDownloadDetailRequest request = new RdsSlowLogDownloadDetailRequest();
//实例ID,必选
request.setInstanceId("rds-jHqrZCEk");
//慢日志ID,必选
request.setLogId("slowlog.202307310005");
//下载有效时间(单位:秒),必选
request.setDownloadValidTimeInSec(1800);
RdsSlowLogDownloadDetailResponse detailResponse = rdsClient.getSlowLogDownloadDetail(request);
print("getSlowLogDownloadDetail", detailResponse);
}
获取错误日志详情
使用以下代码可以获取错误日志详情
public void getSlowLogGetErrorLogDetails(RdsClient rdsClient) {
RdsSlowLogGetErrorLogDetailsRequest request = new RdsSlowLogGetErrorLogDetailsRequest();
//实例ID,可选
request.setInstanceId("rds-b3VFCjMA");
//开始时间,可选
request.setStartTime("2024-07-10T16:00:00Z");
//结束时间,可选
request.setEndTime("2024-07-10T16:00:05Z");
//开始页数 1,可选
request.setPageNo("1");
//每页行数 ,默认为10,可选
request.setPageSize("10");
//搜索关键词,可选
request.setKeyWord("Logging");
RdsSlowLogGetErrorLogDetailsResponse response = rdsClient.getSlowLogGetErrorLogDetails(request);
print("getSlowLogGetErrorLogDetails", response);
}
错误日志下载详情
使用以下代码可以获取错误日志下载详情
public void getSlowLogErrorLogDownloadDetails(RdsClient rdsClient) {
RdsSlowLogErrorLogDownloadDetailsRequest request = new RdsSlowLogErrorLogDownloadDetailsRequest();
//实例ID,必选
request.setInstanceId("rds-1AfwpHXs");
//错误日志ID,必选
request.setLogId("slowlog.202307310005");
//下载有效时间(单位:秒),必选
request.setDownloadValidTimeInSec(1090);
RdsSlowLogErrorLogDownloadDetailsResponse response = rdsClient.getSlowLogErrorLogDownloadDetails(request);
print("getSlowLogErrorLogDownloadDetails", response);
}
错误日志列表
使用以下代码可以获取错误日志列表
public void slowLogGetErrorLogList(RdsClient rdsClient) {
RdsSlowLogGetErrorLogListRequest request = new RdsSlowLogGetErrorLogListRequest();
//实例ID,必选
request.setInstanceId("rds-jHqrZCEk");
//UTC 日期时间(比如要查询 2023-07-28 的日志,则该参数取值 2023-07-28 16:43:39),必选
request.setDatetime("2024-07-11 00:00:00");
RdsSlowLogGetErrorLogListResponse response = rdsClient.slowLogGetErrorLogList(request);
print("slowLogGetErrorLogList", response);
}
获取pg日志详情
使用以下代码可以获取pg日志详情
public void getPGLogDetails(RdsClient rdsClient) {
RdsGetPGLogDetailsRequest request = new RdsGetPGLogDetailsRequest();
//实例ID,必选
request.setInstanceId("rds-jHqrZCEk");
//pg 日志ID,必选
request.setPglogId("postgresql-2024-07-11_000000.log");
//下载链接有效期,单位是秒。默认值3600
request.setDownloadValidTimeInSec(3600);
RdsGetPGLogDetailsResponse response = rdsClient.getPGLogDetails(request);
print("getPGLogDetails", response);
}
获取pg日志列表
使用以下代码可以获取pg日志列表
public void getPGList(RdsClient rdsClient) {
RdsGetPGListRequest request = new RdsGetPGListRequest();
//实例ID,必选
request.setInstanceId("rds-jHqrZCEk");
//日期,格式如:2023-06-14,必选
request.setDate("2023-06-14");
RdsGetPGListResponse response = rdsClient.getPGList(request);
print("getPGList", response);
}