The Challenge of Agent Updates
Keeping monitoring agents up-to-date is very important for maintaining effective observability in your systems. However, manual updates can be time-consuming and often get overlooked. This post demonstrates a very simple way of how to automate NewRelic agent updates in a Windows environment.
Infrastructure Agent Update Script
Create a PowerShell script to update the NewRelic Infrastructure agent:
Stop-Service -Name “newrelic-infra” (New-Object System.Net.WebClient).DownloadFile( “https://download.newrelic.com/infrastructure_agent/windows/newrelic-infra.msi", “$env:TEMP\newrelic-infra.msi” ) msiexec.exe /qn /i “$env:TEMP\newrelic-infra.msi” Start-Service -Name “newrelic-infra”
.NET Agent Update Script
For the .NET agent, which requires an IIS reset:
(New-Object System.Net.WebClient).DownloadFile( “https://download.newrelic.com/dot_net_agent/latest_release/NewRelicDotNetAgent_x64.msi", “$env:TEMP\NewRelicDotNetAgent_x64.msi” ) msiexec.exe /qn /i “$env:TEMP\NewRelicDotNetAgent_x64.msi” iisreset /restart
Scheduling the Updates
- Place both scripts in
C:\Scripts\
- Create a scheduled task to run weekly (e.g., every Monday)
- For the .NET agent, schedule during low-traffic periods due to the IIS reset
Verifying Updates
Check current versions using PowerShellm these could be implemented as part of the script or notifications:
For Infrastructure Agent
Get-WmiObject -Class Win32_Product | Where-Object { $_.Vendor -eq “New Relic, Inc.” } | Select-Object Name, Version
For .NET Agent
(Get-Item “C:\Program Files\New Relic.NET Agent\netcore\NewRelic.Agent.Core.dll”).VersionInfo | Select-Object FileVersion
Best Practices
- Test the scripts in a non-production environment first
- Schedule updates during maintenance windows
- Monitor the update process through logs
- Implement error handling and notifications
- Keep script locations documented and secured
By implementing this automation, you ensure your NewRelic agents stay current without manual intervention, maintaining optimal monitoring capabilities for your applications.