python工程,kafka消息对接转换成配置文件并完成类似看门狗监控linux系统进程,定期清理日志
wangrong
2025-04-05 88f9100edcba9581214c1a0acc23cd33a821a9c6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
1. 主程序main, 读取主程序所在目录下配置文件msg_config.ini
2. msg_config.ini文件中需配置:PROCESSES下的监听进程定义的文件路径
3. 程序主要逻辑如下:
    a. 读取msg_config.ini
    b. 读取kafka配置,并连接server和订阅TRANSFER下的消息
    c. 读取PROCESSES指定的进程监测文件,并检测,每固定时间检测进程是否正常,非启动状态会进行启动
4. deploy commands: pyinstaller --onefile --noconsole main.py
 
 
msg_config内容示例如下:
 
[KAFKA]
server = 192.168.0.79:9092
topics = vp_ba_jam, vp_ba_stop, vp_ba_crossline, vp_tracking
public_topic = vp_ba_result
 
[OUTPUT]
file = kafka_messages.txt
 
[TRANSFER]
topic_1 = cameralist
channel_size = 12
actions = JAM,STOP,WRONG_WAY,CROWD_GATHERING,PERSON_FALLDOWN,FIRE
outfile = textjson/config.json
full_actions = JAM,STOP,WRONG_WAY,CROWD_GATHERING,PERSON_FALLDOWN,FIRE,JUNK_STACK,SMOCKING,BARRIER_GATE
 
[PROCESSES]
process_file = textjson/process_list.json
 
[SEND_MSG]
run_send = true
send_topics = cameralist
send_interval = 300
json_file = textjson/cameralist.json
 
 
process_list配置文件示例如下:
{
    "process_list": [
        {"program_path": "gnome-terminal", "commands": "top -d 1", "process_name": "top0"},
        {"program_path": "gnome-terminal", "commands": "top -p 1234", "process_name": "top1"},
        {"program_path": "gnome-terminal", "commands": "top -u wr", "process_name": "top2"},   
        {"program_path": "gnome-terminal", "commands": "top -H", "process_name": "top3"} 
    ],
    "interval_monitor_seconds": 10
}