Skip to content

Commit

Permalink
Updated mem.sh custom metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Kwee-Veen authored Apr 28, 2024
1 parent c35ce31 commit 29641bc
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions mem.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,21 @@ INSTANCE_ID=$(curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.2
USEDMEMORY=$(free -m | awk 'NR==2{printf "%.2f\t", $3*100/$2 }')
TCP_CONN=$(netstat -an | wc -l)
TCP_CONN_PORT_3000=$(netstat -an | grep 3000 | wc -l)
TCP_CONN_PORT_443=$(netstat -an | grep 443 | wc -l)
IO_WAIT=$(iostat | awk 'NR==4 {print $5}')

aws cloudwatch put-metric-data --metric-name memory-usage --dimensions Instance=$INSTANCE_ID --namespace "Custom" --value $USEDMEMORY
aws cloudwatch put-metric-data --metric-name Tcp_connections --dimensions Instance=$INSTANCE_ID --namespace "Custom" --value $TCP_CONN
aws cloudwatch put-metric-data --metric-name TCP_connection_on_port_3000 --dimensions Instance=$INSTANCE_ID --namespace "Custom" --value $TCP_CONN_PORT_3000
aws cloudwatch put-metric-data --metric-name TCP_connection_on_port_443 --dimensions Instance=$INSTANCE_ID --namespace "Custom" --value $TCP_CONN_PORT_443
aws cloudwatch put-metric-data --metric-name IO_WAIT --dimensions Instance=$INSTANCE_ID --namespace "Custom" --value $IO_WAIT

HTTP_OR_HTTPS_CONN=($TCP_CONN_PORT_3000 + $TCP_CONN_PORT_443)
aws cloudwatch put-metric-data --metric-name HTTP_or_HTTPS_Connections --dimensions Instance=$INSTANCE_ID --namespace "Custom" --value $HTTP_OR_HTTPS_CONN

high_load=0
if [[ $IO_WAIT > 70 || $USEDMEMORY > 80 ]]
then
high_load=1
fi
aws cloudwatch put-metric-data --metric-name High_Load --dimensions Instance=$INSTANCE_ID --namespace "Custom" --value $high_load

0 comments on commit 29641bc

Please sign in to comment.