利用者:Marmaray/Enpediaサーバー診断プログラム

出典: 謎の百科事典もどき『エンペディア(Enpedia)』
ナビゲーションに移動 検索に移動

Enpediaのサーバーが応答可能かどうかを30秒で調べるPythonプログラム。ChatGPT (GPT5.6-Luna)にて作成。

import subprocess
import time

URL = "https://enpedia.org/"
COUNT = 10
INTERVAL = 3
TIMEOUT = 2

results = []

print("Enpedia の状態を確認しています...")
print()

for i in range(COUNT):
    result = subprocess.run(
        [
            "curl",
            "-6",
            "-L",
            "-s",
            "-o", "NUL",
            "-m", str(TIMEOUT),
            "-w", "%{http_code}",
            URL
        ],
        capture_output=True,
        text=True
    )

    code = result.stdout.strip()

    if not code:
        code = "000"

    results.append(code)

    if code == "200":
        status = "OK"
    elif code == "503":
        status = "Backend Error"
    else:
        status = "Other"

    print(f"{i + 1:2}回目: HTTP {code}  {status}")

    if i < COUNT - 1:
        time.sleep(INTERVAL)

# 集計
ok = results.count("200")
error_503 = results.count("503")
other = COUNT - ok - error_503
success_rate = ok / COUNT * 100

print()
print("========== 結果 ==========")
print(f"200 OK       : {ok:2}/{COUNT}")
print(f"503 Backend  : {error_503:2}/{COUNT}")
print(f"その他       : {other:2}/{COUNT}")
print(f"成功率       : {success_rate:5.1f}%")
print()

if success_rate == 100:
    print("判定: 正常")
elif success_rate >= 80:
    print("判定: ほぼ正常")
elif success_rate >= 30:
    print("判定: 五分五分")
elif success_rate > 0:
    print("判定: ほぼ応答なし")
else:
    print("判定: 応答なし")