Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
kx1t committed Nov 9, 2023
1 parent 338adc5 commit 4bf4a47
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,9 @@ You should now be feeding ADSB-ES & UAT to the "new" aggregators, FlightAware, a
| Variable | Description | Default |
| -------- | ------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
| `TZ` | Local timezone in ["TZ database name" format](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones). | `UTC` |
| `LAT` | Latitude of your receiver. Only required if you want range statistics for InfluxDB or Prometheus, or if you are using the autogain script. | Unset |
| `LON` | Longitude of your receiver. Only required if you want range statistics for InfluxDB or Prometheus, or if you are using the autogain script. | Unset |
| `LAT` | Latitude of your receiver. Only required if you want range statistics for InfluxDB, Prometheus, or tar1090/ultrafeeder graphs. | Unset |
| `LON` | Longitude of your receiver. Only required if you want range statistics for InfluxDB, Prometheus, or tar1090/ultrafeeder graphs. | Unset |
| `DUMP978_MSG_MONITORING_INTERVAL` | Interval between runs of the Message Monitor that checks if new messages are received. Format of value is anything that is accepted by the Linux `sleep` command | Unset (15 minutes) |

### `dump978-fa` General Options

Expand Down
34 changes: 23 additions & 11 deletions rootfs/etc/s6-overlay/scripts/message-monitor
Original file line number Diff line number Diff line change
@@ -1,34 +1,46 @@
#!/command/with-contenv bash
#shellcheck shell=bash
#shellcheck shell=bash disable=SC1091

source /scripts/common
mkdir -p /run/stats
s6wrap=(s6wrap --quiet --prepend="$(basename "$0")" --timestamps --args)

while :
do
# Make sure we're receiving messages from the SDR
# get the number of messages received since process start:
mkdir -p /run/stats

if [[ -f /run/skyaware978/aircraft.json ]]; then
read -r new_msg_count <<< "$(jq .messages /run/skyaware978/aircraft.json 2>/dev/null)"
else
new_msg_count="STARTING"
fi
# get the number of messages previously read, or 0 if there's no history:
if [[ -f /run/stats/msgs_since_last_healthcheck ]]; then
read -r old_msg_count < /run/stats/msgs_since_last_healthcheck
secs_since_last_check="$(( $(date +%s) - $(stat -c '%Y' /run/stats/msgs_since_last_healthcheck) ))"
if [[ -f /run/stats/msgs_since_last_monitor_run ]]; then
read -r old_msg_count < /run/stats/msgs_since_last_monitor_run
secs_since_last_check="$(( $(date +%s) - $(stat -c '%Y' /run/stats/msgs_since_last_monitor_run) ))"
else
old_msg_count=0
secs_since_last_check="$(( $(date +%s) - $(stat -c '%Y' /run/service/skyaware978) ))" # use skyaware978 modify time as the creation time of the container
secs_since_last_check="$(( $(date +%s) - $(stat -c '%Y' /run/service/skyaware) ))" # use skyaware978 modify time as the creation time of the container
fi

# if new_msg_count < old_msg_count, dump978 must have restarted since the previous run of this script
# in that case, assume that old_msg_count=0
if (( new_msg_count < old_msg_count )); then
old_msg_count=0
fi

if [[ "$new_msg_count" == "STARTING" ]]; then
echo "[$(date)][STARTING] No messages have been received as the container is still starting"
"${s6wrap[@]}" echo "[STARTING] No messages have been received as the container is still starting"
new_msg_count=0
elif (( new_msg_count == old_msg_count )); then
echo "[$(date)][UNHEALTHY] No messages received since last HealthCheck ($secs_since_last_check secs ago)"
"${s6wrap[@]}" echo "[WARNING] No messages received since last run of the Messages Monitor ($secs_since_last_check secs ago)"
elif (( new_msg_count > old_msg_count )); then
"${s6wrap[@]}" echo "[OK] $(( new_msg_count - old_msg_count )) messages received since last run of the Messages Monitor ($secs_since_last_check secs ago)"
else
echo "[$(date)][ERROR] This situation cannot occur; new_msg_count=$new_msg_count; old_msg_count=$old_msg_count"
"${s6wrap[@]}" echo "[ERROR] This situation cannot occur, please notify the software maintainers. new_msg_count=$new_msg_count; old_msg_count=$old_msg_count"
fi
echo "$new_msg_count" > /run/stats/msgs_since_last_healthcheck
echo "$new_msg_count" > /run/stats/msgs_since_last_monitor_run

sleep 15m
sleep "${DUMP978_MSG_MONITORING_INTERVAL:-15m}" & wait !
done
18 changes: 10 additions & 8 deletions rootfs/scripts/healthcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@ fi
services=($(basename -a $(find /run/service/ -maxdepth 1 -type l)))
# For each service...
for service in "${services[@]}"; do
abnormal_deaths="$(s6-svdt -s "/run/service/$service" | awk '/exitcode/ && !/exitcode 0/' | wc -l)"
if (( abnormal_deaths > 0 )); then
echo "[$(date)][UNHEALTHY] abnormal death count for service $service is $abnormal_deaths"
EXITCODE=1
# Reset service death counts
s6-svdt-clear "/run/service/$service"
else
echo "[$(date)][HEALTHY] no abnormal death count for service $service"
if [[ "${service:0:5}" != "s6rc-" ]]; then
abnormal_deaths="$(s6-svdt -s "/run/service/$service" | awk '/exitcode/ && !/exitcode 0/' | wc -l)"
if (( abnormal_deaths > 0 )); then
echo "[$(date)][UNHEALTHY] abnormal death count for service $service is $abnormal_deaths"
EXITCODE=1
# Reset service death counts
s6-svdt-clear "/run/service/$service"
else
echo "[$(date)][HEALTHY] no abnormal death count for service $service"
fi
fi
done

Expand Down

0 comments on commit 4bf4a47

Please sign in to comment.