-
Notifications
You must be signed in to change notification settings - Fork 509
Expand file tree
/
Copy pathmonitor_logs.sh
More file actions
132 lines (119 loc) · 3.38 KB
/
monitor_logs.sh
File metadata and controls
132 lines (119 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
LOG_DIR="/var/log/supervisor"
show_help() {
echo "Helicone Service Log Monitor"
echo "Usage: $0 [command] [service]"
echo ""
echo "Commands:"
echo " list - List all available log files"
echo " tail - Tail logs for a specific service"
echo " tail-all - Tail logs for all services"
echo " follow - Follow logs for a specific service (like tail -f)"
echo " show - Show last 50 lines of a service log"
echo ""
echo "Services:"
echo " web - Next.js frontend"
echo " jawn - Backend API server"
echo " ai-gateway - AI Gateway service"
echo " postgresql - PostgreSQL database"
echo " clickhouse - ClickHouse database"
echo " minio - MinIO object storage"
echo " flyway - Database migrations"
echo " clickhouse-migrate - ClickHouse migrations"
echo " minio-setup - MinIO setup"
echo " supervisord - Supervisor daemon"
echo ""
echo "Examples:"
echo " $0 list"
echo " $0 tail web"
echo " $0 follow jawn"
echo " $0 tail-all"
}
list_logs() {
echo "Available log files:"
ls -la $LOG_DIR/*.log 2>/dev/null | awk '{print $9, $5, $6, $7, $8}' | column -t
}
tail_service() {
local service=$1
local log_file="$LOG_DIR/${service}.out.log"
local err_file="$LOG_DIR/${service}.err.log"
if [[ -f "$log_file" ]]; then
echo "=== $service Output Logs ==="
tail -n 20 "$log_file"
fi
if [[ -f "$err_file" ]]; then
echo "=== $service Error Logs ==="
tail -n 20 "$err_file"
fi
if [[ ! -f "$log_file" && ! -f "$err_file" ]]; then
echo "No logs found for service: $service"
echo "Available services:"
ls $LOG_DIR/*.log 2>/dev/null | sed 's|.*/||' | sed 's|\..*\.log||' | sort -u
fi
}
follow_service() {
local service=$1
local log_file="$LOG_DIR/${service}.out.log"
if [[ -f "$log_file" ]]; then
echo "Following logs for $service (Ctrl+C to stop)..."
tail -f "$log_file"
else
echo "No output log found for service: $service"
fi
}
tail_all() {
echo "=== All Service Logs (last 10 lines each) ==="
for log_file in $LOG_DIR/*.out.log; do
if [[ -f "$log_file" ]]; then
service_name=$(basename "$log_file" .out.log)
echo ""
echo "--- $service_name ---"
tail -n 10 "$log_file"
fi
done
}
show_service() {
local service=$1
local log_file="$LOG_DIR/${service}.out.log"
if [[ -f "$log_file" ]]; then
echo "=== Last 50 lines for $service ==="
tail -n 50 "$log_file"
else
echo "No output log found for service: $service"
fi
}
case "$1" in
"list")
list_logs
;;
"tail")
if [[ -z "$2" ]]; then
echo "Please specify a service name"
show_help
exit 1
fi
tail_service "$2"
;;
"follow")
if [[ -z "$2" ]]; then
echo "Please specify a service name"
show_help
exit 1
fi
follow_service "$2"
;;
"tail-all")
tail_all
;;
"show")
if [[ -z "$2" ]]; then
echo "Please specify a service name"
show_help
exit 1
fi
show_service "$2"
;;
*)
show_help
;;
esac