以编程方式获取 ADF 管道消耗报告

Eve*_*ela 3 azure cost-management azure-data-factory

我有兴趣查询数据工厂监视器中提供的管道消耗报告。Log Analytics 或 PowerShell cmdlet 上是否有一个表可以返回此信息?我检查了 ADFv2 PowerShell 模块,但找不到任何模块。我的目标是汇总本报告中提供的信息,以确定哪些是成本最高的管道。

在此输入图像描述

参考: https: //techcommunity.microsoft.com/t5/azure-data-factory/new-adf-pipeline-conspiration-report/ba-p/1394671

谢谢

Eve*_*ela 5

进行更多研究后,有人向我指出了一个 GitHub 页面,其中产品团队发布了一个 PowerShell 脚本来查找我正在寻找的部分内容 {1}。所以我对脚本做了一些修改以获得我需要的输出。通过下面的输出,我可以从 MS 计算器中提取值,以获得每次管道运行的估计成本。{2}

$startTime = "21/6/2021 7:00:00"
$endTime = "21/6/2021 10:00:00"
$adf = '<data factory name>'
$rg = '<resrouce group name>'
    

$outputObj = @()
$pipelineRuns = Get-AzDataFactoryV2PipelineRun -ResourceGroupName $rg -DataFactoryName $adf -LastUpdatedAfter $startTime -LastUpdatedBefore $endTime

# loop through all pipelines and child activities to return billable information
foreach ($pipelineRun in $pipelineRuns) {
    $activtiyRuns = Get-AzDataFactoryV2ActivityRun -ResourceGroupName $rg -DataFactoryName $adf -pipelineRunId $pipelineRun.RunId -RunStartedAfter $startTime -RunStartedBefore $endTime

    foreach ($activtiyRun in $activtiyRuns) {
        if ($null -ne $activtiyRun.Output -and $null -ne $activtiyRun.Output.SelectToken("billingReference.billableDuration")) {            
            
            $obj = @()
            $obj = $activtiyRun.Output.SelectToken("billingReference.billableDuration").ToString() | ConvertFrom-Json
            $obj | Add-Member -MemberType NoteProperty -Name activityType -value $activtiyRun.Output.SelectToken("billingReference.activityType").ToString()
            $obj | Add-Member -MemberType NoteProperty -Name pipelineName -value $pipelineRun.PipelineName
            $obj | Add-Member -MemberType NoteProperty -Name activtiyRuns -value $activtiyRuns.Count             

            $outputObj += $obj
        }
        else {}
    }
}

# output aggregated result set as table
$groupedObj = $outputObj | Group-Object -Property pipelineName, activityType, meterType
$groupedObj | ForEach-Object {
    $value = $_.name -split ', '
    New-Object psobject -Property @{ 
                               
        activityType              = $value[1];
        meterType                 = $value[2];
        pipelineName              = $value[0];
        executionHours            = [math]::Round(($_.Group | Measure-object -Property duration -sum).Sum, 4)
        orchestrationActivityRuns = $groupedObj.group.activtiyRuns[0]
    } 
} | Sort-Object -Property meterType | Format-Table
Run Code Online (Sandbox Code Playgroud)

输出样本:

在此输入图像描述

来自数据工厂监视器的消耗报告

在此输入图像描述

参考:

  1. https://github.com/Azure/Azure-DataFactory/tree/main/SamplesV2/PastRunDetails#simple-script-that-prints--activity-level-run-details-in-45-day-range {1}
  2. https://azure.microsoft.com/en-us/pricing/calculator/?service=data-factory%2F {2}