Forum Discussion
Hairy_Zeus
Jul 28, 2021Copper Contributor
Assistance with Log Analytics Disk Query
Good Morning all, I'm hoping to get some help with log analytics, I'm trying to write a simple query that returns the percentage of used disk space for both Windows and Linux VMs. For Linux V...
- Jul 29, 2021
Maybe this?
Perf //| where Computer !startswith "A" //or Computer startswith "J" //testing | where TimeGenerated > startofday(ago(1d)) | where CounterName in ( "% Free Space" , "% Used Space", "Free Megabytes") | where InstanceName !contains 'Harddisk' and InstanceName != '_Total' | summarize PctFree=avgif(CounterValue, CounterName == "% Free Space" ), Linux =avgif(CounterValue, CounterName == "% Used Space"), MbFree =avgif(CounterValue, CounterName == "Free Megabytes"), arg_max(TimeGenerated, Computer) by Computer, InstanceName | extend PctFree = iif(isnan(PctFree),Linux,PctFree) | project-away Linux, Computer1 | project TotalSizeGB=round(MbFree*100/PctFree/1024,0), round(PctFree,2), round(MbFree,2), Computer, InstanceName | summarize FreePCT=avg(PctFree) by Computer, InstanceName, TotalSizeGB, FreeGB = round(MbFree / 1024,2) | sort by Computer asc, InstanceName asc | project Computer, InstanceName, TotalSizeGB, FreeGB, GBinUse = TotalSizeGB - FreeGB, FreePCT
CliveWatson
Microsoft
Maybe this?
Perf
//| where Computer !startswith "A" //or Computer startswith "J" //testing
| where TimeGenerated > startofday(ago(1d))
| where CounterName in ( "% Free Space" , "% Used Space", "Free Megabytes")
| where InstanceName !contains 'Harddisk' and InstanceName != '_Total'
| summarize PctFree=avgif(CounterValue, CounterName == "% Free Space" ),
Linux =avgif(CounterValue, CounterName == "% Used Space"),
MbFree =avgif(CounterValue, CounterName == "Free Megabytes"),
arg_max(TimeGenerated, Computer) by Computer, InstanceName
| extend PctFree = iif(isnan(PctFree),Linux,PctFree)
| project-away Linux, Computer1
| project TotalSizeGB=round(MbFree*100/PctFree/1024,0),
round(PctFree,2),
round(MbFree,2),
Computer,
InstanceName
| summarize FreePCT=avg(PctFree) by Computer,
InstanceName,
TotalSizeGB,
FreeGB = round(MbFree / 1024,2)
| sort by Computer asc, InstanceName asc
| project Computer, InstanceName, TotalSizeGB, FreeGB, GBinUse = TotalSizeGB - FreeGB, FreePCT
Hairy_Zeus
Jul 29, 2021Copper Contributor
This is exactly what I was looking for, you're a life saver. Thank you very much!