LogsQueryAsyncClient Class

  • java.lang.Object
    • com.azure.monitor.query.LogsQueryAsyncClient

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:

Method Summary

Modifier and Type Method and Description
Mono<List<T>> queryResource(String resourceId, String query, QueryTimeInterval timeInterval, Class<T> type)

Returns all the Azure Monitor logs matching the given query for an Azure resource.

Mono<List<T>> queryResource(String resourceId, String query, QueryTimeInterval timeInterval, Class<T> type, LogsQueryOptions options)

Returns all the Azure Monitor logs matching the given query for an Azure resource.

Mono<Response<List<T>>> queryResourceWithResponse(String resourceId, String query, QueryTimeInterval timeInterval, Class<T> type, LogsQueryOptions options)

Returns all the Azure Monitor logs matching the given query for an Azure resource.

Mono<List<T>> queryWorkspace(String workspaceId, String query, QueryTimeInterval timeInterval, Class<T> type)

Returns all the Azure Monitor logs matching the given query in the specified workspaceId.

Mono<List<T>> queryWorkspace(String workspaceId, String query, QueryTimeInterval timeInterval, Class<T> type, LogsQueryOptions options)

Returns all the Azure Monitor logs matching the given query in the specified workspaceId.

Mono<Response<List<T>>> queryWorkspaceWithResponse(String workspaceId, String query, QueryTimeInterval timeInterval, Class<T> type, LogsQueryOptions options)

Returns all the Azure Monitor logs matching the given query in the specified workspaceId.

Mono<LogsBatchQueryResultCollection> queryBatch(LogsBatchQuery logsBatchQuery)

Returns all the Azure Monitor logs matching the given batch of queries.

Mono<Response<LogsBatchQueryResultCollection>> queryBatchWithResponse(LogsBatchQuery logsBatchQuery)

Returns all the Azure Monitor logs matching the given batch of queries.

Mono<LogsQueryResult> queryResource(String resourceId, String query, QueryTimeInterval timeInterval)

Returns all the Azure Monitor logs matching the given query for an Azure resource.

Mono<Response<LogsQueryResult>> queryResourceWithResponse(String resourceId, String query, QueryTimeInterval timeInterval, LogsQueryOptions options)

Returns all the Azure Monitor logs matching the given query for an Azure resource.

Mono<LogsQueryResult> queryWorkspace(String workspaceId, String query, QueryTimeInterval timeInterval)

Returns all the Azure Monitor logs matching the given query in the specified workspaceId.

Mono<Response<LogsQueryResult>> queryWorkspaceWithResponse(String workspaceId, String query, QueryTimeInterval timeInterval, LogsQueryOptions options)

Returns all the Azure Monitor logs matching the given query in the specified workspaceId.

Methods inherited from java.lang.Object

Method Details

queryResource

public Mono> queryResource(String resourceId, String query, QueryTimeInterval timeInterval, Class type)

Returns all the Azure Monitor logs matching the given query for an Azure resource.

Parameters:

resourceId - The resourceId where the query should be executed.
query - The Kusto query to fetch the logs.
timeInterval - The time period for which the logs should be looked up.
type - The type the result of this query should be mapped to.

Returns:

The logs matching the query as a list of objects of type T.

queryResource

public Mono> queryResource(String resourceId, String query, QueryTimeInterval timeInterval, Class type, LogsQueryOptions options)

Returns all the Azure Monitor logs matching the given query for an Azure resource.

Parameters:

resourceId - The resourceId where the query should be executed.
query - The Kusto query to fetch the logs.
timeInterval - The time period for which the logs should be looked up.
type - The type the result of this query should be mapped to.
options - The log query options to configure server timeout, set additional workspaces or enable statistics and rendering information in response.

Returns:

The logs matching the query as a list of objects of type T.

queryResourceWithResponse

public Mono>> queryResourceWithResponse(String resourceId, String query, QueryTimeInterval timeInterval, Class type, LogsQueryOptions options)

Returns all the Azure Monitor logs matching the given query for an Azure resource.

Parameters:

resourceId - The resourceId where the query should be executed.
query - The Kusto query to fetch the logs.
timeInterval - The time period for which the logs should be looked up.
type - The type the result of this query should be mapped to.
options - The log query options to configure server timeout, set additional workspaces or enable statistics and rendering information in response.

Returns:

The logs matching the query including the HTTP response.

queryWorkspace

public Mono> queryWorkspace(String workspaceId, String query, QueryTimeInterval timeInterval, Class type)

Returns all the Azure Monitor logs matching the given query in the specified workspaceId.

Parameters:

workspaceId - The workspaceId where the query should be executed.
query - The Kusto query to fetch the logs.
timeInterval - The time period for which the logs should be looked up.
type - The type the result of this query should be mapped to.

Returns:

The logs matching the query as a list of objects of type T.

queryWorkspace

public Mono> queryWorkspace(String workspaceId, String query, QueryTimeInterval timeInterval, Class type, LogsQueryOptions options)

Returns all the Azure Monitor logs matching the given query in the specified workspaceId.

Parameters:

workspaceId - The workspaceId where the query should be executed.
query - The Kusto query to fetch the logs.
timeInterval - The time period for which the logs should be looked up.
type - The type the result of this query should be mapped to.
options - The log query options to configure server timeout, set additional workspaces or enable statistics and rendering information in response.

Returns:

The logs matching the query as a list of objects of type T.

queryWorkspaceWithResponse

public Mono>> queryWorkspaceWithResponse(String workspaceId, String query, QueryTimeInterval timeInterval, Class type, LogsQueryOptions options)

Returns all the Azure Monitor logs matching the given query in the specified workspaceId.

Parameters:

workspaceId - The workspaceId where the query should be executed.
query - The Kusto query to fetch the logs.
timeInterval - The time period for which the logs should be looked up.
type - The type the result of this query should be mapped to.
options - The log query options to configure server timeout, set additional workspaces or enable statistics and rendering information in response.

Returns:

The logs matching the query including the HTTP response.

queryBatch

public Mono queryBatch(LogsBatchQuery logsBatchQuery)

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:

logsBatchQuery - LogsBatchQuery containing a batch of queries.

Returns:

A collection of query results corresponding to the input batch of queries.@return

queryBatchWithResponse

public Mono> queryBatchWithResponse(LogsBatchQuery logsBatchQuery)

Returns all the Azure Monitor logs matching the given batch of queries.

Parameters:

logsBatchQuery - LogsBatchQuery containing a batch of queries.

Returns:

A collection of query results corresponding to the input batch of queries.@return

queryResource

public Mono queryResource(String resourceId, String query, QueryTimeInterval timeInterval)

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:

resourceId - The resourceId where the query should be executed.
query - The Kusto query to fetch the logs.
timeInterval - The time period for which the logs should be looked up.

Returns:

The logs matching the query.

queryResourceWithResponse

public Mono> queryResourceWithResponse(String resourceId, String query, QueryTimeInterval timeInterval, LogsQueryOptions options)

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:

resourceId - The resourceId where the query should be executed.
query - The Kusto query to fetch the logs.
timeInterval - The time period for which the logs should be looked up.
options - The log query options to configure server timeout, set additional workspaces or enable statistics and rendering information in response.

Returns:

The logs matching the query.

queryWorkspace

public Mono queryWorkspace(String workspaceId, String query, QueryTimeInterval timeInterval)

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:

workspaceId - The workspaceId where the query should be executed.
query - The Kusto query to fetch the logs.
timeInterval - The time period for which the logs should be looked up.

Returns:

The logs matching the query.

queryWorkspaceWithResponse

public Mono> queryWorkspaceWithResponse(String workspaceId, String query, QueryTimeInterval timeInterval, LogsQueryOptions options)

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:

workspaceId - The workspaceId where the query should be executed.
query - The Kusto query to fetch the logs.
timeInterval - The time period for which the logs should be looked up.
options - The log query options to configure server timeout, set additional workspaces or enable statistics and rendering information in response.

Returns:

The logs matching the query.

Applies to