Use Azure Resource Graph Explorer
Azure Resource Graph can be used to query the state of your resources, including Arc-enabled servers. You can create a query to check the status of your VMs and create alerts based on these queries.
Example Query
resources
| where type == "microsoft.hybridcompute/machines"
| project name, status = properties.status.displayStatus
| where status != "Running"
You can set up an alert rule based on this query to notify you when the status of any Arc-enabled server is not "Running." Or else
Use Custom Script for Monitoring.
In scenarios where built-in monitoring tools fall short, you can deploy custom scripts to your Arc-enabled servers to periodically check their status and report back to Azure Monitor.
Example Script
Create a custom script that checks the VM status and logs it to Log Analytics or sends it to an Azure Function for further processing.
#!/bin/bash
# Check if the VM is running
if systemctl is-active --quiet my-vm-service; then
echo "VM is running"
else
echo "VM is stopped"
fi
Deploy this script using a cron job or a similar scheduling tool, and configure it to send logs to Azure Monitor.