Last active
October 6, 2025 11:03
-
-
Save jcardus/6458b9158c5d340e62c02d0c5925c566 to your computer and use it in GitHub Desktop.
traccar connections to cloudwatch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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