LogsQueryAsyncClient Class
- java.
lang. Object - com.
azure. monitor. query. LogsQueryAsyncClient
- com.
public final class LogsQueryAsyncClient
Provides an asynchronous service client for querying logs in the Azure Monitor Service.
The LogsQueryClient is an asynchronous client that provides methods to execute Kusto queries against Azure Monitor logs. It provides methods to query logs in a specific workspace, execute a batch of queries, and query logs for a specific Azure resource.
Getting Started
Authenticating and building instances of this client are handled by LogsQueryClientBuilder. This sample shows how to authenticate and build a LogQueryAsyncClient instance using LogQueryClientBuilder.
LogsQueryAsyncClient logsQueryAsyncClient = new LogsQueryClientBuilder()
.credential(tokenCredential)
.buildAsyncClient();
For more information on building and authenticating, see the LogsQueryClientBuilder documentation.
Client Usage
For more information on how to use this client, see the following method documentation:
- queryWorkspace(String workspaceId, String query, QueryTimeInterval timeInterval) - Query logs from a workspace.
- queryWorkspaceWithResponse(String workspaceId, String query, QueryTimeInterval timeInterval, LogsQueryOptions options) - Query logs from a workspace using query options with service response returned.
- queryBatch(LogsBatchQuery logsBatchQuery) - Execute a batch of logs queries.
- queryBatchWithResponse(LogsBatchQuery logsBatchQuery) - Execute a batch of logs queries with service response returned.
- queryResource(String resourceId, String query, QueryTimeInterval timeInterval) - Query logs for an Azure resource.
- queryResourceWithResponse(String resourceId, String query, QueryTimeInterval timeInterval, LogsQueryOptions options) - Query logs for an Azure resource using query options with service response returned.
Method Summary
Methods inherited from java.lang.Object
Method Details
queryResource
public Mono>
Returns all the Azure Monitor logs matching the given query for an Azure resource.
Parameters:
Returns:
queryResource
public Mono>
Returns all the Azure Monitor logs matching the given query for an Azure resource.
Parameters:
Returns:
queryResourceWithResponse
public Mono
Returns all the Azure Monitor logs matching the given query for an Azure resource.
Parameters:
Returns:
queryWorkspace
public Mono>
Returns all the Azure Monitor logs matching the given query in the specified workspaceId.
Parameters:
Returns:
queryWorkspace
public Mono>
Returns all the Azure Monitor logs matching the given query in the specified workspaceId.
Parameters:
Returns:
queryWorkspaceWithResponse
public Mono
Returns all the Azure Monitor logs matching the given query in the specified workspaceId.
Parameters:
Returns:
queryBatch
public Mono
Returns all the Azure Monitor logs matching the given batch of queries.
Execute a batch of logs queries
LogsBatchQuery batchQuery = new LogsBatchQuery();
String queryId1 = batchQuery.addWorkspaceQuery("{workspace-id-1}", "{kusto-query-1}", QueryTimeInterval.LAST_DAY);
String queryId2 = batchQuery.addWorkspaceQuery("{workspace-id-2}", "{kusto-query-2}",
QueryTimeInterval.LAST_7_DAYS, new LogsQueryOptions().setServerTimeout(Duration.ofMinutes(2)));
Mono<LogsBatchQueryResultCollection> batchQueryResponse = logsQueryAsyncClient.queryBatch(batchQuery);
batchQueryResponse.subscribe(result -> {
for (LogsBatchQueryResult queryResult : result.getBatchResults()) {
System.out.println("Logs query result for query id " + queryResult.getId());
for (LogsTableRow row : queryResult.getTable().getRows()) {
System.out.println(row.getRow()
.stream()
.map(LogsTableCell::getValueAsString)
.collect(Collectors.joining(",")));
}
}
});
Parameters:
Returns:
queryBatchWithResponse
public Mono
Returns all the Azure Monitor logs matching the given batch of queries.
Parameters:
Returns:
queryResource
public Mono
Returns all the Azure Monitor logs matching the given query for an Azure resource.
Query logs from the last 24 hours
Mono<LogsQueryResult> queryResult = logsQueryAsyncClient.queryResource("{resource-id}", "{kusto-query}",
QueryTimeInterval.LAST_DAY);
queryResult.subscribe(result -> {
for (LogsTableRow row : result.getTable().getRows()) {
System.out.println(row.getRow()
.stream()
.map(LogsTableCell::getValueAsString)
.collect(Collectors.joining(",")));
}
});
Parameters:
Returns:
queryResourceWithResponse
public Mono
Returns all the Azure Monitor logs matching the given query for an Azure resource.
Query logs from the last 7 days and set the service timeout to 2 minutes
Mono<Response<LogsQueryResult>> queryResult = logsQueryAsyncClient.queryResourceWithResponse("{resource-id}",
"{kusto-query}",
QueryTimeInterval.LAST_7_DAYS,
new LogsQueryOptions().setServerTimeout(Duration.ofMinutes(2)));
queryResult.subscribe(result -> {
for (LogsTableRow row : result.getValue().getTable().getRows()) {
System.out.println(row.getRow()
.stream()
.map(LogsTableCell::getValueAsString)
.collect(Collectors.joining(",")));
}
});
Parameters:
Returns:
queryWorkspace
public Mono
Returns all the Azure Monitor logs matching the given query in the specified workspaceId.
Query logs from the last 24 hours
Mono<LogsQueryResult> queryResult = logsQueryAsyncClient.queryWorkspace("{workspace-id}", "{kusto-query}",
QueryTimeInterval.LAST_DAY);
queryResult.subscribe(result -> {
for (LogsTableRow row : result.getTable().getRows()) {
System.out.println(row.getRow()
.stream()
.map(LogsTableCell::getValueAsString)
.collect(Collectors.joining(",")));
}
});
Parameters:
Returns:
queryWorkspaceWithResponse
public Mono
Returns all the Azure Monitor logs matching the given query in the specified workspaceId.
Query logs from the last 7 days and set the service timeout to 2 minutes
Mono<Response<LogsQueryResult>> queryResult = logsQueryAsyncClient.queryWorkspaceWithResponse("{workspace-id}",
"{kusto-query}",
QueryTimeInterval.LAST_7_DAYS,
new LogsQueryOptions().setServerTimeout(Duration.ofMinutes(2)));
queryResult.subscribe(result -> {
for (LogsTableRow row : result.getValue().getTable().getRows()) {
System.out.println(row.getRow()
.stream()
.map(LogsTableCell::getValueAsString)
.collect(Collectors.joining(",")));
}
});
Parameters:
Returns:
Applies to
Azure SDK for Java