관리-도구
편집 파일: fault_detector.cpython-311.pyc
� b��fR � �t � d Z ddlZddlZddlmZmZ ddlmZ ddlmZm Z ddl mZmZm Z G d� d� � ZdS ) z[ This module contains FaultDetector class, aimed to track throttling for incoming requests � N)�datetime� timedelta)�RLock)�Tuple�Any)� drop_after�check_period�throttling_thresholdc �@ � e Zd ZdZd� Zdededeeef fd�Z e defd�� � Ze defd�� � Z e defd �� � Ze defd �� � Zededefd�� � Zd edefd�Zdededdfd�Zdeddfd�Zdededeeef fd�Zdd�Zdd�Zdefd�ZdS )� FaultDetectorz Fault Detector class c � � t j d� � | _ t � � | _ t � � | _ d| _ d S )N�fault_detectorz$/usr/share/alt-php-xray/flush.latest)�logging� getLogger�logger�dict�throttling_statr �lock�time_marker_file��selfs �P/opt/cloudlinux/venv/lib64/python3.11/site-packages/xray/agent/fault_detector.py�__init__zFaultDetector.__init__ s: � ��'�(8�9�9���#�v�v����G�G�� � F����� �t_key� cpu_value�returnc �� � | j 5 | j | \ }}| � ||� � \ }}| � |� � n# t $ r d\ }}Y nw xY wddd� � n# 1 swxY w Y ||fS )z) Perform fault detection )Fr N)r r �_was_throttled_since�_flush_entry�KeyError)r r r � saved_cpu�_�hitting_limits�throttled_times r �__call__zFaultDetector.__call__ s� � � �Y� )� )� )�#�3�E�:�� �1� 26�1J�1J��y�2*� 2*�.����!�!�%�(�(�(�(�� � :� :� :�19�.����� :���� )� )� )� )� )� )� )� )� )� )� )���� )� )� )� )� �~�-�-s3 �A*�A �/A*� A�A*�A�A*�*A.�1A.c �B � t t j � � � � S )z( Current Unix timestamp )�int�timer s r � timestampzFaultDetector.timestamp/ s � � �4�9�;�;���r c �6 � | � t � � S )z8 Drop after value as datetime.timedelta )�timedelta_in_minutesr r s r �_drop_afterzFaultDetector._drop_after6 s � � �(�(��4�4�4r c �6 � | � t � � S )z: Check period value as datetime.timedelta )r, r r s r � _check_periodzFaultDetector._check_period= s � � �(�(��6�6�6r c � � t | j � � 5 }t |� � � � � � � � }ddd� � n# 1 swxY w Y | � |� � | j k S # t t f$ r7 | j 5 | � � � ddd� � n# 1 swxY w Y Y dS w xY w)ze If throttling_stat should be flushed right now regarding check period value NF)�openr r( �read�strip� current_deltar/ �OSError� ValueErrorr �_update_latest_flush)r �latest_info�latest_flush_times r �should_flushzFaultDetector.should_flushD sS � � ��d�+�,�,� D��$'��(8�(8�(:�(:�(@�(@�(B�(B�$C�$C�!� D� D� D� D� D� D� D� D� D� D� D���� D� D� D� D��%�%�&7�8�8�4�;M�M�M����$� � � ��� ,� ,��)�)�+�+�+� ,� ,� ,� ,� ,� ,� ,� ,� ,� ,� ,���� ,� ,� ,� ,��5�5� ���sX �A? �4A� A? �A�A? �A� A? �?C�B8�,C�8B< �<C�?B< � C�C�minsc �"