Azure Cognitive Services Anomaly Detector client library for .NET
Microsoft Azure Cognitive Services Anomaly Detector API enables you to monitor and detect abnormalities in your time series data with machine learning.
Install the package
Install the Azure Anomaly Detector client library for .NET with NuGet:
dotnet add package Azure.AI.AnomalyDetector --version 3.0.0-preview.3
- An Azure subscription.
- An existing Cognitive Services or Anomaly Detector resource.
For more information about creating the resource or how to get the location and sku information see here.
Authenticate the client
In order to interact with the Anomaly Detector service, you'll need to create an instance of the
AnomalyDetectorClient class. You will need an endpoint and an API key to instantiate a client object.
Get API Key
You can obtain the endpoint and API key from the resource information in the Azure Portal.
Alternatively, you can use the Azure CLI snippet below to get the API key from the Anomaly Detector resource.
az cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>
Create AnomalyDetectorClient with AzureKeyCredential
Once you have the value for the API key, create an
AzureKeyCredential. With the endpoint and key credential, you can create the
string endpoint = "<endpoint>"; string apiKey = "<apiKey>"; var credential = new AzureKeyCredential(apiKey); var client = new AnomalyDetectorClient(new Uri(endpoint), credential);
Create AnomalyDetectorClient with Azure Active Directory Credential
AzureKeyCredential authentication is used in the examples in this getting started guide, but you can also authenticate with Azure Active Directory using the Azure Identity library. Note that regional endpoints do not support AAD authentication. Create a custom subdomain for your resource in order to use this type of authentication.
To use the DefaultAzureCredential provider shown below, or other credential providers provided with the Azure SDK, please install the
Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.
string endpoint = "<endpoint>"; var client = new AnomalyDetectorClient(new Uri(endpoint), new DefaultAzureCredential());
We guarantee that all client instance methods are thread-safe and independent of each other (guideline). This ensures that the recommendation of reusing client instances is always safe, even across threads.
Setting up console logging
The simplest way to see the logs is to enable the console logging. To create an Azure SDK log listener that outputs messages to console use the AzureEventSourceListener.CreateConsoleLogger method.
// Setup a listener to monitor logged events. using AzureEventSourceListener listener = AzureEventSourceListener.CreateConsoleLogger();
To learn more about other logging mechanisms see Diagnostics Samples.
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.