Skip to content

Commit

Permalink
1. 优化部署yaml
Browse files Browse the repository at this point in the history
2. 更新readme.md
  • Loading branch information
bboysoulcn committed Apr 12, 2024
1 parent 9aaedfa commit ba44425
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,34 @@ 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`

下面是机器人的命令:

- /start - 获取帮助
- /help - 获取帮助
- /status - 获取系统状态

### 如果你不能访问Telegram API

你可以使用下面项目创建一个 api 代理,并且修改环境变量 TG_API_BASE_URL

[teleproxy](https://github.com/bboysoulcn/teleproxy)

### 效果展示

![](./images/img1.webp)
Expand Down
14 changes: 9 additions & 5 deletions deploymet.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
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
- CPU_PERCENT=80
- 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:
Expand Down
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down

0 comments on commit ba44425

Please sign in to comment.