Files
assist/src/analytics/__pycache__/monitor_service.cpython-310.pyc

60 lines
7.7 KiB
Plaintext
Raw Normal View History

o
<00><>5i<35>"<00>@stdZddlZddlZddlZddlmZmZmZddlmZm Z ddl
m Z m Z m Z mZe<01>e<10>ZGdd<08>d<08>ZdS) uE
TSP助手监控服务
实时监控系统状态,执行预警检查
<EFBFBD>N)<03>Dict<63>Any<6E>List)<02>datetime<6D> timedelta<74>)<04> AlertSystem<65> AlertRule<6C>
AlertLevel<EFBFBD> AlertTypec@s<>eZdZdZdd<03>Zdd<05>Zdd<07>Zdd <09>Zd
ee e
ffd d <0C>Z d
ee e
ffd d<0E>Z d
ee e
ffdd<10>Z d
ee e
ffdd<12>Zd
ee e
ffdd<14>Zd
ee e
fde fdd<17>Zd
ee e
ffdd<19>Zdd<1B>Zdd<1D>Zdd<1F>Zd ee e
ffd!d"<22>Zd#eee e
fd$ee e
fd efd%d&<26>Zd'ed e fd(d)<29>Zd*ed efd+d,<2C>Zd-e d efd.d/<2F>Zd-e d efd0d1<64>Zd ee e
ffd2d3<64>Zd4S)5<>MonitorServiceu 监控服务cCst<00>|_d|_d|_d|_dS)NF<4E><)r<00> alert_system<65>
is_running<EFBFBD>monitor_thread<61>check_interval<61><01>self<6C>r<00>-/root/assist/src/analytics/monitor_service.py<70>__init__s
zMonitorService.__init__cCsD|jr
t<01>d<01>dSd|_tj|jdd<04>|_|j<06><07>t<01>d<05>dS)u启动监控服务u监控服务已在运行NT)<02>target<65>daemonu监控服务已启动) r<00>logger<65>warning<6E> threading<6E>Thread<61> _monitor_loopr<00>start<72>inforrrrrs

zMonitorService.startcCs(d|_|jr |jjdd<03>t<03>d<04>dS)u停止监控服务F<E58AA1>)<01>timeoutu监控服务已停止N)rr<00>joinrrrrrr<00>stop&szMonitorService.stopc
Cs<>|jrLz$|j<01><02>}|r t<03>dt|<01><01>d<02><03>|D]}|<00>|<02>qt<07>|j <09>Wnt
yF}zt<03> d|<03><00><02>t<07>d<04>WYd}~nd}~ww|jsdSdS)u 监控循环u触发 u
个预警u监控循环异常: <20>
N) rr<00>check_all_rulesrr<00>len<65> _handle_alert<72>time<6D>sleepr<00> Exception<6F>error)r<00>triggered_alerts<74>alert<72>errrr-s
 <08><02><0E>zMonitorService._monitor_loopr-c
Cs<>z<t<00>d|d<00><00><02>|ddkr|<00>|<01>WdS|ddkr'|<00>|<01>WdS|ddkr5|<00>|<01>WdS|<00>|<01>WdStyW}zt<00>d|<02><00><02>WYd}~dSd}~ww) u 处理预警u预警触发: <20>message<67>level<65>criticalr+ru处理预警失败: N)rr<00>_handle_critical_alert<72>_handle_error_alert<72>_handle_warning_alert<72>_handle_info_alertr*r+)rr-r.rrrr'@s   <08><02>zMonitorService._handle_alertcCs.|<00>|d<01>t<01>d|d<00><00><02>|<00>|<01>dS)u处理严重预警u紧急u严重预警: r/N)<04>_send_notificationrr1<00>_attempt_auto_recovery<72>rr-rrrr2Ss z%MonitorService._handle_critical_alertcC<00>$|<00>|d<01>t<01>d|d<00><00><02>dS)u处理错误预警u错误u错误预警: r/N)r6rr+r8rrrr3^<00> z"MonitorService._handle_error_alertcCr9)u处理警告预警u警告u警告预警: r/N)r6rrr8rrrr4fr:z$MonitorService._handle_warning_alertcCst<00>d|d<00><00><02>dS)u处理信息预警u信息预警: r/N<>rrr8rrrr5nsz!MonitorService._handle_info_alertr0cCs.||d|d|dd<04>}t<00>d|<03><00><02>dS)u 发送通知r/<00> timestamp<6D> rule_name)r0r/r<r=u发送通知: Nr;)rr-r0<00> notificationrrrr6ss <06>z!MonitorService._send_notificationc
Cs<>z(|d}|dkr|<00><00>WdS|dkr|<00><01>WdS|dkr&|<00><02>WdSWdStyC}zt<04>d|<03><00><02>WYd}~dSd}~ww)u尝试自动恢复r=u内存使用预警u错误率预警u响应时间预警u自动恢复失败: N)<06>_cleanup_memory<72>_restart_services<65>_optimize_performancer*rr+)rr-r=r.rrrr7<00>s<06><08><02>z%MonitorService._attempt_auto_recoveryc
CsXzddl}|<01><01>t<02>d<03>WdSty+}zt<02>d|<02><00><02>WYd}~dSd}~ww)u 清理内存rNu执行内存清理u内存清理失败: )<06>gc<67>collectrrr*r+)rrBr.rrrr?<00>s<08><02>zMonitorService._cleanup_memoryc
C<00>Hzt<00>d<01>WdSty#}zt<00>d|<01><00><02>WYd}~dSd}~ww)u 重启服务u尝试重启服务u重启服务失败: N<>rrr*r+<00>rr.rrrr@<00><00> <08><02>z MonitorService._restart_servicesc
CrD)u 优化性能u尝试优化性能u性能优化失败: NrErFrrrrA<00>rGz$MonitorService._optimize_performance<63>returnc
Cs<>z(|j<00><01>}|j<00><02>}|<00>||<02>}||<00>|<03>t|<01>||jrdndt<07><08><00> <09>d<03>WSt
yH}zt <0B> d|<04><00><02>dt |<04>iWYd}~Sd}~ww)u获取系统健康状态<E78AB6>running<6E>stopped)<06> health_score<72>status<75> active_alerts<74>alert_statistics<63>monitor_status<75>
last_checku 获取系统健康状态失败: r+N)r<00>get_active_alerts<74>get_alert_statistics<63>_calculate_health_score<72>_get_health_statusr&rr<00>now<6F> isoformatr*rr+<00>str)rrM<00> alert_statsrKr.rrr<00>get_system_health<74>s 

  
<08> <08><02>z MonitorService.get_system_healthrMrXc
Cs<>z5d}|D]'}|ddkr|d8}q|ddkr|d8}q|ddkr(|d8}q|d 8}qtd
td |<03><02>WStyP}zt<03>d |<05><00><02>WYd }~dSd }~ww)u计算健康分数gY@r0r1<00>r+r$rr rr<00>du计算健康分数失败: NgI@)<05>max<61>minr*rr+)rrMrX<00>
base_scorer-r.rrrrS<00>s  
 
 

<08><02>z&MonitorService._calculate_health_scorerKcCs4|dkrdS|dkr dS|dkrdS|dkrdSd S)
u获取健康状态<E78AB6>Z<00> excellent<6E>F<00>good<6F>2<00>fair<69><00>poorr1r)rrKrrrrT<00>sz!MonitorService._get_health_status<75>rulecC<00> |j<00>|<01>S)u添加自定义规则)r<00>add_custom_rule)rrgrrrri<00><00> zMonitorService.add_custom_ruler=cKs|jj|fi|<02><01>S)u 更新规则)r<00> update_rule)rr=<00>kwargsrrrrk<00>szMonitorService.update_rulecCrh)u 删除规则)r<00> delete_rule)rr=rrrrm<00>rjzMonitorService.delete_rulecCsdd<02>|jj<01><02>D<00>S)u获取所有规则c Ss<i|]\}}||j|j|jj|jj|j|j|j|jd<00><08>qS))<08>name<6D> description<6F>
alert_typer0<00> threshold<6C>enabledr<00>cooldown) rnrorp<00>valuer0rqrrrrs)<03>.0rnrgrrr<00>
<dictcomp><3E>s <02><04><06>z,MonitorService.get_rules.<locals>.<dictcomp>)r<00>rules<65>itemsrrrr<00> get_rules<65>s
<06>zMonitorService.get_rulesN) <20>__name__<5F>
__module__<EFBFBD> __qualname__<5F>__doc__rrr#rrrWrr'r2r3r4r5r6r7r?r@rArYr<00>floatrSrTr <00>boolrirkrmryrrrrr s.   * r )r}<00>loggingrr(<00>typingrrrrrrrr r
r <00> getLoggerrzrr rrrr<00><module>s