一个监控远程客户连接本地service的shell
时间:2006-03-18 来源:tingyu
昨天发现一台DB无法连接,原因是当前的已经达到了Oracle设置的最大连接数。刚好前几天看了一个shell能监控这个问题:
#!/bin/bash #This shell can monitor the connection number for one service. SERVICE_PORT="1521" SERVICE_IP="172.16.219.193" DEFINE_MAX_CONNECTION=1 MAIL_TO_USER="[email protected]" #main function check_connection() { netstat -na |grep ESTABLISH |grep $SERVICE_IP:$SERVICE_PORT |awk '{print $5}' |awk -F':' '{print $1}'|sort |uniq -c|awk '{print $1"="$2}' } for remote_ip in $(check_connection) do if [ $(echo $remote_ip|awk -F'=' '{print $1}') > $DEFINE_MAX_CONNECTION ] then ip=$(echo $remote_ip|awk -F'=' '{print $2}') message="There are more than $DEFINE_MAX_CONNECTION from $ip to $SERVICE_IP:$SERVICE_PORT, I want to drop it, please check it ASAP!" echo $message|mail $MAIL_TO_USER -s "A warning mail from $SERVICE_IP!" fi done |
相关阅读 更多 +
排行榜 更多 +