Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix health issue caused by broken logging in fr24feeder v1.0.46-1 #231

Merged
merged 9 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/on_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
docker-platform:
- linux/amd64
- linux/arm64
- linux/arm/v6
# - linux/arm/v6
- linux/arm/v7

steps:
Expand Down
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ RUN set -x && \
KEPT_PACKAGES=() && \
# 'expect' required for signup
KEPT_PACKAGES+=(expect) && \
# required monitor incoming traffic from beasthost
KEPT_PACKAGES+=(tcpdump) && \
# required for adding fr24 repo
TEMP_PACKAGES+=(gnupg) && \
# required to extract .deb file
Expand Down Expand Up @@ -87,4 +89,4 @@ RUN set -x && \
EXPOSE 30334/tcp 8754/tcp 30003/tcp

# Add healthcheck
HEALTHCHECK --start-period=3600s --interval=600s CMD /scripts/healthcheck.sh
HEALTHCHECK --start-period=600s --interval=600s CMD /scripts/healthcheck.sh
2 changes: 2 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/fr24feed_check_traffic/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
exec /etc/s6-overlay/scripts/fr24feed_check_traffic
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/fr24feed_check_traffic/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
Empty file.
2 changes: 1 addition & 1 deletion rootfs/etc/s6-overlay/scripts/01-fr24feed
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fi
# 22-12-15 16:19:09.421 [E][:] Your machine should be set as GMT+0 time zone!
# 22-12-15 16:19:09.421 [W][:] Time zone is not set to GMT+0
if [ -n "${TZ}" ]; then
echo "WARNING: Setting timezone via TZ is not supported in this container. fr24feed requires the container has a timezone of GMT (+0)."
echo "WARNING: Setting timezone via TZ is ignored for this container because fr24feed requires the container to use timezone GMT (+0)."
fi
printf "GMT" > /var/run/s6/container_environment/TZ

Expand Down
20 changes: 20 additions & 0 deletions rootfs/etc/s6-overlay/scripts/fr24feed_check_traffic
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/command/with-contenv bash
#shellcheck shell=bash

# monitor traffic for 5 minutes and write to logfile

# shellcheck disable=SC1091
source /scripts/common

WATCH_INTERVAL="${WATCH_INTERVAL:-300}"
TRAFFIC_FILE="${TRAFFIC_FILE:-/tmp/packets_rcvd}"

while true; do
packets_rcvd="$(sed -z 's/\n/; /g;s/; $//;s/^.*\s\([0-9]\+\) packets captured.*$/\1/g' <<< "$(timeout "$WATCH_INTERVAL" tcpdump -p tcp src port "${BEASTPORT:-30005}" 2>/dev/stdout 1>/dev/null)")"
echo "$(date +%s) $packets_rcvd" > "${TRAFFIC_FILE}"
tail -100 "${TRAFFIC_FILE}" > "${TRAFFIC_FILE}".1
mv -f "${TRAFFIC_FILE}".1 "${TRAFFIC_FILE}"
if chk_enabled "$VERBOSE_LOGGING"; then
s6wrap --quiet --timestamps --prepend="$(basename "$0")" --args echo "$packets_rcvd packets received from $BEASTHOST in the past 5 minutes"
fi
done
5 changes: 4 additions & 1 deletion rootfs/etc/s6-overlay/scripts/fr24feed_log
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

set -o pipefail

if [ "$VERBOSE_LOGGING" = "true" ]; then
# shellcheck disable=SC1091
source /scripts/common

if chk_enabled "$VERBOSE_LOGGING"; then
# show everything
tail -F /var/log/fr24feed.log 2> /dev/null
else
Expand Down
34 changes: 24 additions & 10 deletions rootfs/scripts/healthcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,32 @@ else
EXITCODE=1
fi

# Check /var/log/fr24feed.log for sent data in last 5 minutes
LOG_LAST_ENTRY=$(grep -a '\[feed\]\[i\]sent' /var/log/fr24feed.log | tail -1)
LOG_LAST_ENTRY_TIMESTAMP=$(date --date="$(echo "$LOG_LAST_ENTRY" | cut -d ' ' -f 1,2)" +%s.%N)
TIMESTAMP_NOW=$(date +%s.%N)
RECENT_LINE_IN_LOG=$(echo "($TIMESTAMP_NOW - $LOG_LAST_ENTRY_TIMESTAMP) < 300" | bc)
if [ "$RECENT_LINE_IN_LOG" -eq 1 ]; then
echo "Data sent to fr24feed in past 5 mins. HEALTHY"
else
echo "No data sent data to fr24feed in past 5 mins. UNHEALTHY"
EXITCODE=1
# Logging is broken in fr24feeder v1.0.46-1 -- disabling this check for now
# # Check /var/log/fr24feed.log for sent data in last 5 minutes
# LOG_LAST_ENTRY=$(grep -a '\[feed\]\[i\]sent' /var/log/fr24feed.log | tail -1)
# LOG_LAST_ENTRY_TIMESTAMP=$(date --date="$(echo "$LOG_LAST_ENTRY" | cut -d ' ' -f 1,2)" +%s.%N)
# TIMESTAMP_NOW=$(date +%s.%N)
# RECENT_LINE_IN_LOG=$(echo "($TIMESTAMP_NOW - $LOG_LAST_ENTRY_TIMESTAMP) < 300" | bc)
# if [ "$RECENT_LINE_IN_LOG" -eq 1 ]; then
# echo "Data sent to fr24feed in past 5 mins. HEALTHY"
# else
# echo "No data sent data to fr24feed in past 5 mins. UNHEALTHY"
# EXITCODE=1
# fi

# Check traffic over the last 5 minutes
TRAFFIC_FILE="${TRAFFIC_FILE:-/tmp/packets_rcvd}"
if [[ -f "${TRAFFIC_FILE}" ]]; then
read -ra traffic <<< "$(tail -1 "${TRAFFIC_FILE}")"
if (( $(date +%s) - traffic[0] > 600 )) || (( traffic[1] < 1 )); then
echo "No data received from $BEASTHOST in the past 5 mins. UNHEALTHY"
EXITCODE=1
else
echo "${traffic[1]} packets received from $BEASTHOST in the past 5 mins. HEALTHY"
fi
fi


# now log checks are finished, truncate log
truncate -s 0 /var/log/fr24feed.log > /dev/null 2>&1

Expand Down