HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/__pycache__/win_pdh.cpython-310.pyc
o

�N�g\7�@s�dZddlZddlZddlZddlmZzddlZddlZdZ	Wne
y+dZ	Ynwe�e�Z
dZdd�ZGd	d
�d
�Zdd�Zd
d�Zdd�Zdd�Zddd�Zdd�Zdd�ZdS)a&
Salt Util for getting system information with the Performance Data Helper (pdh).
Counter information is gathered from current activity or log files.

Usage:

.. code-block:: python

    import salt.utils.win_pdh

    # Get a list of Counter objects
    salt.utils.win_pdh.list_objects()

    # Get a list of ``Processor`` instances
    salt.utils.win_pdh.list_instances('Processor')

    # Get a list of ``Processor`` counters
    salt.utils.win_pdh.list_counters('Processor')

    # Get the value of a single counter
    # \Processor(*)\% Processor Time
    salt.utils.win_pdh.get_counter('Processor', '*', '% Processor Time')

    # Get the values of multiple counters
    counter_list = [('Processor', '*', '% Processor Time'),
                    ('System', None, 'Context Switches/sec'),
                    ('Memory', None, 'Pages/sec'),
                    ('Server Work Queues', '*', 'Queue Length')]
    salt.utils.win_pdh.get_counters(counter_list)

    # Get all counters for the Processor object
    salt.utils.win_pdh.get_all_counters('Processor')
�N)�CommandExecutionErrorTFZpdhcCstjj��sdStsdStS)z8
    Only works on Windows systems with the PyWin32
    )Fz$salt.utils.win_pdh: Requires Windows)Fz,salt.utils.win_pdh: Missing required modules)�salt�utils�platformZ
is_windows�HAS_WINDOWS_MODULES�__virtualname__�rr�F/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/win_pdh.py�__virtual__;s
r
c@s�eZdZdZdZdZdZdZdZdZ	dZ
dZdZd	Z
d
ZdZd	Zd
ZdZdZd
ZdZdZd	ZdZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#dd�Z$e%e$�Z$dd�Z&dd�Z'dd �Z(d!d"�Z)d#d$�Z*d%d&�Z+d'S)(�CounterzU
    Counter object
    Has enumerations and functions for working with counters
    r�iiiiiiiiiiiii i@i�iiii i0i@cCsDt�d||d||fd�}t�|�dkrt|||||�Std|����)a�
        Makes a fully resolved counter path. Counter names are formatted like
        this:

        ``\Processor(*)\% Processor Time``

        The above breaks down like this:

            obj = 'Processor'
            instance = '*'
            counter = '% Processor Time'

        Args:

            obj (str):
                The top level object

            instance (str):
                The instance of the object

            instance_index (int):
                The index of the instance. Can usually be 0

            counter (str):
                The name of the counter

        Returns:
            Counter: A Counter object with the path if valid

        Raises:
            CommandExecutionError: If the path is invalid
        NrzInvalid counter specified: )�win32pdhZMakeCounterPathZValidatePathrr)�obj�instance�instance_index�counter�pathrrr	�
build_counter�s!�zCounter.build_countercCs4||_||_||_||_||_d|_d|_d|_dS�N)rrr�indexr�handle�info�type)�selfrrrrrrrr	�__init__�s
zCounter.__init__cCst�||j�|_dS)z�
        Add the current path to the query

        Args:
            query (obj):
                The handle to the query to add the counter
        N)r
Z
AddCounterrr)r�queryrrr	�add_to_query�szCounter.add_to_querycCs�|jsDt�|jd�}|d|d|d|d|d|d|d|dd|dd|dd|dd|dd|dd|d	d
�|_|jS)z�
        Get information about the counter

        .. note::
            GetCounterInfo sometimes crashes in the wrapper code. Fewer crashes
            if this is called after sampling data.
        r��������)r�versionZscaleZ
default_scaleZ	user_dataZquery_user_data�	full_pathZmachine_nameZobject_nameZ
instance_nameZparent_instancer�counter_nameZexplain_text)rr
ZGetCounterInfor)rZcirrr	�get_info�s$





�zCounter.get_infocCst�|jtj�\}}||_|S)z`
        Return the counter value

        Returns:
            long: The counter value
        )r
ZGetFormattedCounterValuerZPDH_FMT_DOUBLEr)rZcounter_type�valuerrr	r)�s
�z
Counter.valuecCsT|��d}g}t|�D]}|�d�r't||�}|r'||@r'|�|dd��q|S)z~
        Returns the names of the flags that are set in the Type field

        It can be used to format the counter.
        rZPERF_r!N)r(�dir�
startswith�getattr�append)rrZ	type_list�member�bitrrr	�type_string�s

�zCounter.type_stringcCs|jSr)r)rrrr	�__str__�szCounter.__str__N),�__name__�
__module__�__qualname__�__doc__ZPERF_SIZE_DWORDZPERF_SIZE_LARGEZPERF_SIZE_ZEROZPERF_SIZE_VARIABLE_LENZPERF_TYPE_NUMBERZPERF_TYPE_COUNTERZPERF_TYPE_TEXTZPERF_TYPE_ZEROZPERF_NUMBER_HEXZPERF_NUMBER_DECIMALZPERF_NUMBER_DEC_1000ZPERF_COUNTER_VALUEZPERF_COUNTER_RATEZPERF_COUNTER_FRACTIONZPERF_COUNTER_BASEZPERF_COUNTER_ELAPSEDZPERF_COUNTER_QUEUE_LENZPERF_COUNTER_HISTOGRAMZPERF_TEXT_UNICODEZPERF_TEXT_ASCIIZPERF_TIMER_TICKZPERF_TIMER_100NSZPERF_OBJECT_TIMERZPERF_DELTA_COUNTERZPERF_DELTA_BASEZPERF_INVERSE_COUNTERZPERF_MULTI_COUNTERZPERF_DISPLAY_NO_SUFFIXZPERF_DISPLAY_PER_SECZPERF_DISPLAY_PERCENTZPERF_DISPLAY_SECONDSZPERF_DISPLAY_NO_SHOWr�staticmethodrrr(r)r0r1rrrr	rHsT(


rcCstt�dddd��S)zu
    Get a list of available counter objects on the system

    Returns:
        list: A list of counter objects
    N���r)�sortedr
ZEnumObjectsrrrr	�list_objects�sr9cCst�dd|dd�dS)a#
    Get a list of counters available for the object

    Args:
        obj (str):
            The name of the counter object. You can get a list of valid names
            using the ``list_objects`` function

    Returns:
        list: A list of counters available to the passed object
    Nr7r�r
�EnumObjectItems�rrrr	�
list_counters�r=cCst�dd|dd�dS)a%
    Get a list of instances available for the object

    Args:
        obj (str):
            The name of the counter object. You can get a list of valid names
            using the ``list_objects`` function

    Returns:
        list: A list of instances available to the passed object
    Nr7rrr:r<rrr	�list_instancesr>r?cCsrg}d}|D]0\}}}zt�||||�}|d7}|�|�Wqty6}zt�|j�WYd}~qd}~ww|S)a�
    Create a list of Counter objects to be used in the pdh query

    Args:
        counter_list (list):
            A list of tuples containing counter information. Each tuple should
            contain the object, instance, and counter name. For example, to
            get the ``% Processor Time`` counter for all Processors on the
            system (``\Processor(*)\% Processor Time``) you would pass a tuple
            like this:

            ```
            counter_list = [('Processor', '*', '% Processor Time')]
            ```

            If there is no ``instance`` for the counter, pass ``None``

            Multiple counters can be passed like so:

            ```
            counter_list = [('Processor', '*', '% Processor Time'),
                            ('System', None, 'Context Switches/sec')]
            ```

            .. note::
                Invalid counters are ignored

    Returns:
        list: A list of Counter objects
    rrN)rrr-r�log�debug�strerror)�counter_list�countersrrrr'r�excrrr	�build_counter_list&s��rFcCs�t�dd|dd�\}}|dur|}t|t�s|g}g}|D]!}|D]}|��dkr+dn|}|�|||f�q!|�|d|f�q|rEt|�SiS)a�
    Get the values for all counters available to a Counter object

    Args:

        obj (str):
            The name of the counter object. You can get a list of valid names
            using the ``list_objects`` function

        instance_list (list):
            A list of instances to return. Use this to narrow down the counters
            that are returned.

            .. note::
                ``_Total`` is returned as ``*``
    Nr7rZ_total�*)r
r;�
isinstance�list�lowerr-�get_counters)rZ
instance_listrDZinstances_availrCrrrrr	�get_all_countersSs
rLcCst|t�s	td��zyzOt��}t|�}|D]}|�|�qt�|�t�	d�t�|�i}|D]'}z|�
|j|��i�Wq0t
jyW}z|jdkrRWYd}~q0�d}~wwWn!t
jyz}z|jdkruiWYd}~Wt�|�S�d}~wwWt�|�|St�|�w)z�
    Get the values for the passes list of counters

    Args:
        counter_list (list):
            A list of counters to lookup

    Returns:
        dict: A dictionary of counters and their values
    z%counter_list must be a list of tuplesrzNo data to return.N)rHrIrr
Z	OpenQueryrFrZCollectQueryData�time�sleep�updaterr)�
pywintypes�errorrBZ
CloseQuery)rCrrDr�retrErrr	rKws@




���
����
�rKcCst|||fg�S)a,
    Get the value of a single counter

    Args:

        obj (str):
            The name of the counter object. You can get a list of valid names
            using the ``list_objects`` function

        instance (str):
            The counter instance you wish to return. Get a list of instances
            using the ``list_instances`` function

            .. note::
                ``_Total`` is returned as ``*``

        counter (str):
            The name of the counter. Get a list of counters using the
            ``list_counters`` function
    )rK)rrrrrr	�get_counter�srSr)r5�loggingrMZsalt.utils.platformrZsalt.exceptionsrrPr
r�ImportError�	getLogger�__file__r@rr
rr9r=r?rFrLrKrSrrrr	�<module>s0%�

7

-$: