LogsQueryClient Class
- java.
lang. Object - com.
azure. monitor. query. LogsQueryClient
- com.
public final class LogsQueryClient
Provides a synchronous service client for querying logs in the Azure Monitor Service.
The LogsQueryClient is a synchronous 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. his sample shows how to authenticate and build a LogsQueryClient instance using LogQueryClientBuilder.
LogsQueryClient logsQueryClient = new LogsQueryClientBuilder()
.credential(tokenCredential)
.buildClient();
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, Context context) - Query logs from a workspace using query options and context with service response returned.
- queryBatch(LogsBatchQuery logsBatchQuery) - Execute a batch of logs queries.
- queryBatchWithResponse(LogsBatchQuery logsBatchQuery, Context context) - Execute a batch of logs queries with context and 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, Context context) - Query logs for an Azure resource with query options and context with service response returned.
Method Summary
Methods inherited from java.lang.Object
Method Details
queryResource
public List
Returns all the Azure Monitor logs matching the given query for an Azure resource.
Parameters:
Returns:
queryResource
public List
Returns all the Azure Monitor logs matching the given query for an Azure resource.
Parameters:
Returns:
queryResourceWithResponse
public Response<>
Returns all the Azure Monitor logs matching the given query for an Azure resource.
Parameters:
Returns:
queryWorkspace
public List
Returns all the Azure Monitor logs matching the given query in the specified workspaceId.
Parameters:
Returns:
queryWorkspace
public List
Returns all the Azure Monitor logs matching the given query in the specified workspaceId.
Parameters:
Returns:
queryWorkspaceWithResponse
public Response<>
Returns all the Azure Monitor logs matching the given query in the specified workspaceId.
Parameters:
Returns:
queryBatch
public LogsBatchQueryResultCollection 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)));
LogsBatchQueryResultCollection batchQueryResponse = logsQueryClient.queryBatch(batchQuery);
for (LogsBatchQueryResult queryResult : batchQueryResponse.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 Response
Returns all the Azure Monitor logs matching the given batch of queries.
Parameters:
Returns:
queryResource
public LogsQueryResult 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
LogsQueryResult queryResult = logsQueryClient.queryResource("{resource-id}", "{kusto-query}",
QueryTimeInterval.LAST_DAY);
for (LogsTableRow row : queryResult.getTable().getRows()) {
System.out.println(row.getRow()
.stream()
.map(LogsTableCell::getValueAsString)
.collect(Collectors.joining(",")));
}
Parameters:
Returns:
queryResourceWithResponse
public Response
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
Response<LogsQueryResult> queryResult = logsQueryClient.queryResourceWithResponse("{resource-id}",
"{kusto-query}",
QueryTimeInterval.LAST_7_DAYS,
new LogsQueryOptions().setServerTimeout(Duration.ofMinutes(2)),
Context.NONE);
for (LogsTableRow row : queryResult.getValue().getTable().getRows()) {
System.out.println(row.getRow()
.stream()
.map(LogsTableCell::getValueAsString)
.collect(Collectors.joining(",")));
}
Parameters:
Returns:
queryWorkspace
public LogsQueryResult 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
LogsQueryResult queryResult = logsQueryClient.queryWorkspace("{workspace-id}", "{kusto-query}",
QueryTimeInterval.LAST_DAY);
for (LogsTableRow row : queryResult.getTable().getRows()) {
System.out.println(row.getRow()
.stream()
.map(LogsTableCell::getValueAsString)
.collect(Collectors.joining(",")));
}
Parameters:
Returns:
queryWorkspaceWithResponse
public Response
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
Response<LogsQueryResult> queryResult = logsQueryClient.queryWorkspaceWithResponse("{workspace-id}",
"{kusto-query}",
QueryTimeInterval.LAST_7_DAYS,
new LogsQueryOptions().setServerTimeout(Duration.ofMinutes(2)),
Context.NONE);
for (LogsTableRow row : queryResult.getValue().getTable().getRows()) {
System.out.println(row.getRow()
.stream()
.map(LogsTableCell::getValueAsString)
.collect(Collectors.joining(",")));
}
Parameters:
Returns:
Applies to
Azure SDK for Java
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for