I am currently trying to find a way to monitor agents in Azure that were scaled by Azure Scale-Sets. To avoid costs I want to kill every agent that has been running a job for longer than 1 hour. Is there a solution from Azure that would help me in this case?
I was thinking about using alerts and Azure functions but I dont know which alert signal to use since they all only consider metrics from the vmss and not a single agent.
Thank you
You can use an Azure Automation runbook to check and kill the
Agent Serviceevery hour. To create a runbook and schedule the job, you can follow the Stack link that I answered.Here is the
PowerShell scriptcan monitor and terminate theAzure Monitor Agent Serviceif it runs longer than an hour.To schedule the Job and check the
Agent servicestatus hourly, you can follow the steps shown in the snapshot below.Output: