Skip to content

Instantly share code, notes, and snippets.

@jcardus
Last active October 6, 2025 11:03
Show Gist options
  • Select an option

  • Save jcardus/6458b9158c5d340e62c02d0c5925c566 to your computer and use it in GitHub Desktop.

Select an option

Save jcardus/6458b9158c5d340e62c02d0c5925c566 to your computer and use it in GitHub Desktop.
traccar connections to cloudwatch
#!/bin/bash
NAMESPACE="Traccar"
INTERVAL=59
REGION="us-east-1"
while true; do
date
total=$(ss -tan | wc -l)
echo "Total connections: $total"
aws cloudwatch put-metric-data \
--namespace "$NAMESPACE" \
--metric-name "Connections" \
--value "$total" \
--unit "Count" \
--region "$REGION"
ss -tan state established \
| awk '{print $3}' \
| awk -F: '{port=$NF; if (port < 5500) print port}' \
| sort | uniq -c | while read count port; do
echo "Port $port: $count connections"
aws cloudwatch put-metric-data \
--namespace "$NAMESPACE" \
--metric-name "Connections" \
--dimensions "Port=$port" \
--value "$count" \
--unit "Count" \
--region "$REGION"
done
sleep $INTERVAL
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment