-
Notifications
You must be signed in to change notification settings - Fork 84
/
pub_metrics.sh
executable file
·25 lines (19 loc) · 1.33 KB
/
pub_metrics.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/bash
netstat=$(mktemp)
while true
do
netstat -an| grep tcp| awk '{print $NF}'|sort | uniq -c | awk '{printf "%s %s\n",$2,$1}' > $netstat
value=$(cat $netstat | grep ESTABLISHED | awk '{print $2}')
[[ ! -z "$value" ]] && { metric="ESTABLISHED"; aws cloudwatch put-metric-data --metric-name $metric --namespace pgbouncer --value $value; }
value=$(cat $netstat | grep LISTEN | awk '{print $2}')
[[ ! -z "$value" ]] && { metric="LISTEN"; aws cloudwatch put-metric-data --metric-name $metric --namespace pgbouncer --value $value; }
value=$(cat $netstat | grep TIME_WAIT | awk '{print $2}')
[[ ! -z "$value" ]] && { metric="TIME_WAIT"; aws cloudwatch put-metric-data --metric-name $metric --namespace pgbouncer --value $value; }
value=$(cat $netstat | grep SYN_RECV | awk '{print $2}')
[[ ! -z "$value" ]] && { metric="SYN_RECV"; aws cloudwatch put-metric-data --metric-name $metric --namespace pgbouncer --value $value; }
value=$(cat $netstat | grep LAST_ACK | awk '{print $2}')
[[ ! -z "$value" ]] && { metric="LAST_ACK"; aws cloudwatch put-metric-data --metric-name $metric --namespace pgbouncer --value $value ; }
value=$(cat $netstat | grep CLOSE_WAIT | awk '{print $2}')
[[ ! -z "$value" ]] && { metric="CLOSE_WAIT"; aws cloudwatch put-metric-data --metric-name $metric --namespace pgbouncer --value $value ; }
sleep 60
done