mirror of
https://github.com//cppla/ServerStatus
synced 2026-03-23 06:09:48 +08:00
add client docker
This commit is contained in:
33
Dockerfile.client
Normal file
33
Dockerfile.client
Normal file
@@ -0,0 +1,33 @@
|
||||
FROM python:3.11-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Runtime deps for client-linux.py (ss/ps) and optional psutil client
|
||||
RUN apt-get update -y \
|
||||
&& apt-get install -y --no-install-recommends iproute2 procps \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN pip install --no-cache-dir psutil
|
||||
|
||||
COPY clients/client-linux.py /app/client-linux.py
|
||||
COPY clients/client-psutil.py /app/client-psutil.py
|
||||
COPY clients/entrypoint.sh /app/entrypoint.sh
|
||||
|
||||
# Default client and defaults (can be overridden by docker env)
|
||||
ENV SERVER=127.0.0.1 \
|
||||
USER=s01 \
|
||||
PORT=35601 \
|
||||
PASSWORD=USER_DEFAULT_PASSWORD \
|
||||
INTERVAL=1 \
|
||||
PROBEPORT=80 \
|
||||
PROBE_PROTOCOL_PREFER=ipv4 \
|
||||
PING_PACKET_HISTORY_LEN=100 \
|
||||
CU=cu.tz.cloudcpp.com \
|
||||
CT=ct.tz.cloudcpp.com \
|
||||
CM=cm.tz.cloudcpp.com \
|
||||
CLIENT=linux
|
||||
|
||||
RUN chmod +x /app/entrypoint.sh
|
||||
|
||||
ENTRYPOINT ["/app/entrypoint.sh"]
|
||||
CMD []
|
||||
25
README.md
25
README.md
@@ -18,12 +18,15 @@
|
||||
【服务端】:
|
||||
```bash
|
||||
|
||||
`Docker`:
|
||||
`Docker`:
|
||||
|
||||
wget --no-check-certificate -qO ~/serverstatus-config.json https://raw.githubusercontent.com/cppla/ServerStatus/master/server/config.json && mkdir ~/serverstatus-monthtraffic
|
||||
docker run -d --restart=always --name=serverstatus -v ~/serverstatus-config.json:/ServerStatus/server/config.json -v ~/serverstatus-monthtraffic:/usr/share/nginx/html/json -p 80:80 -p 35601:35601 cppla/serverstatus:latest
|
||||
|
||||
`Docker-compose(推荐)`: docker-compose up -d
|
||||
|
||||
`Dockerfile.server`(本地构建服务端):
|
||||
docker build -f Dockerfile.server -t serverstatus-server .
|
||||
```
|
||||
|
||||
【客户端】:
|
||||
@@ -34,6 +37,26 @@ eg:
|
||||
wget --no-check-certificate -qO client-linux.py 'https://raw.githubusercontent.com/cppla/ServerStatus/master/clients/client-linux.py' && nohup python3 client-linux.py SERVER=45.79.67.132 USER=s04 >/dev/null 2>&1 &
|
||||
```
|
||||
|
||||
【客户端 Docker】:
|
||||
```bash
|
||||
# 构建客户端镜像
|
||||
docker build -f Dockerfile.client -t serverstatus-client .
|
||||
|
||||
# 默认 client-linux.py
|
||||
docker run --network=host --rm \
|
||||
-e SERVER=127.0.0.1 -e USER=s01 -e PASSWORD=USER_DEFAULT_PASSWORD \
|
||||
serverstatus-client
|
||||
|
||||
# 选择 client-psutil.py
|
||||
docker run --network=host --rm \
|
||||
-e CLIENT=psutil \
|
||||
-e SERVER=127.0.0.1 -e USER=s01 -e PASSWORD=USER_DEFAULT_PASSWORD \
|
||||
serverstatus-client
|
||||
|
||||
# 或直接覆盖命令
|
||||
docker run --network=host --rm serverstatus-client python3 /app/client-psutil.py
|
||||
```
|
||||
|
||||
|
||||
# 教程:
|
||||
|
||||
|
||||
@@ -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