Dhr*_*shi 5 azure-monitoring azure-data-factory azure-log-analytics
我有一些数据工厂管道,当将数据从 blob 复制到 SQL 时,有时可能会运行超过 2 小时。时间段是可变的,但我希望在任何管道运行超过 2 小时时收到通知/警报。
有哪些可能的方法可以做到这一点?
到目前为止我已经尝试过:
我们这样做是为了跟踪正在运行的管道并管理执行并发性。我发现逻辑应用和 Azure Functions 是创建此类解决方案的绝佳工具。以下是我们如何处理此问题的粗略概述:
您可以执行与此类似的操作,并使用“DurationInMS”根据状态 =“InProgress”和总运行时间 > {所需警报阈值}生成适当的操作。
这是我使用的 DataFactoryHelper 类:
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using Microsoft.Rest;
using Microsoft.Azure.Management.ResourceManager;
using Microsoft.Azure.Management.DataFactory;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace AzureUtilities.DataFactory
{
public class DataFactoryHelper
{
private ClientCredential Credentials { get; set; }
private string KeyVaultUrl { get; set; }
private string TenantId { get; set; }
private string SubscriptionId { get; set; }
private DataFactoryManagementClient _client = null;
private DataFactoryManagementClient Client
{
get {
if (_client == null)
{
var context = new AuthenticationContext("https://login.windows.net/" + TenantId);
AuthenticationResult result = context.AcquireTokenAsync("https://management.azure.com/", Credentials).Result;
ServiceClientCredentials cred = new TokenCredentials(result.AccessToken);
_client = new DataFactoryManagementClient(cred) { SubscriptionId = SubscriptionId };
}
return _client;
}
}
public DataFactoryHelper(string servicePrincipalId, string servicePrincipalKey, string tenantId, string subscriptionId)
{
Credentials = new ClientCredential(servicePrincipalId, servicePrincipalKey);
TenantId = tenantId;
SubscriptionId = subscriptionId;
}
public async Task<string> RunPipelineAsync(string resourceGroupName,
string dataFactoryName,
string pipelineName,
Dictionary<string, object> parameters = null,
Dictionary<string, List<string>> customHeaders = null)
{
var runResponse = await Client.Pipelines.CreateRunWithHttpMessagesAsync(resourceGroupName, dataFactoryName, pipelineName, parameters: parameters , customHeaders: customHeaders);
return runResponse.Body.RunId;
}
public async Task<object> GetPipelineInfoAsync(string resourceGroup, string dataFactory, string runId)
{
var info = await Client.PipelineRuns.GetAsync(resourceGroup, dataFactory, runId);
return new
{
RunId = info.RunId,
PipelineName = info.PipelineName,
InvokedBy = info.InvokedBy.Name,
LastUpdated = info.LastUpdated,
RunStart = info.RunStart,
RunEnd = info.RunEnd,
DurationInMs = info.DurationInMs,
Status = info.Status,
Message = info.Message
};
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3297 次 |
| 最近记录: |