From ba444252c9ff814a8537037609ae69aa4c463a5b Mon Sep 17 00:00:00 2001 From: bboysoul Date: Fri, 12 Apr 2024 15:52:11 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E4=BC=98=E5=8C=96=E9=83=A8=E7=BD=B2yaml?= =?UTF-8?q?=202.=20=E6=9B=B4=E6=96=B0readme.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 19 +++++++++++++------ deploymet.yaml | 14 +++++++++----- docker-compose.yaml | 6 ++++-- main.py | 4 ++-- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 4bfc53d..8c7b2d7 100644 --- a/README.md +++ b/README.md @@ -21,20 +21,21 @@ docker-compose up -d ``` 或者你可以使用 k8s 来运行 Telemonitor: - + ```bash kubectl apply -f deployment.yaml ``` - 下面是 Telemonitor 的环境变量: - `TG_API_TOKEN`: 你的 Telegram bot 的 API token。 - `TG_CHAT_ID`: 你希望接收警告的 Telegram chat ID。 -- `CPU_PERCENT`: CPU 使用率的阈值,超过这个阈值时,Telemonitor 会发送警告。 -- `MEMORY_PERCENT`: 内存使用率的阈值,超过这个阈值时,Telemonitor 会发送警告。 -- `DISK_PERCENT`: 磁盘使用率的阈值,超过这个阈值时,Telemonitor 会发送警告。 -- `MONITOR_INTERVAL`: 监控的间隔时间(秒)。 +- `TG_API_BASE_URL`: Telegram API 的基础 URL,默认值为 `https://api.telegram.org`. +- `CPU_PERCENT`: CPU 使用率的阈值,超过这个阈值时,Telemonitor 会发送警告,默认值为 80。 +- `MEMORY_PERCENT`: 内存使用率的阈值,超过这个阈值时,Telemonitor 会发送警告,默认值为 80。 +- `DISK_PERCENT`: 磁盘使用率的阈值,超过这个阈值时,Telemonitor 会发送警告,默认值为 80。 +- `MONITOR_INTERVAL`: 监控的间隔时间(秒),默认值为 60。 +- `DISK_PATH`: 磁盘的路径,默认值为 `/host`。 下面是机器人的命令: @@ -42,6 +43,12 @@ kubectl apply -f deployment.yaml - /help - 获取帮助 - /status - 获取系统状态 +### 如果你不能访问Telegram API + +你可以使用下面项目创建一个 api 代理,并且修改环境变量 TG_API_BASE_URL + +[teleproxy](https://github.com/bboysoulcn/teleproxy) + ### 效果展示 ![](./images/img1.webp) diff --git a/deploymet.yaml b/deploymet.yaml index 94e6114..ccd4175 100644 --- a/deploymet.yaml +++ b/deploymet.yaml @@ -1,24 +1,24 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: serverstatus + name: telemonitor namespace: app spec: replicas: 1 selector: matchLabels: - app: serverstatus + app: telemonitor template: metadata: labels: - app: serverstatus + app: telemonitor spec: hostNetwork: true hostPID: true containers: - - name: serverstatus + - name: telemonitor image: ghcr.io/bboysoulcn/telemonitor:latest - pullPolicy: Always + imagePullPolicy: Always env: - name: TG_CHAT_ID value: your_chat_id @@ -32,6 +32,10 @@ spec: value: "80" - name: MONITOR_INTERVAL value: "300" + - name: TG_API_BASE_URL + value: "https://api.telegram.org" + - name: DISK_PATH + value: "/host" volumeMounts: - name: localtime mountPath: /etc/localtime diff --git a/docker-compose.yaml b/docker-compose.yaml index 2db8c1b..d55f00e 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,9 +1,9 @@ version: '3' services: - serverstatus: + telemonitor: image: ghcr.io/bboysoulcn/telemonitor:latest restart: always - container_name: serverstatus + container_name: telemonitor environment: - TG_CHAT_ID=your_chat_id - TG_API_TOKEN=your_api_token @@ -11,6 +11,8 @@ services: - MEMORY_PERCENT=80 - DISK_PERCENT=80 - MONITOR_INTERVAL=300 + - TG_API_BASE_URL=https://api.telegram.org + - DISK_PATH=/host network_mode: host pid: host volumes: diff --git a/main.py b/main.py index 0d62091..8fc00e5 100644 --- a/main.py +++ b/main.py @@ -29,7 +29,7 @@ async def monitor_memory_usage(context: ContextTypes.DEFAULT_TYPE): async def monitor_disk_usage(context: ContextTypes.DEFAULT_TYPE): - disk_path = os.environ['DISK_PATH'] + disk_path = os.environ.get('DISK_PATH', '/host') disk_percent = int(context.job.data) disk_info = psutil.disk_usage(disk_path) disk_usage = int(disk_info.percent) @@ -40,7 +40,7 @@ async def monitor_disk_usage(context: ContextTypes.DEFAULT_TYPE): def get_systeminfo(): - disk_path = os.environ['DISK_PATH'] + disk_path = os.environ.get('DISK_PATH', '/host') # Get CPU usage cpu_usage = psutil.cpu_percent(interval=1)