debug log 502 error

This commit is contained in:
2025-09-06 02:49:44 +09:00
parent 4cd3745812
commit 49d2aa588b
2 changed files with 410 additions and 5 deletions

View File

@ -8,7 +8,138 @@ import re
from collections import defaultdict, Counter
from datetime import datetime
def analyze_nginx_logs():
def analyze_provided_logs():
"""
ユーザーが提供したログデータを分析
"""
print("🔍 提供されたログデータの分析")
print("=" * 50)
# ユーザーが提供したログデータ
log_data = """
nginx-1 | 172.18.0.1 - - [05/Sep/2025:17:25:15 +0000] "GET /api/new-events/ HTTP/1.0" 200 22641 "-" "Dart/3.9 (dart:io)" "202.215.43.20"
nginx-1 | 172.18.0.1 - - [05/Sep/2025:17:25:15 +0000] "GET /api/entry/ HTTP/1.0" 200 11524 "-" "Dart/3.9 (dart:io)" "202.215.43.20"
nginx-1 | 172.18.0.1 - - [05/Sep/2025:17:25:15 +0000] "GET /api/teams/ HTTP/1.0" 200 674 "-" "Dart/3.9 (dart:io)" "202.215.43.20"
nginx-1 | 172.18.0.1 - - [05/Sep/2025:17:25:15 +0000] "GET /api/categories/ HTTP/1.0" 200 2824 "-" "Dart/3.9 (dart:io)" "202.215.43.20"
nginx-1 | 172.18.0.1 - - [05/Sep/2025:17:25:18 +0000] "GET /api/user/current-entry-info/ HTTP/1.0" 200 512 "-" "Dart/3.9 (dart:io)" "202.215.43.20"
nginx-1 | 172.18.0.1 - - [05/Sep/2025:17:25:19 +0000] "PATCH /api/entries/897/update-status/ HTTP/1.0" 200 1281 "-" "Dart/3.9 (dart:io)" "202.215.43.20"
nginx-1 | 172.18.0.1 - - [05/Sep/2025:17:25:31 +0000] "GET /api/entry/ HTTP/1.0" 200 11523 "-" "Dart/3.9 (dart:io)" "202.215.43.20"
nginx-1 | 172.18.0.1 - - [05/Sep/2025:17:25:31 +0000] "GET /api/teams/ HTTP/1.0" 200 674 "-" "Dart/3.9 (dart:io)" "202.215.43.20"
nginx-1 | 172.18.0.1 - - [05/Sep/2025:17:25:31 +0000] "GET /api/new-events/ HTTP/1.0" 200 22641 "-" "Dart/3.9 (dart:io)" "202.215.43.20"
nginx-1 | 172.18.0.1 - - [05/Sep/2025:17:25:31 +0000] "GET /api/categories/ HTTP/1.0" 200 2824 "-" "Dart/3.9 (dart:io)" "202.215.43.20"
""".strip()
analyze_log_content(log_data.split('\n'))
def analyze_log_content(lines):
"""
ログ内容を分析する共通関数
"""
print(f"📊 ログ行数: {len(lines)}")
# チェックイン・画像関連のエンドポイント
checkin_endpoints = {
'/api/checkinimage/': '画像アップロード',
'/gifuroge/checkin_from_rogapp': 'チェックイン登録',
'/api/bulk_upload_checkin_photos/': '一括写真アップロード',
'/api/user/current-entry-info/': 'ユーザー参加情報',
'/api/entries/': 'エントリー操作',
'/api/new-events/': 'イベント情報',
'/api/teams/': 'チーム情報',
'/api/categories/': 'カテゴリ情報'
}
# 分析結果
endpoint_counts = defaultdict(int)
methods = Counter()
status_codes = Counter()
user_agents = Counter()
client_ips = Counter()
dart_requests = 0
for line in lines:
if not line.strip():
continue
# ログパターンマッチング
# nginx-1 | IP - - [timestamp] "METHOD path HTTP/1.0" status size "-" "user-agent" "real-ip"
match = re.search(r'"(\w+)\s+([^"]+)\s+HTTP/[\d\.]+"\s+(\d+)\s+(\d+)\s+"[^"]*"\s+"([^"]*)"\s+"([^"]*)"', line)
if match:
method = match.group(1)
path = match.group(2)
status = match.group(3)
size = match.group(4)
user_agent = match.group(5)
real_ip = match.group(6)
methods[method] += 1
status_codes[status] += 1
user_agents[user_agent] += 1
client_ips[real_ip] += 1
# Dartクライアントスマホアプリの検出
if 'Dart/' in user_agent:
dart_requests += 1
# エンドポイント別カウント
for endpoint in checkin_endpoints:
if endpoint in path:
endpoint_counts[endpoint] += 1
# 結果表示
print(f"\n📱 Dartクライアントスマホアプリリクエスト: {dart_requests}")
print(f"\n🎯 関連APIエンドポイントの使用状況:")
print("-" * 60)
found_activity = False
for endpoint, description in checkin_endpoints.items():
count = endpoint_counts[endpoint]
if count > 0:
print(f"{description:20s} ({endpoint}): {count}")
found_activity = True
else:
print(f"{description:20s} ({endpoint}): アクセスなし")
print(f"\n📊 HTTPメソッド別:")
for method, count in methods.most_common():
print(f" {method}: {count}")
print(f"\n📊 ステータスコード別:")
for status, count in status_codes.most_common():
print(f" HTTP {status}: {count}")
print(f"\n📊 User Agent:")
for ua, count in user_agents.most_common():
ua_short = ua[:50] + "..." if len(ua) > 50 else ua
print(f" {ua_short}: {count}")
print(f"\n📊 クライアントIP:")
for ip, count in client_ips.most_common():
print(f" {ip}: {count}")
# チェックイン・画像機能の判定
print(f"\n🎯 機能使用状況の判定:")
print("-" * 40)
checkin_active = endpoint_counts['/gifuroge/checkin_from_rogapp'] > 0
image_upload_active = endpoint_counts['/api/checkinimage/'] > 0
bulk_upload_active = endpoint_counts['/api/bulk_upload_checkin_photos/'] > 0
print(f"チェックイン登録機能: {'✅ 使用中' if checkin_active else '❌ 未使用'}")
print(f"画像アップロード機能: {'✅ 使用中' if image_upload_active else '❌ 未使用'}")
print(f"一括写真アップロード機能: {'✅ 使用中' if bulk_upload_active else '❌ 未使用'}")
print(f"スマホアプリDartクライアント: {'✅ アクティブ' if dart_requests > 0 else '❌ 非アクティブ'}")
if dart_requests > 0:
print(f"\n📱 スマホアプリの動作状況:")
print(f" • アプリは正常に動作している")
print(f" • イベント情報、エントリー情報、チーム情報を取得中")
print(f" • エントリーステータスの更新も実行中")
print(f" • ただし、チェックインや画像アップロードは確認されていない")
return found_activity
"""
nginxログを分析してチェックイン・画像関連の活動を確認
"""
@ -20,8 +151,7 @@ def analyze_nginx_logs():
result = subprocess.run(
['docker-compose', 'logs', '--tail=500', 'nginx'],
capture_output=True,
text=True,
cwd='/Volumes/PortableSSD1TB/main/GifuTabi/rogaining_srv_exdb-2/rogaining_srv'
text=True
)
if result.returncode != 0:
@ -204,9 +334,50 @@ def get_status_emoji(status_code):
else:
return ''
def main():
def analyze_nginx_logs():
"""
Dockerコンテナからnginxログを取得・分析
"""
print("🔍 Dockerからnginxログを取得中...")
print("=" * 50)
try:
analyze_nginx_logs()
# docker-compose logsでnginxのログを取得
result = subprocess.run(
['docker-compose', 'logs', '--tail=100', 'nginx'],
capture_output=True,
text=True,
check=True
)
lines = result.stdout.split('\n')
analyze_log_content(lines)
except subprocess.CalledProcessError as e:
print(f"❌ ログ取得エラー: {e}")
print(f"stderr: {e.stderr}")
print("\n💡 Dockerコンテナが起動していることを確認してください")
print(" docker-compose ps")
except FileNotFoundError:
print("❌ docker-composeコマンドが見つかりません")
print("💡 Dockerがインストールされていることを確認してください")
def main():
print("🚀 スマホアプリのnginxログ解析ツール")
print("=" * 50)
choice = input("\n分析方法を選択してください:\n1. Dockerからログを取得\n2. 提供されたログデータを分析\n選択 (1/2): ")
try:
if choice == "1":
analyze_nginx_logs()
elif choice == "2":
analyze_provided_logs()
else:
print("無効な選択です。提供されたログデータを分析します。")
analyze_provided_logs()
print(f"\n✅ 分析完了")
print(f"\n💡 結論:")
print(f" ログから、チェックイン・画像アップロード機能の実際の使用状況を確認できます")
@ -214,6 +385,8 @@ def main():
except Exception as e:
print(f"❌ エラー: {e}")
import traceback
traceback.print_exc()
if __name__ == '__main__':
main()