JudgeServer/server/utils.py
2017-06-12 23:51:13 +08:00

38 lines
942 B
Python

import _judger
import psutil
import socket
import logging
import hashlib
import os
from exception import JudgeClientError
logger = logging.getLogger(__name__)
handler = logging.FileHandler("/log/judge_server.log")
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.setLevel(logging.WARNING)
def server_info():
ver = _judger.VERSION
return {"hostname": socket.gethostname(),
"cpu": psutil.cpu_percent(),
"cpu_core": psutil.cpu_count(),
"memory": psutil.virtual_memory().percent,
"judger_version": ".".join([str((ver >> 16) & 0xff), str((ver >> 8) & 0xff), str(ver & 0xff)])}
def get_token():
token = os.environ.get("token")
if token:
return token
else:
raise JudgeClientError("ENV token not found")
token = hashlib.sha256(get_token().encode("utf-8")).hexdigest()