Compare commits

..

No commits in common. "7cbca85a60eb5c18a524e699a60e1ac83946b20c" and "87418edeea61eeb01eefadc33d38421885aca9b2" have entirely different histories.

4 changed files with 26 additions and 41 deletions

View File

@ -57,8 +57,8 @@ _✨ 服务器状态 - 客户端 ✨_
### 命令 ### 命令
- `python main.py <server> <token> <id> run` - 运行客户端 - `server-status <server> <token> <id> run` - 运行客户端
- `python.main.py <server> <token> <id> rm` - 从服务端移除主机 - `server-status <server> <token> <id> rm` - 从服务端移除主机
#### 可选项 #### 可选项
@ -71,7 +71,7 @@ _✨ 服务器状态 - 客户端 ✨_
#### 示例 #### 示例
```shell ```shell
python main.py https://status.liteyuki.icu 114514 myhost run -n "MyHost" --labels "标签1,标签2" --interval 5 --location "Chongqing" --link "https://example.com" server_status https://status.liteyuki.icu 114514 myhost run -n "MyHost" --labels "标签1,标签2" --interval 5 --location "Chongqing" --link "https://example.com"
``` ```
## 📝 其他 ## 📝 其他

View File

@ -10,36 +10,40 @@ fi
# check install dir # check install dir
install_dir="/opt" install_dir="/opt"
echo -n "安装目录? (默认: $install_dir/server-status-client): " && read -r install_dir_input echo -n "Install directory? (default: $install_dir/server-status-client): " && read -r install_dir_input
if [ -n "$install_dir_input" ]; then if [ -n "$install_dir_input" ]; then
install_dir="$install_dir_input" install_dir="$install_dir_input"
fi fi
# check server # check server
echo -n "服务端地址? (必须): " && read -r server echo -n "Server? (required): " && read -r server
if [ -z "$server" ]; then if [ -z "$server" ]; then
echo "服务端地址是必须的" echo "Server is required"
exit 1 exit 1
fi fi
# check token # check token
echo -n "令牌? (必须或留空): " && read -r token echo -n "Token? (required): " && read -r token
if [ -z "$token" ]; then
echo "Token is required"
exit 1
fi
# check hostname # check hostname
hostname=$(hostname) hostname=$(hostname)
echo -n "此主机名? (默认: $hostname): " && read -r hostname_input echo -n "Hostname? (default: $hostname): " && read -r hostname_input
if [ -n "$hostname_input" ]; then if [ -n "$hostname_input" ]; then
hostname="$hostname_input" hostname="$hostname_input"
fi fi
# labels # labels
echo -n "标签们? (空格分隔): " && read -r labels_input echo -n "Labels? (space separated): " && read -r labels_input
if [ -n "$labels_input" ]; then if [ -n "$labels_input" ]; then
labels="$labels_input" labels="$labels_input"
fi fi
# location # location
echo -n "地理位置? (可选|自定义): " && read -r location_input echo -n "Location? (optional): " && read -r location_input
if [ -n "$location_input" ]; then if [ -n "$location_input" ]; then
location="$location_input" location="$location_input"
fi fi
@ -48,7 +52,7 @@ fi
repo2="https://git.liteyuki.icu/snowykami/server-status-client" repo2="https://git.liteyuki.icu/snowykami/server-status-client"
# try 1 if failed try 2 # try 1 if failed try 2
git clone "$repo2" "$install_dir/server-status-client" git clone "$repo2" "$install_dir/server-status-client"
cd "$install_dir/server-status-client" || { echo "克隆失败"; exit 1; } cd "$install_dir/server-status-client" || { echo "Failed to clone repo"; exit 1; }
# create venv # create venv
python3 -m venv venv python3 -m venv venv
@ -56,22 +60,22 @@ python_exe="./venv/bin/python"
# check if venv is created # check if venv is created
if [ ! -f "$python_exe" ]; then if [ ! -f "$python_exe" ]; then
echo "创建虚拟环境失败" echo "Failed to create venv"
exit 1 exit 1
fi fi
echo "虚拟环境创建成功" echo "venv created successfully"
# install the required packages # install the required packages
echo "正在安装依赖包..." echo "Installing the required packages"
$python_exe -m pip install pdm -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple $python_exe -m pip install pdm -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
$python_exe -m pdm install $python_exe -m pdm install
# create the systemd service # create the systemd service
echo "正在创建服务..." echo "Creating the systemd service"
# generate random id # generate random id
# shellcheck disable=SC2002 # shellcheck disable=SC2002
id=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1) id=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
bash -c "cat <<EOF > /etc/systemd/system/server-status-client.service bash -c "cat <<EOF > /etc/systemd/system/server-status-client.service
[Unit] [Unit]
@ -93,4 +97,4 @@ EOF"
systemctl enable server-status-client systemctl enable server-status-client
systemctl start server-status-client systemctl start server-status-client
echo "安装完成,服务已启动" echo "server-status-client installed successfully"

View File

@ -74,7 +74,7 @@ echo "Creating the systemd service"
# generate random id # generate random id
# shellcheck disable=SC2002 # shellcheck disable=SC2002
id=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1) id=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
bash -c "cat <<EOF > /etc/systemd/system/server-status-client.service bash -c "cat <<EOF > /etc/systemd/system/server-status-client.service
[Unit] [Unit]

View File

@ -10,24 +10,6 @@ from server_status.timezone import get_timezone
excluded_partition_prefix = ("/var", "/boot", "/run", "/proc", "/sys", "/dev", "/tmp", "/snap") excluded_partition_prefix = ("/var", "/boot", "/run", "/proc", "/sys", "/dev", "/tmp", "/snap")
os_name = "" # linux下为发行版名称windows下为Windows
os_version = "" # linux下为发行版版本windows下为Windows版本
try:
# read /etc/os-release
with open("/etc/os-release") as f:
os_release = f.read()
# 找到NAME=和VERSION=的行
for line in os_release.split("\n"):
if line.startswith("NAME="):
os_name = line.split("=")[1].replace('"', '')
elif line.startswith("VERSION_ID="):
os_version = line.split("=")[1].replace('"', '')
except FileNotFoundError:
os_name = platform.system()
os_version = platform.release()
print("Current OS:", os_name, os_version)
def log(*args): def log(*args):
# 在输出前加上时间 # 在输出前加上时间
@ -47,7 +29,6 @@ def get_network_speed(interval) -> tuple[int, int]:
class Hardware: class Hardware:
os_release: str = ""
mem_total: int = psutil.virtual_memory().total mem_total: int = psutil.virtual_memory().total
mem_used: int = psutil.virtual_memory().used mem_used: int = psutil.virtual_memory().used
@ -204,10 +185,10 @@ class Client:
"id": self.client_id, "id": self.client_id,
"name": self.name, "name": self.name,
"os": { "os": {
"name": platform.system(), # 系统类型 linux|windows|darwin "name": platform.system(),
"version": os_name + os_version, # 系统版本复杂描述 #1 SMP PREEMPT_DYNAMIC Fri Sep 13 10:42:50 UTC 2024 (5c05eeb) "version": platform.version(),
"machine": platform.machine(), # 机器类型 x86_64 "machine": platform.machine(),
"release": os_version, # 系统版本 "release": platform.release(),
}, },
"labels": self.labels, "labels": self.labels,
"location": self.location, "location": self.location,