mirror of
https://github.com//cppla/ServerStatus
synced 2026-03-26 00:09:49 +08:00
add client docker
This commit is contained in:
@@ -32,6 +32,34 @@ import threading
|
||||
import platform
|
||||
from queue import Queue
|
||||
|
||||
def _env_str(name, default):
|
||||
value = os.getenv(name)
|
||||
if value is None or value == "":
|
||||
return default
|
||||
return value
|
||||
|
||||
def _env_int(name, default):
|
||||
value = os.getenv(name)
|
||||
if value is None or value == "":
|
||||
return default
|
||||
try:
|
||||
return int(value)
|
||||
except ValueError:
|
||||
return default
|
||||
|
||||
# Allow docker env overrides
|
||||
SERVER = _env_str("SERVER", SERVER)
|
||||
USER = _env_str("USER", USER)
|
||||
PASSWORD = _env_str("PASSWORD", PASSWORD)
|
||||
PORT = _env_int("PORT", PORT)
|
||||
INTERVAL = _env_int("INTERVAL", INTERVAL)
|
||||
PROBEPORT = _env_int("PROBEPORT", PROBEPORT)
|
||||
PROBE_PROTOCOL_PREFER = _env_str("PROBE_PROTOCOL_PREFER", PROBE_PROTOCOL_PREFER)
|
||||
PING_PACKET_HISTORY_LEN = _env_int("PING_PACKET_HISTORY_LEN", PING_PACKET_HISTORY_LEN)
|
||||
CU = _env_str("CU", CU)
|
||||
CT = _env_str("CT", CT)
|
||||
CM = _env_str("CM", CM)
|
||||
|
||||
def get_uptime():
|
||||
with open('/proc/uptime', 'r') as f:
|
||||
uptime = f.readline().split('.', 2)
|
||||
|
||||
@@ -32,6 +32,34 @@ import threading
|
||||
import platform
|
||||
from queue import Queue
|
||||
|
||||
def _env_str(name, default):
|
||||
value = os.getenv(name)
|
||||
if value is None or value == "":
|
||||
return default
|
||||
return value
|
||||
|
||||
def _env_int(name, default):
|
||||
value = os.getenv(name)
|
||||
if value is None or value == "":
|
||||
return default
|
||||
try:
|
||||
return int(value)
|
||||
except ValueError:
|
||||
return default
|
||||
|
||||
# Allow docker env overrides
|
||||
SERVER = _env_str("SERVER", SERVER)
|
||||
USER = _env_str("USER", USER)
|
||||
PASSWORD = _env_str("PASSWORD", PASSWORD)
|
||||
PORT = _env_int("PORT", PORT)
|
||||
INTERVAL = _env_int("INTERVAL", INTERVAL)
|
||||
PROBEPORT = _env_int("PROBEPORT", PROBEPORT)
|
||||
PROBE_PROTOCOL_PREFER = _env_str("PROBE_PROTOCOL_PREFER", PROBE_PROTOCOL_PREFER)
|
||||
PING_PACKET_HISTORY_LEN = _env_int("PING_PACKET_HISTORY_LEN", PING_PACKET_HISTORY_LEN)
|
||||
CU = _env_str("CU", CU)
|
||||
CT = _env_str("CT", CT)
|
||||
CM = _env_str("CM", CM)
|
||||
|
||||
def get_uptime():
|
||||
return int(time.time() - psutil.boot_time())
|
||||
|
||||
|
||||
20
clients/entrypoint.sh
Normal file
20
clients/entrypoint.sh
Normal file
@@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
if [ "$#" -gt 0 ]; then
|
||||
exec "$@"
|
||||
fi
|
||||
|
||||
case "${CLIENT:-linux}" in
|
||||
linux|client-linux|client-linux.py)
|
||||
exec python3 /app/client-linux.py
|
||||
;;
|
||||
psutil|client-psutil|client-psutil.py)
|
||||
exec python3 /app/client-psutil.py
|
||||
;;
|
||||
*)
|
||||
echo "Unknown CLIENT='$CLIENT'. Use 'linux' or 'psutil'." >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
|
||||
Reference in New Issue
Block a user