commit
25e9eb2e12
@ -0,0 +1,52 @@
|
||||
# Copyright (c) 2014, 2024, Oracle and/or its affiliates.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License, version 2.0,
|
||||
# as published by the Free Software Foundation.
|
||||
#
|
||||
# This program is designed to work with certain software (including
|
||||
# but not limited to OpenSSL) that is licensed under separate terms,
|
||||
# as designated in a particular file or component or in included license
|
||||
# documentation. The authors of MySQL hereby grant you an additional
|
||||
# permission to link the program and your derivative works with the
|
||||
# separately licensed software that they have either included with
|
||||
# the program or referenced in the documentation.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License, version 2.0, for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
#
|
||||
# The MySQL Server configuration file.
|
||||
#
|
||||
# For explanations see
|
||||
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
|
||||
|
||||
[mysqld]
|
||||
pid-file = /var/run/mysqld/mysqld.pid
|
||||
socket = /var/run/mysqld/mysqld.sock
|
||||
datadir = /var/lib/mysql
|
||||
log-error = /var/log/mysql/error.log
|
||||
|
||||
bind-address = 0.0.0.0
|
||||
port = 3344
|
||||
|
||||
server_id=130
|
||||
binlog_format=row
|
||||
default_storage_engine=InnoDB
|
||||
innodb_file_per_table=1
|
||||
innodb_autoinc_lock_mode=2
|
||||
|
||||
wsrep_on=ON
|
||||
wsrep_provider=/usr/lib/galera/libgalera_smm.so
|
||||
wsrep_cluster_name="YaneiGaleraCluster"
|
||||
wsrep_cluster_address="gcomm://192.168.100.129,129.168.100.128"
|
||||
wsrep_node_name="node_130"
|
||||
wsrep_node_address="192.168.100.130"
|
||||
wsrep_sst_method=rsync
|
||||
wsrep_sst_auth=root:yanei!23
|
@ -0,0 +1,85 @@
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
|
||||
import psutil
|
||||
|
||||
|
||||
# 定义状态
|
||||
NORMAL = 'NORMAL'
|
||||
ABNORMAL = 'ABNORMAL'
|
||||
|
||||
# 定义状态持续时间阈值(秒)
|
||||
NORMAL_THRESHOLD = 10 * 60
|
||||
ABNORMAL_THRESHOLD = 30
|
||||
|
||||
|
||||
def get_process(name="mysqld"):
|
||||
|
||||
for proc in psutil.process_iter():
|
||||
if proc.name() == name:
|
||||
return proc
|
||||
return None
|
||||
|
||||
|
||||
# 定义状态机类
|
||||
class ProcessMonitorStateMachine:
|
||||
def __init__(self, process_name):
|
||||
self.process_name = process_name
|
||||
self.state = NORMAL
|
||||
self.last_state_change_time = time.time()
|
||||
|
||||
def check_process(self):
|
||||
"""检查进程是否存在,并返回其状态"""
|
||||
process = get_process(name=self.process_name)
|
||||
if process:
|
||||
return NORMAL
|
||||
else:
|
||||
return ABNORMAL
|
||||
|
||||
def process_event(self):
|
||||
"""处理事件,根据事件类型切换状态"""
|
||||
current_time = time.time()
|
||||
|
||||
process_state = self.check_process()
|
||||
print(f"当前状态:{process_state} {current_time}")
|
||||
if process_state != self.state:
|
||||
self.state = process_state
|
||||
self.last_state_change_time = current_time
|
||||
print(f"状态变更为: {self.state}")
|
||||
if self.state == ABNORMAL:
|
||||
self.handle_abnormal_timeout()
|
||||
|
||||
else:
|
||||
if self.state == NORMAL and (current_time - self.last_state_change_time) > NORMAL_THRESHOLD:
|
||||
self.handle_normal_timeout()
|
||||
self.last_state_change_time = current_time
|
||||
|
||||
elif self.state == ABNORMAL and (current_time - self.last_state_change_time) > ABNORMAL_THRESHOLD:
|
||||
self.handle_abnormal_timeout()
|
||||
self.last_state_change_time = current_time
|
||||
|
||||
def handle_normal_timeout(self):
|
||||
"""处理正常状态超时的指令"""
|
||||
print("程序已正常,退出监控")
|
||||
sys.exit(0)
|
||||
|
||||
def handle_abnormal_timeout(self):
|
||||
"""处理异常状态超时的指令"""
|
||||
print("异常状态持续时间过长,执行特定指令。")
|
||||
os.system("/usr/bin/mysqld_bootstrap")
|
||||
|
||||
|
||||
# 使用状态机监控进程
|
||||
def main():
|
||||
process_name = "mysqld" # 指定要监控的进程名称
|
||||
monitor = ProcessMonitorStateMachine(process_name)
|
||||
print("start...")
|
||||
# 模拟定时检查进程状态
|
||||
while True:
|
||||
monitor.process_event()
|
||||
time.sleep(10) # 每10秒检查一次
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in new issue