Percentage of Arc Machines by Domain

Frequent Visitor

I am trying to use Azure Resource Graph to get 3 columns of data: 

  • List of Domain names
  • Count of Arc Machines by Domain
  • Percentage of Arc Machines by Domain

 

resources

where type == "microsoft.hybridcompute/machines"
extend Domain=properties.domainName,ArcMachines=name
summarize TotalResources=count()
summarize MachinesByDomain=count(ArcMachines) by tostring(Domain)
summarize Percentage = ( toreal(sum(MachinesByDomain)) / toreal(sum(TotalResources)) ) * 100
project Domain,MachinesByDomain,Percentage
 
 
This is the result I am getting:
"Please provide below info when asking for support: timestamp = 2021-07-26T14:38:35.7800277Z, correlationId = d2b015fa-2584-4f11-99c4-eb0e4f1a5096. (Code:BadRequest)
 
Details: Query is invalid. Please refer to the documentation for the Azure Resource Graph service and fix the error before retrying. (Code:InvalidQuery) 'summarize' operator: Failed to resolve scalar expression named 'TotalResources' (Code:Operator_FailedToResolveEntity)"
 
Please let me know if you have any suggestions to achieve the results I am looking for. Thank you!
1 Reply

@Josh_Washburn 

 

One way to do this is to use a join 

// get the Total count, store it and create a column to join on
resources
| where type == "microsoft.hybridcompute/machines"
| summarize Total_ = dcount(name), fake_join = "join_" 
// Join data on the fake column name = left
| join  //right
(
	resources
	| where type == "microsoft.hybridcompute/machines"
	| extend Domain=properties.domainName,ArcMachines=name
	| summarize MachinesByDomain=count(ArcMachines)  by tostring(Domain), ArcMachines, fake_join ="join_"
) on fake_join
// now calculate the Total from left with the data from the right  
| summarize MachinesByDomain=count(ArcMachines), Percentage = ( toreal(sum(MachinesByDomain)) / toreal(max(Total_)) * 100 ) by tostring(Domain)
| order by MachinesByDomain desc

 

Screenshot 2021-07-27 102156.png