refactor: enhance logging and user agent mapping in nginx configuration for improved monitoring

This commit is contained in:
zurdi
2025-05-08 17:22:30 +00:00
parent d5bb63c06f
commit 5bc820d3ee
2 changed files with 33 additions and 13 deletions

View File

@@ -93,18 +93,19 @@ start_bin_gunicorn() {
start_bin_nginx() {
wait_for_gunicorn_socket
info_log "Starting internal nginx"
info_log "Starting nginx"
if [[ ${EUID} -ne 0 ]]; then
nginx
else
# if container runs as root, drop permissions
nginx -g 'user romm;'
fi
info_log "🚀 RomM is now available at http://[::1]:8080"
}
# Commands to start valkey-server (handling PID creation internally)
start_bin_valkey-server() {
info_log "Starting internal valkey-server"
info_log "Starting internal valkey"
if [[ -f /usr/local/etc/valkey/valkey.conf ]]; then
if [[ ${LOGLEVEL} == "debug" ]]; then
@@ -128,7 +129,7 @@ start_bin_valkey-server() {
local max_retries=120
local retry=0
debug_log "Waiting for internal valkey-server to be ready..."
debug_log "Waiting for internal valkey to be ready..."
# Temporarily disable errexit for this part of the script
set +o errexit
@@ -136,7 +137,7 @@ start_bin_valkey-server() {
while ((retry < max_retries)); do
# Attempt to check if valkey TCP port is open
if (echo >/dev/tcp/"${host}"/"${port}") 2>/dev/null; then
debug_log "Internal valkey-server is ready and accepting connections"
debug_log "Internal valkey is ready and accepting connections"
set -o errexit # Re-enable errexit after success
return 0
fi
@@ -145,7 +146,7 @@ start_bin_valkey-server() {
((retry++))
done
error_log "Internal valkey-server did not become ready after $((max_retries * 500))ms"
error_log "Internal valkey did not become ready after $((max_retries * 500))ms"
}
# function that runs our independent python scripts and creates corresponding PID files,
@@ -232,8 +233,6 @@ fi
while ! ((exited)); do
watchdog_process_pid bin gunicorn
watchdog_process_pid bin nginx
watchdog_process_pid python worker
# only start the scheduler if enabled
@@ -246,6 +245,8 @@ while ! ((exited)); do
watchdog_process_pid python watcher
fi
watchdog_process_pid bin nginx
# check for died processes every 5 seconds
sleep 5
done

View File

@@ -42,13 +42,32 @@ http {
~T([0-9:]+)\+ $1;
}
#INFO: [nginx][2023-11-14 09:20:29] 127.0.0.1 - -"GET / HTTP/1.1" 500 177 "-" "Mozilla/5.0 (X11; Linux x86_64)"rt=0.000 uct="-" uht="-" urt="-"
log_format romm_log 'INFO: [nginx][$date $time] $remote_addr - $remote_user '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" '
'rt=$request_time uct="$upstream_connect_time" uht="$upstream_header_time" urt="$upstream_response_time"';
# Map to extract the browser name (e.g., Chrome, Firefox, etc.)
map $http_user_agent $browser {
default "Unknown";
"~Chrome/" "Chrome";
"~Firefox/" "Firefox";
"~Safari/" "Safari";
"~Edge/" "Edge";
"~Opera/" "Opera";
}
access_log /dev/stdout romm_log;
# Map to extract the OS (e.g., Windows, MacOS, Linux)
map $http_user_agent $os {
default "Unknown";
"~Windows NT" "Windows";
"~Macintosh" "macOS";
"~Linux" "Linux";
"~Android" "Android";
"~iPhone" "iOS";
}
#INFO: [nginx][2023-11-14 09:20:29] 127.0.0.1 - -"GET / HTTP/1.1" 500 177 "-" "Mozilla/5.0 (X11; Linux x86_64)"rt=0.000 uct="-" uht="-" urt="-"
log_format romm_logs 'INFO: [RomM][nginx][$date $time] $remote_addr | $http_x_forwarded_for | '
'$request_method $server_protocol $request_uri $status $body_bytes_sent | '
'$browser $os | $request_time';
access_log /dev/stdout romm_logs;
error_log /dev/stderr;
gzip on;