%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/utils/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/utils/win_pdh.pyo

�
���^c@@sdZddlmZmZddlZddlZy"ddlZddlZeZ	Wne
k
roeZ	nXddlZ
ddlmZeje�ZdZd�Zdefd��YZd	�Zd
�Zd�Zd�Zdd
�Zd�Zd�ZdS(u&
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')
i(tabsolute_importtunicode_literalsN(tCommandExecutionErrorupdhcC@s0tjjj�stdfSts,tdfStS(u8
    Only works on Windows systems with the PyWin32
    u$salt.utils.win_pdh: Requires Windowsu,salt.utils.win_pdh: Missing required modules(tsalttutilstplatformt
is_windowstFalsetHAS_WINDOWS_MODULESt__virtualname__(((s6/usr/lib/python2.7/site-packages/salt/utils/win_pdh.pyt__virtual__<s


tCountercB@seZdZdZdZdZdZdZdZdZ	dZ
dZdZd	Z
dZdZd	Zd
ZdZdZd
ZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"d�Z#e$e#�Z#d�Z%d�Z&d�Z'd�Z(d�Z)d�Z*RS(uU
    Counter object
    Has enumerations and functions for working with counters
    iiiiiiiiiiiiiii i@i�iiii i0i@cC@shtjd||d||fd�}tj|�dkrOt|||||�Stdj|���dS(u�
        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
        iuInvalid counter specified: {0}N(twin32pdhtMakeCounterPathtNonetValidatePathRRtformat(tobjtinstancetinstance_indextcountertpath((s6/usr/lib/python2.7/site-packages/salt/utils/win_pdh.pyt
build_counter�s
!cC@sL||_||_||_||_||_d|_d|_d|_dS(N(	RRRtindexRRthandletinfottype(tselfRRRRR((s6/usr/lib/python2.7/site-packages/salt/utils/win_pdh.pyt__init__�s							cC@stj||j�|_dS(u�
        Add the current path to the query

        Args:
            query (obj):
                The handle to the query to add the counter
        N(Rt
AddCounterRR(Rtquery((s6/usr/lib/python2.7/site-packages/salt/utils/win_pdh.pytadd_to_query�scC@s�|js�tj|jd�}i|dd6|dd6|dd6|dd6|d	d
6|dd6|d
d6|ddd6|ddd6|ddd6|ddd6|dd	d6|ddd6|dd6|_n|jS(u�
        Get information about the counter

        .. note::
            GetCounterInfo sometimes crashes in the wrapper code. Fewer crashes
            if this is called after sampling data.
        iutypeiuversioniuscaleiu
default_scaleiu	user_dataiuquery_user_dataiu	full_pathiumachine_nameuobject_nameu
instance_nameuparent_instanceuinstance_indexucounter_nameiuexplain_text(RRtGetCounterInfoR(Rtci((s6/usr/lib/python2.7/site-packages/salt/utils/win_pdh.pytget_info�s$	cC@s+tj|jtj�\}}||_|S(u`
        Return the counter value

        Returns:
            long: The counter value
        (RtGetFormattedCounterValueRtPDH_FMT_DOUBLER(Rtcounter_typetvalue((s6/usr/lib/python2.7/site-packages/salt/utils/win_pdh.pyR&�s	cC@sv|j�d}g}xYt|�D]K}|jd�r#t||�}|rn||@rn|j|d�qnq#q#W|S(u~
        Returns the names of the flags that are set in the Type field

        It can be used to format the counter.
        utypeuPERF_i(R"tdirt
startswithtgetattrtappend(RRt	type_listtmembertbit((s6/usr/lib/python2.7/site-packages/salt/utils/win_pdh.pyttype_string�scC@s|jS(N(R(R((s6/usr/lib/python2.7/site-packages/salt/utils/win_pdh.pyt__str__�s(+t__name__t
__module__t__doc__tPERF_SIZE_DWORDtPERF_SIZE_LARGEtPERF_SIZE_ZEROtPERF_SIZE_VARIABLE_LENtPERF_TYPE_NUMBERtPERF_TYPE_COUNTERtPERF_TYPE_TEXTtPERF_TYPE_ZEROtPERF_NUMBER_HEXtPERF_NUMBER_DECIMALtPERF_NUMBER_DEC_1000tPERF_COUNTER_VALUEtPERF_COUNTER_RATEtPERF_COUNTER_FRACTIONtPERF_COUNTER_BASEtPERF_COUNTER_ELAPSEDtPERF_COUNTER_QUEUE_LENtPERF_COUNTER_HISTOGRAMtPERF_TEXT_UNICODEtPERF_TEXT_ASCIItPERF_TIMER_TICKtPERF_TIMER_100NStPERF_OBJECT_TIMERtPERF_DELTA_COUNTERtPERF_DELTA_BASEtPERF_INVERSE_COUNTERtPERF_MULTI_COUNTERtPERF_DISPLAY_NO_SUFFIXtPERF_DISPLAY_PER_SECtPERF_DISPLAY_PERCENTtPERF_DISPLAY_SECONDStPERF_DISPLAY_NO_SHOWRtstaticmethodRRR"R&R.R/(((s6/usr/lib/python2.7/site-packages/salt/utils/win_pdh.pyRIsR	'	
	
			cC@sttjdddd��S(uu
    Get a list of available counter objects on the system

    Returns:
        list: A list of counter objects
    i����iN(tsortedRtEnumObjectsR(((s6/usr/lib/python2.7/site-packages/salt/utils/win_pdh.pytlist_objects�scC@stjdd|dd�dS(u#
    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
    i����iN(RtEnumObjectItemsR(R((s6/usr/lib/python2.7/site-packages/salt/utils/win_pdh.pyt
list_countersscC@stjdd|dd�dS(u%
    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
    i����iiN(RRWR(R((s6/usr/lib/python2.7/site-packages/salt/utils/win_pdh.pytlist_instancesscC@s�g}d}xs|D]k\}}}y3tj||||�}|d7}|j|�Wqtk
r}}tj|j�qqXqW|S(u�
    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
    ii(RRR*Rtlogtdebugtstrerror(tcounter_listtcountersRRRtcounter_nameRtexc((s6/usr/lib/python2.7/site-packages/salt/utils/win_pdh.pytbuild_counter_list$s
cC@s�tjdd|dd�\}}|dkr6|}nt|t�sQ|g}ng}xi|D]a}xX|D]:}|j�dkr�dn|}|j|||f�qkW|j|d|f�q^W|r�t|�SiS(u�
    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 ``*``
    i����iu_totalu*N(RRWRt
isinstancetlisttlowerR*tget_counters(Rt
instance_listR^tinstances_availR]RR((s6/usr/lib/python2.7/site-packages/salt/utils/win_pdh.pytget_all_countersQs!	

cC@s�t|t�std��nz�tj�}t|�}x|D]}|j|�q@Wtj|�tj	d�tj|�i}x`|D]X}y!|j
i|j�|j6�Wq�t
jk
r�}|jdkr�q�q��q�Xq�WWdtj|�X|S(u�
    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
    u%counter_list must be a list of tuplesiuNo data to return.N(RbRcRRt	OpenQueryRaRtCollectQueryDatattimetsleeptupdateR&Rt
pywintypesterrorR\t
CloseQuery(R]RR^RtretR`((s6/usr/lib/python2.7/site-packages/salt/utils/win_pdh.pyReus(




!cC@st|||fg�S(u,
    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
    (Re(RRR((s6/usr/lib/python2.7/site-packages/salt/utils/win_pdh.pytget_counter�s(R2t
__future__RRtloggingRkRnRtTrueRtImportErrorRtsalt.utils.platformRtsalt.exceptionsRt	getLoggert__file__RZR	R
tobjectRRVRXRYRaRRhReRr(((s6/usr/lib/python2.7/site-packages/salt/utils/win_pdh.pyt<module>"s,


	
�	
			-$	2

Zerion Mini Shell 1.0