a
    !f?.                     @   sd   d Z ddlZddlmZ G dd deZG dd deZG dd	 d	eZG d
d deddZ	dS )zMetric Descriptors for the `Google Stackdriver Monitoring API (V3)`_.

.. _Google Stackdriver Monitoring API (V3):
    https://cloud.google.com/monitoring/api/ref_v3/rest/v3/    projects.metricDescriptors
    N)LabelDescriptorc                   @   s    e Zd ZdZdZdZdZdZdS )
MetricKindzChoices for the `kind of measurement`_.

    .. _kind of measurement:
        https://cloud.google.com/monitoring/api/ref_v3/rest/v3/        projects.metricDescriptors#MetricKind
    METRIC_KIND_UNSPECIFIEDGAUGEDELTA
CUMULATIVEN)__name__
__module____qualname____doc__r   r   r   r    r   r   Y/var/www/html/python-backend/venv/lib/python3.9/site-packages/gcloud/monitoring/metric.pyr      s
   r   c                   @   s(   e Zd ZdZdZdZdZdZdZdZ	dS )		ValueTypezChoices for the `metric value type`_.

    .. _metric value type:
        https://cloud.google.com/monitoring/api/ref_v3/rest/v3/        projects.metricDescriptors#ValueType
    VALUE_TYPE_UNSPECIFIEDBOOLINT64DOUBLESTRINGDISTRIBUTIONN)
r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   +   s   r   c                   @   sz   e Zd ZdZejejdddddfddZdd Z	d	d
 Z
edd ZedddZedd Zdd Zdd Zdd ZdS )MetricDescriptora  Specification of a metric type and its schema.

    The preferred way to construct a metric descriptor object is using the
    :meth:`~gcloud.monitoring.client.Client.metric_descriptor` factory method
    of the :class:`~gcloud.monitoring.client.Client` class.

    :type client: :class:`gcloud.monitoring.client.Client`
    :param client: A client for operating on the metric descriptor.

    :type type_: string
    :param type_:
        The metric type including a DNS name prefix. For example:
        ``"compute.googleapis.com/instance/cpu/utilization"``

    :type metric_kind: string
    :param metric_kind:
        The kind of measurement. It must be one of
        :data:`MetricKind.GAUGE`, :data:`MetricKind.DELTA`,
        or :data:`MetricKind.CUMULATIVE`. See :class:`MetricKind`.

    :type value_type: string
    :param value_type:
        The value type of the metric. It must be one of
        :data:`ValueType.BOOL`, :data:`ValueType.INT64`,
        :data:`ValueType.DOUBLE`, :data:`ValueType.STRING`,
        or :data:`ValueType.DISTRIBUTION`.
        See :class:`ValueType`.

    :type labels: list of :class:`~gcloud.monitoring.label.LabelDescriptor`
    :param labels:
        A sequence of zero or more label descriptors specifying the labels
        used to identify a specific instance of this metric.

    :type unit: string
    :param unit: An optional unit in which the metric value is reported.

    :type description: string
    :param description: An optional detailed description of the metric.

    :type display_name: string
    :param display_name: An optional concise name for the metric.

    :type name: string or None
    :param name:
        The "resource name" of the metric descriptor. For example:
        ``"projects/<project_id>/metricDescriptors/<type>"``. As
        retrieved from the service, this will always be specified.
        You can and should omit it when constructing an instance for
        the purpose of creating a new metric descriptor.
    r    Nc
           
      C   s:   || _ |	| _|| _|| _|| _|| _|| _|| _|| _d S N)	clientnametypelabelsmetric_kind
value_typeunitdescriptiondisplay_name)
selfr   type_r   r   r   r   r   r    r   r   r   r   __init__q   s    zMetricDescriptor.__init__c                 C   s6   dj | jjd}| jjjd||  d}| | dS )a  Create a new metric descriptor based on this object.

        Example::

            >>> descriptor = client.metric_descriptor(
            ...     'custom.googleapis.com/my_metric',
            ...     metric_kind=MetricKind.GAUGE,
            ...     value_type=ValueType.DOUBLE,
            ...     description='This is a simple example of a custom metric.')
            >>> descriptor.create()

        The metric kind must not be :data:`MetricKind.METRIC_KIND_UNSPECIFIED`,
        and the value type must not be
        :data:`ValueType.VALUE_TYPE_UNSPECIFIED`.

        The ``name`` attribute is ignored in preparing the creation request.
        All attributes are overwritten by the values received in the response
        (normally affecting only ``name``).
        &/projects/{project}/metricDescriptors/projectPOST)methodpathdataN)formatr   r&   
connectionapi_request_to_dict_init_from_dict)r!   r)   responser   r   r   create   s    zMetricDescriptor.createc                 C   s*   dj | jj| jd}| jjjd|d dS )a%  Delete the metric descriptor identified by this object.

        Example::

            >>> descriptor = client.metric_descriptor(
            ...     'custom.googleapis.com/my_metric')
            >>> descriptor.delete()

        Only the ``client`` and ``type`` attributes are used.
        ,/projects/{project}/metricDescriptors/{type}r&   r   DELETEr(   r)   N)r+   r   r&   r   r,   r-   )r!   r)   r   r   r   delete   s
    zMetricDescriptor.deletec                 C   s,   dj |j|d}|jjd|d}| ||S )a  Look up a metric descriptor by type.

        :type client: :class:`gcloud.monitoring.client.Client`
        :param client: The client to use.

        :type metric_type: string
        :param metric_type: The metric type name.

        :rtype: :class:`MetricDescriptor`
        :returns: The metric descriptor instance.

        :raises: :class:`gcloud.exceptions.NotFound` if the metric descriptor
            is not found.
        r2   r3   GETr5   )r+   r&   r,   r-   
_from_dict)clsr   Zmetric_typer)   infor   r   r   _fetch   s    zMetricDescriptor._fetchc                 C   s   dj |jd}g }|dur$|| |dur>|dj |d g }d}i }|r\d||d< |durl||d< |jjd	||d
}	|	ddD ]}
|| ||
 q|	d}|sFqqF|S )a  List all metric descriptors for the project.

        :type client: :class:`gcloud.monitoring.client.Client`
        :param client: The client to use.

        :type filter_string: string or None
        :param filter_string:
            An optional filter expression describing the metric descriptors
            to be returned. See the `filter documentation`_.

        :type type_prefix: string or None
        :param type_prefix: An optional prefix constraining the selected
            metric types. This adds ``metric.type = starts_with("<prefix>")``
            to the filter.

        :rtype: list of :class:`MetricDescriptor`
        :returns: A list of metric descriptor instances.

        .. _filter documentation:
            https://cloud.google.com/monitoring/api/v3/filters
        r$   r%   Nz%metric.type = starts_with("{prefix}"))prefixz AND filterZ	pageTokenr7   )r(   r)   Zquery_paramsZmetricDescriptorsr   ZnextPageToken)r+   r&   appendjoinr,   r-   getr8   )r9   r   Zfilter_stringZtype_prefixr)   filtersZdescriptorsZ
page_tokenparamsr0   r:   r   r   r   _list   s4    

zMetricDescriptor._listc                 C   s   | |d}| | |S )a  Construct a metric descriptor from the parsed JSON representation.

        :type client: :class:`gcloud.monitoring.client.Client`
        :param client: A client to be included in the returned object.

        :type info: dict
        :param info:
            A ``dict`` parsed from the JSON wire-format representation.

        :rtype: :class:`MetricDescriptor`
        :returns: A metric descriptor.
        N)r/   )r9   r   r:   Z
descriptorr   r   r   r8      s    

zMetricDescriptor._from_dictc                 C   sr   |d | _ |d | _tdd |dg D | _|d | _|d | _|dd	| _|d
d	| _|dd	| _	dS )zInitialize attributes from the parsed JSON representation.

        :type info: dict
        :param info:
            A ``dict`` parsed from the JSON wire-format representation.
        r   r   c                 s   s   | ]}t |V  qd S r   )r   r8   .0labelr   r   r   	<genexpr>  s   z3MetricDescriptor._init_from_dict.<locals>.<genexpr>r   
metricKind	valueTyper   r   r   displayNameN)
r   r   tupler@   r   r   r   r   r   r    r!   r:   r   r   r   r/     s    





z MetricDescriptor._init_from_dictc                 C   s`   | j | j| jd}| jr,dd | jD |d< | jr<| j|d< | jrL| j|d< | jr\| j|d< |S )zBuild a dictionary ready to be serialized to the JSON wire format.

        :rtype: dict
        :returns: A dictionary.
        )r   rH   rI   c                 S   s   g | ]}|  qS r   )r.   rD   r   r   r   
<listcomp>)      z-MetricDescriptor._to_dict.<locals>.<listcomp>r   r   r   rJ   )r   r   r   r   r   r   r    rL   r   r   r   r.     s    


zMetricDescriptor._to_dictc                 C   s   dj f i | jS )Nz<MetricDescriptor:
 name={name!r},
 type={type!r},
 metric_kind={metric_kind!r}, value_type={value_type!r},
 labels={labels!r},
 display_name={display_name!r}, unit={unit!r},
 description={description!r}>)r+   __dict__)r!   r   r   r   __repr__3  s    zMetricDescriptor.__repr__)NN)r   r	   r
   r   r   r   r   r   r#   r1   r6   classmethodr;   rC   r8   r/   r.   rP   r   r   r   r   r   =   s$   4

7
r   c                   @   s    e Zd ZdZdZedd ZdS )Metrica/  A specific metric identified by specifying values for all labels.

    :type type: string
    :param type: The metric type name.

    :type labels: dict
    :param labels: A mapping from label names to values for all labels
                   enumerated in the associated :class:`MetricDescriptor`.
    r   c                 C   s   | |d | di dS )a  Construct a metric object from the parsed JSON representation.

        :type info: dict
        :param info:
            A ``dict`` parsed from the JSON wire-format representation.

        :rtype: :class:`Metric`
        :returns: A metric object.
        r   r   )r   r   )r@   )r9   r:   r   r   r   r8   K  s    
zMetric._from_dictN)r   r	   r
   r   	__slots__rQ   r8   r   r   r   r   rR   ?  s   	rR   ztype labels)
r   collectionsZgcloud.monitoring.labelr   objectr   r   r   
namedtuplerR   r   r   r   r   <module>   s     