ó
6]c           @   sU   d  d l  Z  d  d l m Z d d l m Z d e f d     YZ e d e  Z d S(   i˙˙˙˙N(   t   Locki   (   t   Metrict   CollectorRegistryc           B   sS   e  Z d  Z e d  Z d   Z d   Z d   Z d   Z d   Z	 d d  Z RS(	   sŮ   Metric collector registry.

    Collectors must have a no-argument method 'collect' that returns a list of
    Metric objects. The returned metrics should be consistent with the Prometheus
    exposition formats.
    c         C   s+   i  |  _  i  |  _ | |  _ t   |  _ d  S(   N(   t   _collector_to_namest   _names_to_collectorst   _auto_describeR    t   _lock(   t   selft   auto_describe(    (    s9   lib/python2.7/site-packages/prometheus_client/registry.pyt   __init__   s    			c         C   s   |  j  u |  j |  } t |  j  j |  } | rO t d j |    n  x | D] } | |  j | <qV W| |  j | <Wd QXd S(   s    Add a collector to the registry.s/   Duplicated timeseries in CollectorRegistry: {0}N(   R   t
   _get_namest   setR   t   intersectiont
   ValueErrort   formatR   (   R   t	   collectort   namest
   duplicatest   name(    (    s9   lib/python2.7/site-packages/prometheus_client/registry.pyt   register   s    
c         C   s@   |  j  1 x |  j | D] } |  j | =q W|  j | =Wd QXd S(   s%   Remove a collector from the registry.N(   R   R   R   (   R   R   R   (    (    s9   lib/python2.7/site-packages/prometheus_client/registry.pyt
   unregister"   s    
c         C   ső   d } y | j } Wn t k
 r& n X| rC |  j rC | j } n  | sM g  Sg  } i d d g d 6d d d d g d 6d d d d g d	 6d d
 d g d 6d g d 6} xH |   D]= } x4 | j | j d g  D] } | j | j |  qĎ Wq° W| S(   s/   Get names of timeseries the collector produces.t   _totalt   _createdt   countert    t   _sumt   _countt   summaryt   _buckett	   histogramt   _gsumt   _gcountt   gaugehistogramt   _infot   infoN(	   t   Nonet   describet   AttributeErrorR   t   collectt   gett   typet   appendR   (   R   R   t	   desc_funct   resultt   type_suffixest   metrict   suffix(    (    s9   lib/python2.7/site-packages/prometheus_client/registry.pyR
   )   s(    c         c   sY   d } |  j  t j |  j  } Wd QXx* | D]" } x | j   D] } | VqB Wq/ Wd S(   s3   Yields metrics from the collectors in the registry.N(   R#   R   t   copyR   R&   (   R   t
   collectorsR   R-   (    (    s9   lib/python2.7/site-packages/prometheus_client/registry.pyR&   E   s    
c   
         s  t  |  } t    } |  j < x4 | D], } | |  j k r& | j |  j |  q& q& WWd QXg    x | D] } xz | j   D]l } g  | j D] } | d | k r | ^ q } | r| t | j | j | j	  } | | _   j
 |  q| q| Wqi Wd t f   f d     Y}	 |	   S(   s  Returns object that only collects some metrics.

        Returns an object which upon collect() will return
        only samples with the given names.

        Intended usage is:
            generate_latest(REGISTRY.restricted_registry(['a_timeseries']))

        Experimental.Ni    t   RestrictedRegistryc              s   e  Z   f d    Z RS(   c            s     S(   N(    (   R   (   t   metrics(    s9   lib/python2.7/site-packages/prometheus_client/registry.pyR&   h   s    (   t   __name__t
   __module__R&   (    (   R2   (    s9   lib/python2.7/site-packages/prometheus_client/registry.pyR1   g   s   (   R   R   R   t   addR&   t   samplesR   R   t   documentationR(   R)   t   object(
   R   R   R0   R   R   R-   t   sR6   t   mR1   (    (   R2   s9   lib/python2.7/site-packages/prometheus_client/registry.pyt   restricted_registryN   s     
	
!,	c         C   si   | d k r i  } n  xM |  j   D]? } x6 | j D]+ } | j | k r2 | j | k r2 | j Sq2 Wq" Wd S(   s~   Returns the sample value, or None if not found.

        This is inefficient, and intended only for use in unittests.
        N(   R#   R&   R6   R   t   labelst   value(   R   R   R<   R-   R9   (    (    s9   lib/python2.7/site-packages/prometheus_client/registry.pyt   get_sample_valuem   s    	N(   R3   R4   t   __doc__t   FalseR	   R   R   R
   R&   R;   R#   R>   (    (    (    s9   lib/python2.7/site-packages/prometheus_client/registry.pyR      s   						R   (	   R/   t	   threadingR    t   metrics_coreR   R8   R   t   Truet   REGISTRY(    (    (    s9   lib/python2.7/site-packages/prometheus_client/registry.pyt   <module>   s   t