获得徽章 6
- ## curl 监测接口响应时间
让ChatGPT写了个小脚本, 不得不说, 干这个它确实很在行, 一步到位
write a shell script to check the reponse time of an api:
1. use curl cmd
2. check every 1s
3. echo response time only
4. if the response time is greater than 3s, echo "slow request"
```bash
API_URL="http://11.71......"
DELAY=1
SLOW_THRESHOLD=3
while true; do
response_time=$(curl -s -w "%{time_total}\n" -o /dev/null $API_URL)
echo "Response Time: ${response_time} seconds"
if (( $(echo "$response_time > $SLOW_THRESHOLD" | bc -l) )); then
echo "Slow Request: Response time exceeds 3 seconds,$response_time seconds"
fi
sleep $DELAY
done
```展开17
![[捂脸]](http://lf-web-assets.juejin.cn/obj/juejin-web/xitu_juejin_web/img/jj_emoji_28.8981538.png)