If CPU usage for the `api` service exceeds **90% for more than 5 minutes**, follow these steps:
1. **Identify Top Processes**
SSH into `${AFFECTED_HOST}` and run:
ps -eo pid,ppid,cmd,%cpu --sort=-%cpu | head -n 10
- Note which processes are consuming the most CPU.
2. **Capture Java Thread Dump (if applicable)**
If you find a Java process in the top list:
jstack -l ${JAVA_PID} > /tmp/thread-dump-$(date +%s).txt
- Replace `${JAVA_PID}` with the actual PID of the Java process.
3. **Scale the API Deployment (if needed)**
If `api` is the main contributor to CPU:
kubectl scale deployment api --replicas=$((CURRENT_REPLICAS * 2)) -n production
- Replace `CURRENT_REPLICAS` with the current replica count.
4. **Alert Message**
Prepare an alert message with top processes included:
High CPU usage detected. Investigation required.
Top processes:
<paste output from step 1>
5. **Escalation**
- If CPU usage continues after scaling or thread dump indicates deeper issues, escalate to infra or backend team.