Skip to content

Instantly share code, notes, and snippets.

@AdamNaj
Last active June 2, 2024 18:34
Show Gist options
  • Save AdamNaj/bd0c56251049fe2aeea452e2a51e83eb to your computer and use it in GitHub Desktop.
Save AdamNaj/bd0c56251049fe2aeea452e2a51e83eb to your computer and use it in GitHub Desktop.
Most executed Solr queries from latest Sitecore logs
# Gets the latest 30 log files, filters only solr query lines from them, groups them by query content and orders by most executed,
# Letting you find things that are most effective to cache.
Set-HostProperty -HostWidth 2000
$logFileFilter = "azure.log.*"
$logfileCountToAnalyse = 30
$minQueryOccurence = 20
Get-ChildItem $SitecoreLogFolder -Recurse -Filter $logFileFilter `
| Sort -Property LastWriteTime -Descending `
| Select -first $logfileCountToAnalyse `
| Get-Content `
| ? {$_.Contains("INFO Solr Query - ?") } `
| % { $_.Substring($_.IndexOf("Solr Query - ?")+13) } `
| Group-Object `
| ? { $_.Count -gt $minQueryOccurence } `
| Sort-Object -Property Count -Descending `
| ft Count, Name
Clear-Host
# Gets the latest 30 log files, filters only solr query lines from them, groups them by query content and orders by most executed,
# Letting you find things that are most effective to cache.
$logFileFilter = "azure.log.*.*"
$logfileCountToAnalyse = 200
$minQueryOccurence = 100
$SitecoreLogFolder = "C:\Projects\CD Logs\20240522"
$files = Get-ChildItem $SitecoreLogFolder -Recurse -Filter $logFileFilter `
| Sort -Property LastWriteTime -Descending `
| Select -first $logfileCountToAnalyse
$files | Get-Content `
| ? {$_.Contains("INFO Solr Query - ?") } `
| % { $_.Substring($_.IndexOf("Solr Query - ?")+13) } `
| Group-Object `
| ? { $_.Count -gt $minQueryOccurence } `
| Sort-Object -Property Count -Descending `
| ft Count, Name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment