public async Task GetAlertConfigurationAsync() { string endpoint = MetricsAdvisorUri; string subscriptionKey = MetricsAdvisorSubscriptionKey; string apiKey = MetricsAdvisorApiKey; var credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey); var adminClient = new MetricsAdvisorAdministrationClient(new Uri(endpoint), credential); string alertConfigurationId = AlertConfigurationId; Response <AnomalyAlertConfiguration> response = await adminClient.GetAlertConfigurationAsync(alertConfigurationId); AnomalyAlertConfiguration alertConfiguration = response.Value; Console.WriteLine($"Alert configuration name: {alertConfiguration.Name}"); Console.WriteLine($"Alert configuration description: {alertConfiguration.Description}"); Console.WriteLine(); Console.WriteLine($"IDs of hooks to alert:"); foreach (string hookId in alertConfiguration.IdsOfHooksToAlert) { Console.WriteLine($" - {hookId}"); } Console.WriteLine(); Console.WriteLine("Metric anomaly alert configurations:"); foreach (MetricAnomalyAlertConfiguration metricAlertConfiguration in alertConfiguration.MetricAlertConfigurations) { Console.Write($" Scope type: {metricAlertConfiguration.AlertScope.ScopeType}, "); Console.WriteLine($"Anomaly detection configuration ID: {metricAlertConfiguration.DetectionConfigurationId}"); } }
public async Task UpdateDataFeedAsync() { string endpoint = MetricsAdvisorUri; string subscriptionKey = MetricsAdvisorSubscriptionKey; string apiKey = MetricsAdvisorApiKey; var credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey); var adminClient = new MetricsAdvisorAdministrationClient(new Uri(endpoint), credential); string dataFeedId = DataFeedId; Response <DataFeed> response = await adminClient.GetDataFeedAsync(dataFeedId); DataFeed dataFeed = response.Value; string originalDescription = dataFeed.Description; dataFeed.Description = "This description was generated by a sample."; await adminClient.UpdateDataFeedAsync(dataFeedId, dataFeed); // Undo the changes to leave the data feed unaltered. Skip this step if you intend to keep // the changes. dataFeed.Description = originalDescription; await adminClient.UpdateDataFeedAsync(dataFeedId, dataFeed); }
public async Task CreateHookForReceivingAnomalyAlerts() { string endpoint = MetricsAdvisorUri; string subscriptionKey = MetricsAdvisorSubscriptionKey; string apiKey = MetricsAdvisorApiKey; var credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey); var adminClient = new MetricsAdvisorAdministrationClient(new Uri(endpoint), credential); #region Snippet:CreateHookForReceivingAnomalyAlerts string hookName = "Sample hook"; var emailsToAlert = new List <string>() { "*****@*****.**", "*****@*****.**" }; var emailHook = new EmailHook(hookName, emailsToAlert); Response <AlertingHook> response = adminClient.CreateHook(emailHook); AlertingHook hook = response.Value; Console.WriteLine($"Hook ID: {hook.Id}"); #endregion // Delete the created hook to clean up the Metrics Advisor resource. Do not perform this // step if you intend to keep using the hook. await adminClient.DeleteHookAsync(hook.Id); }
public async Task CreateAndDeleteDataSourceCredentialAsync() { string endpoint = MetricsAdvisorUri; string subscriptionKey = MetricsAdvisorSubscriptionKey; string apiKey = MetricsAdvisorApiKey; var credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey); var adminClient = new MetricsAdvisorAdministrationClient(new Uri(endpoint), credential); #region Snippet:CreateDataSourceCredentialAsync #if SNIPPET string credentialName = "<credentialName>"; #else string credentialName = GetUniqueName(); #endif var credentialEntity = new ServicePrincipalCredentialEntity(credentialName, "<clientId>", "<clientSecret>", "<tenantId>"); Response <DataSourceCredentialEntity> response = await adminClient.CreateDataSourceCredentialAsync(credentialEntity); DataSourceCredentialEntity createdCredentialEntity = response.Value; Console.WriteLine($"Credential entity ID: {createdCredentialEntity.Id}"); #endregion // Delete the created credential to clean up the Metrics Advisor resource. Do not perform this // step if you intend to keep using the credential. await adminClient.DeleteDataSourceCredentialAsync(createdCredentialEntity.Id); }
public async Task UpdateDetectionConfigurationAsync() { string endpoint = MetricsAdvisorUri; string subscriptionKey = MetricsAdvisorSubscriptionKey; string apiKey = MetricsAdvisorApiKey; var credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey); var adminClient = new MetricsAdvisorAdministrationClient(new Uri(endpoint), credential); string detectionConfigurationId = DetectionConfigurationId; Response <AnomalyDetectionConfiguration> response = await adminClient.GetDetectionConfigurationAsync(detectionConfigurationId); AnomalyDetectionConfiguration detectionConfiguration = response.Value; string originalDescription = detectionConfiguration.Description; detectionConfiguration.Description = "This description was generated by a sample."; response = await adminClient.UpdateDetectionConfigurationAsync(detectionConfiguration); AnomalyDetectionConfiguration updatedDetectionConfiguration = response.Value; Console.WriteLine($"Updated description: {updatedDetectionConfiguration.Description}"); // Undo the changes to leave the detection configuration unaltered. Skip this step if you intend to keep // the changes. detectionConfiguration.Description = originalDescription; await adminClient.UpdateDetectionConfigurationAsync(detectionConfiguration); }
public async Task GetAnomalyDimensionValuesAsync() { string endpoint = MetricsAdvisorUri; string subscriptionKey = MetricsAdvisorSubscriptionKey; string apiKey = MetricsAdvisorApiKey; var credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey); var client = new MetricsAdvisorClient(new Uri(endpoint), credential); string detectionConfigurationId = DetectionConfigurationId; string dimensionName = "city"; var startTime = DateTimeOffset.Parse("2020-01-01T00:00:00Z"); var endTime = DateTimeOffset.UtcNow; var options = new GetAnomalyDimensionValuesOptions(startTime, endTime) { MaxPageSize = 10 }; Console.WriteLine($"The dimension '{dimensionName}' assumed the following values on anomalous data points (limited to 10):"); int dimensionValueCount = 0; await foreach (string dimensionValue in client.GetAnomalyDimensionValuesAsync(detectionConfigurationId, dimensionName, options)) { Console.WriteLine($" {dimensionValue}"); // Print at most 10 values. if (++dimensionValueCount >= 10) { break; } } }
public async Task GetDataSourceCredentialsAsync() { string endpoint = MetricsAdvisorUri; string subscriptionKey = MetricsAdvisorSubscriptionKey; string apiKey = MetricsAdvisorApiKey; var credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey); var adminClient = new MetricsAdvisorAdministrationClient(new Uri(endpoint), credential); var options = new GetDataSourceCredentialsOptions() { MaxPageSize = 5 }; int credentialCount = 0; await foreach (DataSourceCredentialEntity credentialEntity in adminClient.GetDataSourceCredentialsAsync(options)) { Console.WriteLine($"Credential ID: {credentialEntity.Id}"); Console.WriteLine($"Name: {credentialEntity.Name}"); Console.WriteLine($"Description: {credentialEntity.Description}"); Console.WriteLine($"Kind: {credentialEntity.CredentialKind}"); Console.WriteLine(); // Print at most 5 credentials. if (++credentialCount >= 5) { break; } } }
public async Task AddFeedbackAsync() { string endpoint = MetricsAdvisorUri; string subscriptionKey = MetricsAdvisorSubscriptionKey; string apiKey = MetricsAdvisorApiKey; var credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey); var client = new MetricsAdvisorClient(new Uri(endpoint), credential); string metricId = MetricId; var dimensions = new Dictionary <string, string>() { { "region", "Karachi" } }; var dimensionKey = new DimensionKey(dimensions); var startsOn = DateTimeOffset.Parse("2020-02-01T00:00:00Z"); var endsOn = DateTimeOffset.Parse("2020-02-03T00:00:00Z"); // Other types of feedback, such as MetricCommentFeedback, MetricChangePointFeedback, // and MetricPeriodFeedback are supported as well. var anomalyFeedback = new MetricAnomalyFeedback(metricId, dimensionKey, startsOn, endsOn, AnomalyValue.NotAnomaly); Response <MetricFeedback> response = await client.AddFeedbackAsync(anomalyFeedback); MetricFeedback addedFeedback = response.Value; Console.WriteLine($"Feedback ID: {addedFeedback.Id}"); }
public async Task GetMetricEnrichmentStatusesAsync() { string endpoint = MetricsAdvisorUri; string subscriptionKey = MetricsAdvisorSubscriptionKey; string apiKey = MetricsAdvisorApiKey; var credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey); var client = new MetricsAdvisorClient(new Uri(endpoint), credential); string metricId = MetricId; var startTime = DateTimeOffset.Parse("2020-01-01T00:00:00Z"); var endTime = DateTimeOffset.UtcNow; var options = new GetMetricEnrichmentStatusesOptions(startTime, endTime) { MaxPageSize = 5 }; int statusCount = 0; await foreach (EnrichmentStatus enrichmentStatus in client.GetMetricEnrichmentStatusesAsync(metricId, options)) { Console.WriteLine($"Ingestion timestamp: {enrichmentStatus.Timestamp}"); Console.WriteLine($"Status: {enrichmentStatus.Status}"); Console.WriteLine($"Message: {enrichmentStatus.Message}"); Console.WriteLine(); // Print at most 5 entries. if (++statusCount >= 5) { break; } } }
public async Task MetricsAdvisorKeyCredentialSendsSecretInMetricsAdvisorClient() { MockResponse response = new MockResponse(200); response.SetContent("{}"); MockTransport mockTransport = new MockTransport(response); string expectedSubscriptionKey = "fakeSubscriptionKey"; string expectedApiKey = "fakeApiKey"; MetricsAdvisorKeyCredential credential = new MetricsAdvisorKeyCredential(expectedSubscriptionKey, expectedApiKey); MetricsAdvisorClient client = CreateInstrumentedClient(mockTransport, credential); IAsyncEnumerator <MetricFeedback> asyncEnumerator = client.GetAllFeedbackAsync(FakeGuid).GetAsyncEnumerator(); await asyncEnumerator.MoveNextAsync(); MockRequest request = mockTransport.Requests.First(); Assert.That(request.Headers.TryGetValue(Constants.SubscriptionAuthorizationHeader, out string subscriptionKey)); Assert.That(request.Headers.TryGetValue(Constants.ApiAuthorizationHeader, out string apiKey)); Assert.That(subscriptionKey, Is.EqualTo(expectedSubscriptionKey)); Assert.That(apiKey, Is.EqualTo(expectedApiKey)); }
public async Task AddFeedbackAsync() { string endpoint = MetricsAdvisorUri; string subscriptionKey = MetricsAdvisorSubscriptionKey; string apiKey = MetricsAdvisorApiKey; var credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey); var client = new MetricsAdvisorClient(new Uri(endpoint), credential); string metricId = MetricId; FeedbackDimensionFilter filter = new FeedbackDimensionFilter(); filter.DimensionFilter.AddDimensionColumn("city", "Belo Horizonte"); var startTime = DateTimeOffset.Parse("2020-02-01T00:00:00Z"); var endTime = DateTimeOffset.Parse("2020-02-03T00:00:00Z"); // Other types of feedback, such as MetricCommentFeedback, MetricChangePointFeedback, // and MetricPeriodFeedback are supported as well. var anomalyFeedback = new MetricAnomalyFeedback(metricId, filter, startTime, endTime, AnomalyValue.NotAnomaly); Response <MetricFeedback> response = await client.AddFeedbackAsync(anomalyFeedback); MetricFeedback addedFeedback = response.Value; Console.WriteLine($"Feedback ID: {addedFeedback.Id}"); }
public async Task GetMetricDimensionValuesAsync() { string endpoint = MetricsAdvisorUri; string subscriptionKey = MetricsAdvisorSubscriptionKey; string apiKey = MetricsAdvisorApiKey; var credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey); var client = new MetricsAdvisorClient(new Uri(endpoint), credential); string metricId = MetricId; string dimensionName = "city"; var options = new GetMetricDimensionValuesOptions() { MaxPageSize = 10 }; Console.WriteLine($"The dimension '{dimensionName}' can assume the following values (limited to 10):"); int dimensionValueCount = 0; await foreach (string dimensionValue in client.GetMetricDimensionValuesAsync(metricId, dimensionName, options)) { Console.WriteLine($" {dimensionValue}"); // Print at most 10 values. if (++dimensionValueCount >= 10) { break; } } }
public async Task UpdateAlertConfigurationAsync() { string endpoint = MetricsAdvisorUri; string subscriptionKey = MetricsAdvisorSubscriptionKey; string apiKey = MetricsAdvisorApiKey; var credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey); var adminClient = new MetricsAdvisorAdministrationClient(new Uri(endpoint), credential); string alertConfigurationId = AlertConfigurationId; Response <AnomalyAlertConfiguration> response = await adminClient.GetAlertConfigurationAsync(alertConfigurationId); AnomalyAlertConfiguration alertConfiguration = response.Value; string originalDescription = alertConfiguration.Description; alertConfiguration.Description = "This description was generated by a sample."; await adminClient.UpdateAlertConfigurationAsync(alertConfigurationId, alertConfiguration); // Undo the changes to leave the alert configuration unaltered. Skip this step if you intend to keep // the changes. alertConfiguration.Description = originalDescription; await adminClient.UpdateAlertConfigurationAsync(alertConfigurationId, alertConfiguration); }
public async Task GetDetectionConfigurationsAsync() { string endpoint = MetricsAdvisorUri; string subscriptionKey = MetricsAdvisorSubscriptionKey; string apiKey = MetricsAdvisorApiKey; var credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey); var adminClient = new MetricsAdvisorAdministrationClient(new Uri(endpoint), credential); string metricId = MetricId; int configCount = 0; await foreach (AnomalyDetectionConfiguration detectionConfiguration in adminClient.GetDetectionConfigurationsAsync(metricId)) { Console.WriteLine($"Detection configuration ID: {detectionConfiguration.Id}"); Console.WriteLine($"Name: {detectionConfiguration.Name}"); Console.WriteLine($"Description: {detectionConfiguration.Description}"); Console.WriteLine(); // Print at most 5 detection configurations. if (++configCount >= 5) { break; } } }
public async Task GetHooksAsync() { string endpoint = MetricsAdvisorUri; string subscriptionKey = MetricsAdvisorSubscriptionKey; string apiKey = MetricsAdvisorApiKey; var credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey); var adminClient = new MetricsAdvisorAdministrationClient(new Uri(endpoint), credential); var options = new GetHooksOptions() { MaxPageSize = 5 }; int hookCount = 0; await foreach (NotificationHook hook in adminClient.GetHooksAsync(options)) { Console.WriteLine($"Hook ID: {hook.Id}"); Console.WriteLine($"Name: {hook.Name}"); Console.WriteLine($"Description: {hook.Description}"); Console.WriteLine($"Type: {hook.HookType}"); Console.WriteLine(); // Print at most 5 hooks. if (++hookCount >= 5) { break; } } }
public async Task UpdateHookAsync() { string endpoint = MetricsAdvisorUri; string subscriptionKey = MetricsAdvisorSubscriptionKey; string apiKey = MetricsAdvisorApiKey; var credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey); var adminClient = new MetricsAdvisorAdministrationClient(new Uri(endpoint), credential); string hookId = HookId; Response <NotificationHook> response = await adminClient.GetHookAsync(hookId); NotificationHook hook = response.Value; string originalDescription = hook.Description; hook.Description = "This description was generated by a sample."; response = await adminClient.UpdateHookAsync(hook); NotificationHook updatedHook = response.Value; Console.WriteLine($"Updated description: {updatedHook.Description}"); // Undo the changes to leave the hook unaltered. Skip this step if you intend to keep // the changes. hook.Description = originalDescription; await adminClient.UpdateHookAsync(hook); }
public async Task GetAllFeedbackAsync() { string endpoint = MetricsAdvisorUri; string subscriptionKey = MetricsAdvisorSubscriptionKey; string apiKey = MetricsAdvisorApiKey; var credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey); var client = new MetricsAdvisorClient(new Uri(endpoint), credential); string metricId = MetricId; var options = new GetAllFeedbackOptions() { StartTime = DateTimeOffset.Parse("2020-01-01T00:00:00Z"), EndTime = DateTimeOffset.Parse("2020-09-09T00:00:00Z"), TimeMode = FeedbackQueryTimeMode.MetricTimestamp, MaxPageSize = 5 }; int feedbackCount = 0; await foreach (MetricFeedback feedback in client.GetAllFeedbackAsync(metricId, options)) { Console.WriteLine($"Feedback ID: {feedback.Id}"); Console.WriteLine($"Metric ID: {feedback.MetricId}"); Console.WriteLine($"Feedback type: {feedback.Type}"); Console.WriteLine(); // Print at most 5 feedback entries. if (++feedbackCount >= 5) { break; } } }
public void ConstructorAllowsNullOptions() { var endpoint = new Uri("http://notreal.azure.com"); var credential = new MetricsAdvisorKeyCredential("fakeSubscriptionKey", "fakeApiKey"); Assert.That(() => new MetricsAdvisorClient(endpoint, credential, null), Throws.Nothing); }
private MetricsAdvisorAdministrationClient GetMetricsAdvisorAdministrationClient() { var fakeEndpoint = new Uri("http://notreal.azure.com"); var fakeCredential = new MetricsAdvisorKeyCredential("fakeSubscriptionKey", "fakeApiKey"); return(new MetricsAdvisorAdministrationClient(fakeEndpoint, fakeCredential)); }
public async Task CreateAndDeleteHookAsync() { string endpoint = MetricsAdvisorUri; string subscriptionKey = MetricsAdvisorSubscriptionKey; string apiKey = MetricsAdvisorApiKey; var credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey); var adminClient = new MetricsAdvisorAdministrationClient(new Uri(endpoint), credential); #region Snippet:CreateHookAsync string hookName = "Sample hook"; var emailHook = new EmailNotificationHook() { Name = hookName }; emailHook.EmailsToAlert.Add("*****@*****.**"); emailHook.EmailsToAlert.Add("*****@*****.**"); Response <NotificationHook> response = await adminClient.CreateHookAsync(emailHook); NotificationHook createdHook = response.Value; Console.WriteLine($"Hook ID: {createdHook.Id}"); #endregion // Delete the created hook to clean up the Metrics Advisor resource. Do not perform this // step if you intend to keep using the hook. await adminClient.DeleteHookAsync(createdHook.Id); }
public async Task GetIncidentsForDetectionConfigurationAsync() { string endpoint = MetricsAdvisorUri; string subscriptionKey = MetricsAdvisorSubscriptionKey; string apiKey = MetricsAdvisorApiKey; var credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey); var client = new MetricsAdvisorClient(new Uri(endpoint), credential); string detectionConfigurationId = DetectionConfigurationId; // Only incidents from time series that are part of one of the groups specified // will be returned. var groupKey1 = new DimensionKey(); groupKey1.AddDimensionColumn("city", "Bengaluru"); var groupKey2 = new DimensionKey(); groupKey2.AddDimensionColumn("city", "Hong Kong"); groupKey2.AddDimensionColumn("category", "Industrial & Scientific"); var startTime = DateTimeOffset.Parse("2020-01-01T00:00:00Z"); var endTime = DateTimeOffset.UtcNow; var options = new GetIncidentsForDetectionConfigurationOptions(startTime, endTime) { DimensionsToFilter = new List <DimensionKey>() { groupKey1, groupKey2 }, TopCount = 3 }; int incidentCount = 0; await foreach (AnomalyIncident incident in client.GetIncidentsForDetectionConfigurationAsync(detectionConfigurationId, options)) { Console.WriteLine($"Incident ID: {incident.Id}"); Console.WriteLine($"First associated anomaly occurred at: {incident.StartTime}"); Console.WriteLine($"Last associated anomaly occurred at: {incident.LastTime}"); Console.WriteLine($"Status: {incident.Status}"); Console.WriteLine($"Severity: {incident.Severity}"); Console.WriteLine("Series key:"); foreach (KeyValuePair <string, string> keyValuePair in incident.DimensionKey.AsDictionary()) { Console.WriteLine($" Dimension '{keyValuePair.Key}': {keyValuePair.Value}"); } Console.WriteLine(); // Print at most 3 incidents. if (++incidentCount >= 3) { break; } } }
public async Task GetMetricSeriesDataAsync() { string endpoint = MetricsAdvisorUri; string subscriptionKey = MetricsAdvisorSubscriptionKey; string apiKey = MetricsAdvisorApiKey; var credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey); var client = new MetricsAdvisorClient(new Uri(endpoint), credential); string metricId = MetricId; var startsOn = DateTimeOffset.Parse("2020-01-01T00:00:00Z"); var endsOn = DateTimeOffset.UtcNow; var options = new GetMetricSeriesDataOptions(startsOn, endsOn); // Only the two time series with the keys specified below will be returned. var dimensions = new Dictionary <string, string>() { { "Dim1", "JPN" }, { "Dim2", "__SUM__" } }; var seriesKey1 = new DimensionKey(dimensions); dimensions = new Dictionary <string, string>() { { "Dim1", "USD" }, { "Dim2", "US" } }; var seriesKey2 = new DimensionKey(dimensions); options.SeriesKeys.Add(seriesKey1); options.SeriesKeys.Add(seriesKey2); await foreach (MetricSeriesData seriesData in client.GetMetricSeriesDataAsync(metricId, options)) { Console.WriteLine($"Time series metric ID: {seriesData.MetricId}"); Console.WriteLine("Time series key:"); foreach (KeyValuePair <string, string> keyValuePair in seriesData.SeriesKey) { Console.WriteLine($" Dimension '{keyValuePair.Key}': {keyValuePair.Value}"); } Console.WriteLine("Data points:"); // Print at most 3 points per time series. int totalPoints = seriesData.Timestamps.Count < 3 ? seriesData.Timestamps.Count : 3; for (int pointIndex = 0; pointIndex < totalPoints; pointIndex++) { Console.WriteLine($" Point {pointIndex}:"); Console.WriteLine($" - Timestamp: {seriesData.Timestamps[pointIndex]}"); Console.WriteLine($" - Metric value: {seriesData.MetricValues[pointIndex]}"); } Console.WriteLine(); } }
public async Task GetAnomaliesForAlertAsync() { string endpoint = MetricsAdvisorUri; string subscriptionKey = MetricsAdvisorSubscriptionKey; string apiKey = MetricsAdvisorApiKey; var credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey); var client = new MetricsAdvisorClient(new Uri(endpoint), credential); #region Snippet:GetAnomaliesForAlertAsync #if SNIPPET string alertConfigurationId = "<alertConfigurationId>"; string alertId = "<alertId>"; #else string alertConfigurationId = AlertConfigurationId; string alertId = AlertId; #endif var options = new GetAnomaliesForAlertOptions() { MaxPageSize = 3 }; int anomalyCount = 0; await foreach (DataPointAnomaly anomaly in client.GetAnomaliesAsync(alertConfigurationId, alertId, options)) { Console.WriteLine($"Anomaly detection configuration ID: {anomaly.DetectionConfigurationId}"); Console.WriteLine($"Data feed ID: {anomaly.DataFeedId}"); Console.WriteLine($"Metric ID: {anomaly.MetricId}"); Console.WriteLine($"Anomaly value: {anomaly.Value}"); if (anomaly.ExpectedValue.HasValue) { Console.WriteLine($"Anomaly expected value: {anomaly.ExpectedValue}"); } Console.WriteLine($"Anomaly at timestamp: {anomaly.Timestamp}"); Console.WriteLine($"Anomaly detected at: {anomaly.CreatedTime}"); Console.WriteLine($"Status: {anomaly.Status}"); Console.WriteLine($"Severity: {anomaly.Severity}"); Console.WriteLine("Series key:"); foreach (KeyValuePair <string, string> keyValuePair in anomaly.SeriesKey.AsDictionary()) { Console.WriteLine($" Dimension '{keyValuePair.Key}': {keyValuePair.Value}"); } Console.WriteLine(); // Print at most 3 anomalies. if (++anomalyCount >= 3) { break; } } #endregion }
public async Task GetMetricEnrichedSeriesDataAsync() { string endpoint = MetricsAdvisorUri; string subscriptionKey = MetricsAdvisorSubscriptionKey; string apiKey = MetricsAdvisorApiKey; var credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey); var client = new MetricsAdvisorClient(new Uri(endpoint), credential); string detectionConfigurationId = DetectionConfigurationId; // Only the two time series with the keys specified below will be returned. var seriesKey1 = new DimensionKey(); seriesKey1.AddDimensionColumn("city", "Belo Horizonte"); seriesKey1.AddDimensionColumn("category", "__SUM__"); var seriesKey2 = new DimensionKey(); seriesKey2.AddDimensionColumn("city", "Hong Kong"); seriesKey2.AddDimensionColumn("category", "Industrial & Scientific"); var seriesKeys = new List <DimensionKey>() { seriesKey1, seriesKey2 }; var startTime = DateTimeOffset.Parse("2020-01-01T00:00:00Z"); var endTime = DateTimeOffset.UtcNow; await foreach (MetricEnrichedSeriesData seriesData in client.GetMetricEnrichedSeriesDataAsync(seriesKeys, detectionConfigurationId, startTime, endTime)) { Console.WriteLine("Time series key:"); foreach (KeyValuePair <string, string> keyValuePair in seriesData.SeriesKey.AsDictionary()) { Console.WriteLine($" Dimension '{keyValuePair.Key}': {keyValuePair.Value}"); } Console.WriteLine("Data points:"); // Print at most 2 points per time series. for (int pointIndex = 0; pointIndex < 2; pointIndex++) { Console.WriteLine($" Point {pointIndex}:"); Console.WriteLine($" - Timestamp: {seriesData.Timestamps[pointIndex]}"); Console.WriteLine($" - Metric value: {seriesData.MetricValues[pointIndex]}"); Console.WriteLine($" - Expected metric value: {seriesData.ExpectedMetricValues[pointIndex]}"); Console.WriteLine($" - Lower boundary: {seriesData.LowerBoundaryValues[pointIndex]}"); Console.WriteLine($" - Upper boundary: {seriesData.UpperBoundaryValues[pointIndex]}"); Console.WriteLine($" - Is this point an anomaly: {seriesData.IsAnomaly[pointIndex]}"); Console.WriteLine($" - Period: {seriesData.Periods[pointIndex]}"); } Console.WriteLine(); } }
public MetricsAdvisorTest(TOptions options) : base(options) { TestEnvironment = PerfTestEnvironment.Instance; var uri = new Uri(TestEnvironment.MetricsAdvisorUri); var credential = new MetricsAdvisorKeyCredential(TestEnvironment.MetricsAdvisorSubscriptionKey, TestEnvironment.MetricsAdvisorApiKey); Client = new MetricsAdvisorClient(uri, credential); }
public async Task CreateAndDeleteDataFeedAsync() { string endpoint = MetricsAdvisorUri; string subscriptionKey = MetricsAdvisorSubscriptionKey; string apiKey = MetricsAdvisorApiKey; var credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey); var adminClient = new MetricsAdvisorAdministrationClient(new Uri(endpoint), credential); string sqlServerConnectionString = SqlServerConnectionString; string sqlServerQuery = SqlServerQuery; #region Snippet:CreateDataFeedAsync //@@ string sqlServerConnectionString = "<connectionString>"; //@@ string sqlServerQuery = "<query>"; var dataFeedName = "Sample data feed"; var dataFeedSource = new SqlServerDataFeedSource(sqlServerConnectionString, sqlServerQuery); var dataFeedGranularity = new DataFeedGranularity(DataFeedGranularityType.Daily); var dataFeedMetrics = new List <DataFeedMetric>() { new DataFeedMetric("cost"), new DataFeedMetric("revenue") }; var dataFeedDimensions = new List <DataFeedDimension>() { new DataFeedDimension("category"), new DataFeedDimension("city") }; var dataFeedSchema = new DataFeedSchema(dataFeedMetrics) { DimensionColumns = dataFeedDimensions }; var ingestionStartTime = DateTimeOffset.Parse("2020-01-01T00:00:00Z"); var dataFeedIngestionSettings = new DataFeedIngestionSettings(ingestionStartTime); var dataFeed = new DataFeed(dataFeedName, dataFeedSource, dataFeedGranularity, dataFeedSchema, dataFeedIngestionSettings); Response <string> response = await adminClient.CreateDataFeedAsync(dataFeed); string dataFeedId = response.Value; Console.WriteLine($"Data feed ID: {dataFeedId}"); #endregion // Only the ID of the data feed is known at this point. You can perform another service // call to GetDataFeedAsync or GetDataFeed to get more information, such as status, created // time, the list of administrators, or the metric IDs. // Delete the created data feed to clean up the Metrics Advisor resource. Do not perform this // step if you intend to keep using the data feed. await adminClient.DeleteDataFeedAsync(dataFeedId); }
public async Task GetMetricSeriesDataAsync() { string endpoint = MetricsAdvisorUri; string subscriptionKey = MetricsAdvisorSubscriptionKey; string apiKey = MetricsAdvisorApiKey; var credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey); var client = new MetricsAdvisorClient(new Uri(endpoint), credential); string metricId = MetricId; // Only the two time series with the keys specified below will be returned. var seriesKey1 = new DimensionKey(); seriesKey1.AddDimensionColumn("city", "Belo Horizonte"); seriesKey1.AddDimensionColumn("category", "__SUM__"); var seriesKey2 = new DimensionKey(); seriesKey2.AddDimensionColumn("city", "Hong Kong"); seriesKey2.AddDimensionColumn("category", "Industrial & Scientific"); var filter = new List <DimensionKey>() { seriesKey1, seriesKey2 }; var startTime = DateTimeOffset.Parse("2020-01-01T00:00:00Z"); var endTime = DateTimeOffset.UtcNow; var options = new GetMetricSeriesDataOptions(filter, startTime, endTime); await foreach (MetricSeriesData seriesData in client.GetMetricSeriesDataAsync(metricId, options)) { Console.WriteLine($"Time series metric ID: {seriesData.Definition.MetricId}"); Console.WriteLine("Time series key:"); foreach (KeyValuePair <string, string> keyValuePair in seriesData.Definition.SeriesKey.AsDictionary()) { Console.WriteLine($" Dimension '{keyValuePair.Key}': {keyValuePair.Value}"); } Console.WriteLine("Data points:"); // Print at most 3 points per time series. for (int pointIndex = 0; pointIndex < 3; pointIndex++) { Console.WriteLine($" Point {pointIndex}:"); Console.WriteLine($" - Timestamp: {seriesData.Timestamps[pointIndex]}"); Console.WriteLine($" - Value: {seriesData.Values[pointIndex]}"); } Console.WriteLine(); } }
public void ConstructorValidatesArguments() { var endpoint = new Uri("http://notreal.azure.com"); var credential = new MetricsAdvisorKeyCredential("fakeSubscriptionKey", "fakeApiKey"); var options = new MetricsAdvisorClientsOptions(); Assert.That(() => new MetricsAdvisorClient(null, credential), Throws.InstanceOf <ArgumentNullException>()); Assert.That(() => new MetricsAdvisorClient(endpoint, null), Throws.InstanceOf <ArgumentNullException>()); Assert.That(() => new MetricsAdvisorClient(null, credential, options), Throws.InstanceOf <ArgumentNullException>()); Assert.That(() => new MetricsAdvisorClient(endpoint, null, options), Throws.InstanceOf <ArgumentNullException>()); }
public MetricsAdvisorAdministrationClient CreateInstrumentedAdministrationClient(MockTransport transport) { var fakeEndpoint = new Uri("http://notreal.azure.com"); var fakeCredential = new MetricsAdvisorKeyCredential("fakeSubscriptionKey", "fakeApiKey"); var options = new MetricsAdvisorClientsOptions() { Transport = transport }; return(InstrumentClient(new MetricsAdvisorAdministrationClient(fakeEndpoint, fakeCredential, options))); }
public async Task GetIncidentsForAlertAsync() { string endpoint = MetricsAdvisorUri; string subscriptionKey = MetricsAdvisorSubscriptionKey; string apiKey = MetricsAdvisorApiKey; var credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey); var client = new MetricsAdvisorClient(new Uri(endpoint), credential); string alertConfigurationId = AlertConfigurationId; string alertId = AlertId; var options = new GetIncidentsForAlertOptions() { MaxPageSize = 3 }; int incidentCount = 0; await foreach (AnomalyIncident incident in client.GetIncidentsForAlertAsync(alertConfigurationId, alertId, options)) { Console.WriteLine($"Incident ID: {incident.Id}"); Console.WriteLine($"Data feed ID: {incident.DataFeedId}"); Console.WriteLine($"Metric ID: {incident.MetricId}"); Console.WriteLine($"Detection configuration ID: {incident.DetectionConfigurationId}"); Console.WriteLine($"First associated anomaly occurred at: {incident.StartTime}"); Console.WriteLine($"Last associated anomaly occurred at: {incident.LastTime}"); Console.WriteLine($"Status: {incident.Status}"); Console.WriteLine($"Severity: {incident.Severity}"); Console.WriteLine($"Value of root node anomaly: {incident.ValueOfRootNode}"); if (incident.ExpectedValueOfRootNode.HasValue) { Console.WriteLine($"Expected value of root node anomaly: {incident.ExpectedValueOfRootNode}"); } Console.WriteLine("Series key of root node:"); foreach (KeyValuePair <string, string> keyValuePair in incident.RootDimensionKey.AsDictionary()) { Console.WriteLine($" Dimension '{keyValuePair.Key}': {keyValuePair.Value}"); } Console.WriteLine(); // Print at most 3 incidents. if (++incidentCount >= 3) { break; } } }