Package com.azure.monitor.ingestion
Getting Started
Prerequisites
The client library requires the following:
- Java 8 or later
- An Azure subscription
- An existing Azure Monitor Data Collection Rule
- An existing Azure Monitor Data Collection Endpoint
- An existing Azure Monitor Log Analytics workspace
Authenticate a Client
The LogIngestionClient and
LogIngestionAsyncClient can be authenticated
using Microsoft Entra ID. To authenticate with Microsoft Entra ID, create a
TokenCredential that can be passed to the
LogIngestionClientBuilder. The Azure Identity
library provides implementations of TokenCredential for
multiple authentication flows. See TokenCredential for multiple
authentication flows. See Azure Identity
Azure
Identity
for more information. See LogIngestionClientBuilder
for more examples on authenticating a client.
The following sample demonstrates how to create a LogIngestionClient
using LogIngestionClientBuilder and TokenCredential
authentication.
LogsIngestionClient logsIngestionClient = new LogsIngestionClientBuilder()
.credential(tokenCredential)
.endpoint("<data-collection-endpoint>")
.buildClient();
Overview
The Logs Ingestion REST API in Azure Monitor lets you send data to a Log Analytics workspace. The API allows you to send data to supported tables or to custom tables that you create. You can also extend the schema of Azure tables with custom columns to accept additional data.
The Azure Monitor Ingestion client library provides both synchronous and asynchronous client implementations, providing you the capability to send custom logs to an Azure Monitor Log Analytics workspace.
Key Concepts
Data Collection Endpoint
Data Collection Endpoints (DCEs) allow you to uniquely configure ingestion settings for Azure Monitor. This article provides an overview of data collection endpoints including their contents and structure and how you can create and work with them.
Data Collection Rule
Data collection rules (DCR) define data collected by Azure Monitor and specify how and where that data should be sent or stored. The REST API call must specify a DCR to use. A single DCE can support multiple DCRs, so you can specify a different DCR for different sources and target tables.
The DCR must understand the structure of the input data and the structure of the target table. If the two don't match, it can use a transformation to convert the source data to match the target table. You may also use the transform to filter source data and perform any other calculations or conversions.
For more details, see Data collection rules in Azure Monitor. For information on how to retrieve a DCR ID, see this tutorial.
Log Analytics Workspace Tables
Custom logs can send data to any custom table that you create and to certain built-in tables in your Log Analytics workspace. The target table must exist before you can send data to it.
Logs retrieval
The logs that were uploaded using this library can be queried using the Azure Monitor Query client library.
Client Usage
Uploading logs to Azure Monitor
The following sample demonstrates how to upload logs to Azure Monitor using
LogIngestionClient.
List<Object> logs = getLogs();
logsIngestionClient.upload("<data-collection-rule-id>", "<stream-name>", logs);
System.out.println("Logs uploaded successfully");
For more synchronous and asynchronous client usage information, see
LogsIngestionClient and
LogsIngestionAsyncClient, respectively.
- See Also:
-
ClassDescriptionThis class provides an asynchronous client for uploading custom logs to an Azure Monitor Log Analytics workspace.This class provides a synchronous client for uploading custom logs to an Azure Monitor Log Analytics workspace.Fluent builder for creating instances of
LogsIngestionClientandLogsIngestionAsyncClient.Service version of LogsIngestionClient.