Forum Discussion
KQL question
AzureActivity | summarize LastActivity = max(TimeGenerated) by ResourceProvider, ResourceGroup | join kind = innerunique( AzureActivity | summarize Operations = count() by ResourceGroup, ResourceProvider) on ResourceGroup, ResourceProvider |project ResourceProvider, ResourceGroup, Operations, LastActivity |sort by Operations
The above KQL is used to print 4 columns
I need to print the fifth column as well that highlights the percentage of operations per Resource Group and Resource provider.
There have to 5 columns in the result
Resource Provider, Resource Group,Number of Operations (Activities), Last activity time, Percentage
Can someone help me with this?
16 Replies
- hspinto
Microsoft
there may be a better solution, but this approach should work:
let TotalOperations = todouble(toscalar(AzureActivity | summarize count()));
AzureActivity| summarize LastActivity = max(TimeGenerated), Operations = count() by ResourceProvider, ResourceGroup| extend Percentage = round(todouble(Operations) / TotalOperations * 100, 1)| project ResourceProvider, ResourceGroup, Operations, Percentage, LastActivity| sort by Operations- uditk14Copper Contributor
hspinto - Thanks a lot
I have one more query with the exteraldata operator
I have used externaldata operator to fetch data from a CSV having a few columns namely, IP ranges, country code, country name, continent name etc.
In Azure Activity table there is a CallerIP value.
I need to print the location for each caller Ip.
CSV file - https://datahub.io/core/geoip2-ipv4#premium-data-2
hspinto Can you help me with the KQL
- hspinto
Microsoft
something like this would respond to your needs. However, due to a restriction of user-defined functions, you cannot call functions sending parameters that depend on row-context.
let GeoData = externaldata (network:string,geoname_id:string,continent_code:string,continent_name:string,country_iso_code:string,country_name:string,is_anonymous_proxy:bool,is_satellite_provider:bool) [ @"https://datahub.io/core/geoip2-ipv4/r/geoip2-ipv4.csv" ] with(format="csv", ignoreFirstRecord=true); let GetCountryName = (CallerIp:string) { toscalar( GeoData | extend AddressMask = split(network,'/')[1] | where ipv4_compare(CallerIp, tostring(split(network,'/')[0]), toint(tostring(split(network,'/')[1]))) == 0 | project country_name ) }; //this works, because the parameter is hardcoded //print GetCountryName('94.45.78.16') // this will fail with a "Unresolved reference binding" error AzureActivity | extend CountryName = GetCountryName(CallerIpAddress)
Deleted, do you have a solution for this one?