
2\c           @   s>   d  Z  d d l m Z e d d d d d g  Z d   Z d	 S(
   s   
Prometheus metrics exported by Jupyter Notebook Server

Read https://prometheus.io/docs/practices/naming/ for naming
conventions for metrics & labels.
i(   t	   Histogramt   http_request_duration_secondss)   duration in seconds for all HTTP requestst   methodt   handlert   status_codec         C   sY   t  j d |  j j d d j |  j j t |   j  d |  j	    j
 |  j j    d S(   s  
    Tornado log handler for recording RED metrics.

    We record the following metrics:
       Rate - the number of requests, per second, your services are serving.
       Errors - the number of failed requests per second.
       Duration - The amount of time each request takes expressed as a time interval.

    We use a fully qualified name of the handler as a label,
    rather than every url path to reduce cardinality.

    This function should be either the value of or called from a function
    that is the 'log_function' tornado setting. This makes it get called
    at the end of every request, allowing us to record the metrics we need.
    R   R   s   {}.{}R   N(   t   HTTP_REQUEST_DURATION_SECONDSt   labelst   requestR   t   formatt	   __class__t
   __module__t   typet   __name__t
   get_statust   observet   request_time(   R   (    (    s/   lib/python2.7/site-packages/notebook/metrics.pyt   prometheus_log_method   s
    	!N(   t   __doc__t   prometheus_clientR    R   R   (    (    (    s/   lib/python2.7/site-packages/notebook/metrics.pyt   <module>   s   