How to create an alert when apm agent stops working?

I have multiple elastic apm java agent deployed and i need to create an alert when it stops working. I see one topic relevant to this but I still want to check what is the configuration of alert in case we enable health metrics as suggested in below topic :

Can someone please suggest if they worked on it. I am pretty much new to elastic. Please help.

Elastic version : 8.13.2

Regards,
Gopikrishnan R.

{
  "rule_id": "apm-agent-health-alert",
  "risk_score": 50,
  "severity": "medium",
  "description": "Alert when an APM agent stops sending health metrics",
  "interval": "5m",
  "name": "APM Agent Health Alert",
  "type": "query",
  "from": "now-5m",
  "to": "now",
  "query": {
    "bool": {
      "must_not": [
        {
          "exists": {
            "field": "agent.name"
          }
        }
      ],
      "filter": [
        {
          "range": {
            "@timestamp": {
              "gte": "now-5m",
              "lte": "now"
            }
          }
        }
      ]
    }
  },
  "actions": [
    {
      "action_type_id": ".email",
      "group": "default",
      "params": {
        "to": ["your-email@example.com"],
        "subject": "APM Agent Health Alert",
        "body": "An APM agent has stopped sending health metrics."
      }
    }
  ]
}

Hi @krishnannair87, Welcome to the Elastic community.

Adding to @atul_mohan suggestion, you can also try to setup APM Rules and alerts on your data.

@atul_mohan @ashishtiwari1993 thanks for your response. I am pretty much beginner in elastic so need some guidance. If I click on option Alerts and rulesManage rulesCreate Rule I only see options to create alert on APM anamoly, failed threshold count, latency etc. how can i create alert on agent status metrics?

Regards,
Gopikrishnan R.