我正在创建一个Azure工作簿,该工作簿将显示所有设置为GRS的存储帐户,然后显示这些存储帐户迄今为止的每月成本。第一位在KQL查询返回正确结果的情况下工作正常,即设置为GRS的存储帐户。我只是不知道如何创建第二个查询或json脚本来显示第一个查询结果的成本数据。
运行良好的第一个查询如下所示(此查询返回所有存储帐户的列表):
`resources
| where type == "microsoft.storage/storageaccounts"
| where resourceGroup has "dev" or resourceGroup has "test" or resourceGroup has "train" or resourceGroup has "uat"
| where sku has "GRS"
| extend skuName=tostring(sku.name)
| extend accountType=case(skuName =~ 'Standard_LRS', 'Standard HDD LRS',
skuName =~ 'StandardSSD_LRS', 'Standard SSD LRS',
skuName =~ 'UltraSSD_LRS', 'Ultra disk LRS',
skuName =~ 'Premium_LRS', 'Premium SSD LRS',
skuName =~ 'Standard_ZRS', 'Zone-redundant',
skuName =~ 'Premium_ZRS', 'Premium SSD ZRS',
skuName =~ 'StandardSSD_ZRS', 'Standard SSD ZRS',
skuName)
| extend securityTypeString=tostring(properties.securityProfile.securityType)
| extend securityType=case(securityTypeString =~ 'Standard', 'Standard',
securityTypeString =~ 'TrustedLaunch', 'Trusted launch',
securityTypeString startswith 'ConfidentialVm', 'Confidential',
securityTypeString == '', '-',
'-')
| extend architecture=iff(tostring(properties.supportedCapabilities.architecture) =~ 'Arm64', 'Arm64', 'x64')
| extend timeCreated=tostring(properties.creationTime)
| extend size=tostring(properties.diskSizeGB)
| extend iops=strcat(tostring(properties.diskIOPSReadWrite), '/', tostring(properties.diskMBpsReadWrite))
| extend owner=coalesce(split(managedBy, '/')[(-1)], '-')
| extend diskStateProperty=tostring(properties.provisioningState)
| extend diskState=case(diskStateProperty =~ 'Succeeded', 'Attached',
diskStateProperty =~ 'Creating', 'Creating',
diskStateProperty =~ 'Resolving', 'Resolving',
diskStateProperty =~ 'Updating', 'Updating',
diskStateProperty =~ 'Deleting', 'Deleting',
diskStateProperty =~ 'Failed', 'Failed',
diskStateProperty =~ 'Canceled', 'Canceled',
diskStateProperty == '', '-',
coalesce(diskStateProperty, '-'))
| extend osType=coalesce(properties.osType, '-')
| extend provisioningState=coalesce(properties.provisioningState, '-')
| extend sourceId=tostring(coalesce(properties.creationData.imageReference.id, properties.creationData.sourceUri, properties.creationData.sourceResourceId))
| parse kind=regex sourceId with '/Publishers/' publisher '/ArtifactTypes/(.*)/Offers/' offer '/Skus/' sku '/Versions/' version
| extend createOption=tostring(properties.creationData.createOption)
| extend source=case(createOption =~ 'empty', '-',
createOption =~ 'copy', split(sourceId, '/')[(-1)],
createOption =~ 'import', sourceId,
createOption =~ 'FromImage', strcat(publisher, ' / ', offer, ' / ', sku, ' / ', version),
'-')
| extend shareCapacity = iff(properties.shareCapacityInBytes > 0, strcat(tostring(properties.shareCapacityInBytes), ' GiB'), 'N/A')
| project
name,
resourceGroup,
location,
kind,
accountType
`
请指导我应该写的第二个查询或JSON脚本,显示第一个查询结果的成本数据。非常感谢您的评分
我试着从其他地方复制这个JSON脚本,我知道这不会起作用,但可能是一个起点:
`{
"type": "Usage",
"timeframe": "MonthToDate",
"dataset": {
"granularity": "Monthly",
"aggregation": {
"totalCost": {
"name": "PreTaxCost",
"function": "Sum"
}
},
"filter": {
"and": [
{
"dimensions": {
"name": "ResourceGroup",
"operator": "In",
"values": [
"StorageAccounts"
]
}
},
{
"dimensions": {
"name": "ServiceName",
"operator": "In",
"values": [
"Geo-Replicated Storage"
]
}
}
]
},
"grouping": [
{
"type": "Dimension",
"name": "ResourceGroup"
},
{
"type": "Dimension",
"name": "ResourceId"
}
]
}
}
`
1条答案
按热度按时间62lalag41#
一般来说,你可能需要做两个查询,然后第三个查询使用
Merge
连接器来连接它们。1.查询1:可能是Azure Resource Graph来查找相应的资源?
1.查询2:可能是ARM = ARM,到成本管理API获取适当的详细信息,使用JSONPath过滤结果,只找到您想要/需要的资源类型数据