heartbeat/README.md

98 lines
2.9 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# heartbeat
用python写的简易心跳工具配合Uptime-kuma的被动监控功能当然你也可以自己实现服务端实现监测PC客户端的运行情况。
## 运行效果
通过访问连接服务端会实现被动检测。同时本地访问结果会回显记录在heartbeat.log如果服务端异常可以通过返回的代码进行故障排查。
## 使用方法
### 下载程序:
1. 下载[最新的版本](https://github.com/yshtcn/heartbeat/releases)。
2. 解压缩到任意目录
### 编辑配置文件:
运行前,记得打开把[config.Exsample.ini配置文件](https://github.com/yshtcn/heartbeat/blob/main/config.Exsample.ini)复制一份改名为config.ini并打开配置接收心跳包的服务器地址。
如果不存在config.ini直接运行程序程序会将config.Exsample.ini范例配置自动复制一份。
### 日志文件
心跳日志会存放在heartbeat.log包括时间和返回值。例如下面是一个返回200正常值的日志
```
2023-08-04 11:46:15.306916 Ping: 8ms. Final URL: http://example.com/heartbeat?ping=8. Response status code: 200
```
## 执行python源代码
如果你需要直接使用源代码,可能需要用到以下几个步骤:
### 确保安装Python和必要的python库
可以从[这里下载最新的python环境](https://python.org/downloads/release/)。
使用命令行执行以下命令:
```
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pystray pillow requests configparser PySocks
```
如果希望自动检测python安装及必要的库支持可以把以下内容保存为bat文件执行。
```
@echo off
cd /d %~dp0
setlocal enabledelayedexpansion
:: 检查pip
for /f "tokens=1" %%i in ('pip --version 2^>^&1 ^| findstr /C:"pip"') do (
set PIPVER=%%i
)
if "!PIPVER!" == "pip" (
echo Pip detected!
) else (
echo Error: pip is not installed.
pause
exit /b 1
)
:: 检查python
for /f "tokens=1" %%h in ('python --version 2^>^&1') do (
set PYVER2=%%h
)
if "!PYVER2!" == "Python" (
echo Python detected!
) else (
echo Error: Python is not installed.
pause
exit /b 1
)
endlocal
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pystray pillow requests configparser PySocks
@echo All Done
pause
```
### 执行批处理
每次使用py命令并不方便可以把以下内容保存为bat文件。
```
@echo off
@echo heartbeat start
cd /d %~dp0
py heartbeat.py
pause
```
如果希望后台静默运行可以把以下内容保存为bat文件执行。
```
@echo off
cd /d %~dp0
start pythonw heartbeat.py
```
### 打包成exe
1. 根据你的需要修改heartbeat_pyinstaller.bat,特别是如果你不希望自动更新你的pyinstaller
2. 执行heartbeat_pyinstaller.bat。
## 授权信息
项目地址: https://github.com/yshtcn/heartbeat
项目授权方式:[Apache-2.0 license](https://github.com/yshtcn/heartbeat/blob/main/LICENSE)