§ v<ˆj³;ãó`—ddlmZddlZddlmZddlZddlZddlZddlZddl m Z m Z m Z ddl mZ ddlmZddlmZ dd lmZmZdd lmZdd lmZmZmZdd lmZdd lmZmZn-#e $r%dd l!mZmZdd l"mZdd l#mZmZmZddl$mZmZmZYnwxYwe%d¦«Z& ej'dkZ(ej'dkZ)d„Z*efd„Z+Gd„de ¦«Z,Gd„dee ¦«Z-defd„Z.e.Z/efd„Z0d„Z1Gd„de¦«Z2d„Z3d„Z4d)d „Z5dd!e4fd"„Z6dd!e4fd#„Z7dd!e4fd$„Z8d%„Z9d&„Z:d'„Z; dd(l.prometheus_app/sbø€àŸ š  MÑ2Ô2ˆ ݘ'Ÿ+š+ n°bÑ9Ô9Ñ:Ô:ˆå!-¨h¸ ÀvÑ!NÔ!Nш�˜àˆ�v ˜xÑ(Ô(Ð(؈xˆr&©)rr1s` r$Ú make_wsgi_appr3,s$ø€ðððððð Ðr&có—eZdZdZd„ZdS)Ú_SilentHandlerz(WSGI handler that does not log requests.có—dS©z Log nothing.Nr2©ÚselfÚformatÚargss r$Ú log_messagez_SilentHandler.log_message?ó€€€r&N)Ú__name__Ú __module__Ú __qualname__Ú__doc__r<r2r&r$r5r5<s)€€€€€Ø2Ð2ðððððr&r5có—eZdZdZdZdS)ÚThreadingWSGIServerzThread per request HTTP server.TN)r>r?r@rAÚdaemon_threadsr2r&r$rCrCCs€€€€€Ø)Ð)ð€N€N€Nr&rCr+cóÊ—t|¦«}t|||tt¬¦«}t j|j¬¦«}d|_| ¦«dS)z?Starts a WSGI server for prometheus metrics as a daemon thread.)Ú handler_class)ÚtargetTN) r3rrCr5Ú threadingÚThreadÚ serve_foreverÚdaemonÚstart)ÚportÚaddrrÚappÚhttpdÚts r$Ústart_wsgi_serverrRKsV€å ˜Ñ !Ô !€CÝ ˜˜d CÕ)<ÍNÐ [Ñ [Ô [€EÝÔ Ô 3Ð4Ñ4Ô4€AØ€A„H؇G‚G�I„I€I€I€Ir&c óÖ—d„}g}| ¦«D�]'} |j}|j}|dkr|dz}n(|dkr|dz}d}n|dkrd}n|dkrd }n|d krd }| d  ||j d d¦« dd¦«¦«¦«| d ||¦«¦«i}|jD]l}dD]I}|j|j|zkr4| |g¦« ||¦«¦«nŒJ| ||¦«¦«Œmn%#t$r} | j pd|fz| _ ‚d} ~ wwxYwt|  ¦«¦«D]¤\}} | d |j||j d d¦« dd¦«¦«¦«| d |j|¦«¦«|  | ¦«Œ¥�Œ)d |¦« d¦«S)zHReturns the metrics from the registry in latest text format as a string.c ó —|jrWd d d„t|j ¦«¦«D¦«¦«¦«}nd}d}|j�7d t t|j¦«dz¦«¦«}d |j|t|j ¦«|¦«S)Nz{{{0}}}ú,c ó¸—g|]W\}}d || dd¦« dd¦« dd¦«¦«‘ŒXS)z {0}="{1}"ú\ú\\ú ú\nú"z\")r:Úreplace©Ú.0ÚkÚvs r$ú z8generate_latest..sample_line..]sr€ð=ð=ð=ᘘ1ð×#Ò#Ø�q—y’y  uÑ-Ô-×5Ò5°d¸EÑBÔB×JÒJÈ3ÐPUÑVÔVñXôXð=ð=ð=r&r+z {0:d}ièz{0}{1} {2}{3} ) Úlabelsr:ÚjoinÚsortedÚitemsÚ timestampÚintÚfloatÚnamer Úvalue)ÚlineÚlabelstrrfs r$Ú sample_linez$generate_latest..sample_lineZsÑ€Ø Œ;ð Ø ×'Ò'¨¯ªð=ð=å & t¤{×'8Ò'8Ñ':Ô':Ñ ;Ô ;ð=ñ=ô=ñ)>ô)>ñ?ô?ˆHˆHð ˆH؈ Ø Œ>Ð %à Ÿš­­E°$´.Ñ,AÔ,AÀDÑ,HÑ(IÔ(IÑJÔJˆIØ ×'Ò'Ø ŒI�x¥°´Ñ!<Ô!<¸iñIôIð Ir&ÚcounterÚ_totalÚinfoÚ_infoÚgaugeÚstatesetÚgaugehistogramÚ histogramÚunknownÚuntypedz# HELP {0} {1} rWrXrYrZz# TYPE {0} {1} )Ú_createdÚ_gsumÚ_gcount)r+Nz# HELP {0}{1} {2} z# TYPE {0}{1} gauge r+úutf-8)ÚcollectriÚtypeÚappendr:Ú documentationr\ÚsamplesÚ setdefaultÚ Exceptionr;rdreÚextendrcÚencode) rrmr#ÚmetricÚmnameÚmtypeÚ om_samplesÚsÚsuffixÚ exceptionÚliness r$Úgenerate_latestr�WsÙ€ð Ið Ið Ið€FØ×"Ò"Ñ$Ô$ð(!ñ(!ˆð! Ø”KˆEØ”KˆEà˜ Ò!Ð!Ø Ñ(��ؘ&’�Ø ™�Ø��ؘ*Ò$Ð$Ø��ØÐ*Ò*Ð*ð$��ؘ)Ò#Ð#Ø!�à �MŠMÐ,×3Ò3Ø�vÔ+×3Ò3°D¸%Ñ@Ô@×HÒHÈÈuÑUÔUñWôWñ Xô Xð Xà �MŠMÐ,×3Ò3°E¸5ÑAÔAÑ BÔ BÐ BàˆJØ”^ð 2ð 2�Ø>ð2ð2�FØ”v ¤¨vÑ!5Ò5Ð5à"×-Ò-¨f°bÑ9Ô9×@Ò@ÀÀÈQÁÄÑPÔPÐPؘð6ð —M’M + +¨a¡.¤.Ñ1Ô1Ð1øð 2øõð ð ð Ø'œnÐ5°¸&¸ÑBˆIŒNØ øøøøð øøøõ$ J×$4Ò$4Ñ$6Ô$6Ñ7Ô7ð !ð !‰MˆF�EØ �MŠMÐ/×6Ò6°v´{ÀFØ7=Ô7K×7SÒ7SÐTXÐZ_Ñ7`Ô7`×7hÒ7hÐimÐotÑ7uÔ7uñwôwñ xô xð xà �MŠMÐ1×8Ò8¸¼ÀfÑMÔMÑ NÔ NÐ NØ �MŠM˜%Ñ Ô Ð Ð ñ  !ð �7Š7�6‰?Œ?× !Ò ! 'Ñ *Ô *Ð*sžD7EÅ E8Å E3Å3E8cóì—|pd}| d¦«D]M}| d¦«d ¦«dkrtjtjfcSŒNttfS)Nr+rUú;rzapplication/openmetrics-text)ÚsplitÚstripÚ openmetricsr�ÚCONTENT_TYPE_LATEST)rÚaccepteds r$rr–s†€Ø!Ð' R€MØ!×'Ò'¨Ñ,Ô,ð5ð5ˆØ �>Š>˜#Ñ Ô ˜qÔ !× 'Ò 'Ñ )Ô )Ð-KÒ KÐ KÝÔ/ÝÔ3ð5ð 5ð 5ð 5ð Lõ Õ/Ð /Ð/r&có8—eZdZdZeZd„Zd„Zed„¦«Z dS)ÚMetricsHandlerz2HTTP handler that gives metrics from ``REGISTRY``.có¤—|j}|j d¦«}tt |j¦«j¦«}t|||¦«\}}}| t|  d¦«d¦«¦«|j |Ž|  ¦«|j  |¦«dS)NÚAcceptú r)rÚheadersr,rrÚpathÚqueryr%Ú send_responsergr�Ú send_headerÚ end_headersÚwfileÚwrite)r9rrr r/r0r#s r$Údo_GETzMetricsHandler.do_GET£s»€à”=ˆØœ ×(Ò(¨Ñ2Ô2ˆ Ý�( 4¤9Ñ-Ô-Ô3Ñ4Ô4ˆå!-¨h¸ ÀvÑ!NÔ!Nш�˜à ×Ò�3˜vŸ|š|¨CÑ0Ô0°Ô3Ñ4Ô4Ñ5Ô5Ð5؈Ԙ&Ð!Ð!Ø ×ÒÑÔÐØ Œ ×Ò˜Ñ Ô Ð Ð Ð r&có—dSr7r2r8s r$r<zMetricsHandler.log_message°r=r&cób—t|j¦«}t||tfd|i¦«}|S)zWReturns a dynamic MetricsHandler class tied to the passed registry. r)rr>r}Úobject)ÚclsrÚcls_nameÚMyMetricsHandlers r$ÚfactoryzMetricsHandler.factory³s9€õ�s”|Ñ$Ô$ˆÝ ¨3µ¨-Ø!+¨XÐ 6ñ8ô8ÐàÐr&N) r>r?r@rAr rr¢r<Ú classmethodr©r2r&r$r–r–ŸsX€€€€€Ø<Ð<Ø€Hð !ð !ð !ððððð  ð  ñ„[ð  ð  ð  r&r–có&—|›dtj¦«›dtj¦«j›�}t |d¦«5}| t|¦«¦«ddd¦«n #1swxYwYtj||¦«dS)z²Write metrics to the given path. This is intended for use with the Node exporter textfile collector. The path must end in .prom for the textfile collector to process it.ú.ÚwbN) ÚosÚgetpidrHÚcurrent_threadÚidentÚopenr¡r�Úrename)r›rÚtmppathÚfs r$Úwrite_to_textfiler¶ÃsÀð !˜D˜D¥"¤)¡+¤+ + +­yÔ/GÑ/IÔ/IÔ/OÐ/OÐP€GÝ ˆg�tÑ Ô ð+ Ø �Š• Ñ)Ô)Ñ*Ô*Ð*ð+ð+ð+ñ+ô+ð+ð+ð+ð+ð+ð+øøøð+ð+ð+ð+õ„Iˆg�tÑÔÐÐÐsÁ#A1Á1A5Á8A5có"‡‡‡‡‡—ˆˆˆˆˆfd„}|S)z…Default handler that implements HTTP/HTTPS connections. Used by the push_to_gateway functions. Can be re-used by other handlers.có<•—t‰‰¬¦«}ˆfd„|_‰D]\}}| ||¦«Œtt¦« |‰¬¦«}|jdkr-td |j|j ¦«¦«‚dS)N)Údatacó•—‰S)Nr2)Úmethods€r$úz1default_handler..handle..Ösø€ V€r&)Útimeouti�z%error talking to pushgateway: {0} {1}) rÚ get_methodÚ add_headerrrr²ÚcodeÚIOErrorr:Úmsg) Úrequestr_r`Úrespr¹ršr»r½Úurls €€€€€r$Úhandlezdefault_handler..handleÔs²ø€Ý˜# DÐ)Ñ)Ô)ˆØ+˜^˜^˜^ˆÔØð %ð %‰DˆAˆqØ × Ò ˜q !Ñ $Ô $Ð $Ð $Ý�KÑ(Ô(×-Ò-¨g¸wÐ-ÑGÔGˆØ Œ9˜Ò Ð ÝÐA×HÒHØ” ˜4œ8ñ%ô%ñ&ô&ð &ð Ð r&r2)rÅr»r½ršr¹rÆs````` r$Údefault_handlerrÇÏs;øøøøø€ð &ð&ð&ð&ð&ð&ð&ð&ð&ð €Mr&có*‡‡‡‡‡‡‡—ˆˆˆˆˆˆˆfd„}|S)zÕHandler that implements HTTP/HTTPS connections with Basic Auth. Sets auth headers using supplied 'username' and 'password', if set. Used by the push_to_gateway functions. Can be re-used by other handlers.cóø•—‰ �[‰�Yd ‰ ‰¦« d¦«}tj|¦«}d|z}‰ d|g¦«t ‰‰‰‰‰¦«¦«dS)z1Handler that implements HTTP Basic Auth. Nz{0}:{1}r{sBasic Ú Authorization)r:r„Úbase64Ú b64encoder~rÇ) Ú auth_valueÚ auth_tokenÚ auth_headerr¹ršr»Úpasswordr½rÅÚusernames €€€€€€€r$rÆz"basic_auth_handler..handleçsˆø€ð Ð  HÐ$8Ø"×)Ò)¨(°HÑ=Ô=×DÒDÀWÑMÔMˆJÝÔ)¨*Ñ5Ô5ˆJØ# jÑ0ˆKØ �NŠN˜O¨[Ð9Ñ :Ô :Ð :Ø<�˜˜V W¨g°tÑ<Ô<Ñ>Ô>Ð>Ð>Ð>r&r2)rÅr»r½ršr¹rÑrÐrÆs``````` r$Úbasic_auth_handlerrÒásGøøøøøøø€ð ?ð?ð?ð?ð?ð?ð?ð?ð?ð?ð?ð €Mr&éc ó0—td||||||¦«dS)aNPush metrics to the given pushgateway. `gateway` the url for your push gateway. Either of the form 'http://pushgateway.local', or 'pushgateway.local'. Scheme defaults to 'http' if none is provided `job` is the job label to be attached to all pushed metrics `registry` is an instance of CollectorRegistry `grouping_key` please see the pushgateway documentation for details. Defaults to None `timeout` is how long push will attempt to connect before giving up. Defaults to 30s, can be set to None for no timeout. `handler` is an optional function which can be provided to perform requests to the 'gateway'. Defaults to None, in which case an http or https request will be carried out by a default handler. If not None, the argument must be a function which accepts the following arguments: url, method, timeout, headers, and content May be used to implement additional functionality not supported by the built-in default handler (such as SSL client certicates, and HTTP authentication mechanisms). 'url' is the URL for the request, the 'gateway' argument described earlier will form the basis of this URL. 'method' is the HTTP method which should be used when carrying out the request. 'timeout' requests not successfully completed after this many seconds should be aborted. If timeout is None, then the handler should not set a timeout. 'headers' is a list of ("header-name","header-value") tuples which must be passed to the pushgateway in the form of HTTP request headers. The function should raise an exception (e.g. IOError) on failure. 'content' is the data which should be used to form the HTTP Message Body. This overwrites all metrics with the same job and grouping_key. This uses the PUT HTTP method.ÚPUTN©Ú _use_gateway©ÚgatewayÚjobrÚ grouping_keyr½Úhandlers r$Úpush_to_gatewayrÝôs%€õR�˜  h° ¸gÀwÑOÔOÐOÐOÐOr&c ó0—td||||||¦«dS)a"PushAdd metrics to the given pushgateway. `gateway` the url for your push gateway. Either of the form 'http://pushgateway.local', or 'pushgateway.local'. Scheme defaults to 'http' if none is provided `job` is the job label to be attached to all pushed metrics `registry` is an instance of CollectorRegistry `grouping_key` please see the pushgateway documentation for details. Defaults to None `timeout` is how long push will attempt to connect before giving up. Defaults to 30s, can be set to None for no timeout. `handler` is an optional function which can be provided to perform requests to the 'gateway'. Defaults to None, in which case an http or https request will be carried out by a default handler. See the 'prometheus_client.push_to_gateway' documentation for implementation requirements. This replaces metrics with the same name, job and grouping_key. This uses the POST HTTP method.ÚPOSTNrÖrØs r$Úpushadd_to_gatewayrà s$€õ.�˜ # x°¸wÈÑPÔPÐPÐPÐPr&c ó0—td||d|||¦«dS)aîDelete metrics from the given pushgateway. `gateway` the url for your push gateway. Either of the form 'http://pushgateway.local', or 'pushgateway.local'. Scheme defaults to 'http' if none is provided `job` is the job label to be attached to all pushed metrics `grouping_key` please see the pushgateway documentation for details. Defaults to None `timeout` is how long delete will attempt to connect before giving up. Defaults to 30s, can be set to None for no timeout. `handler` is an optional function which can be provided to perform requests to the 'gateway'. Defaults to None, in which case an http or https request will be carried out by a default handler. See the 'prometheus_client.push_to_gateway' documentation for implementation requirements. This deletes metrics with the given job and grouping_key. This uses the DELETE HTTP method.ÚDELETENrÖ)rÙrÚrÛr½rÜs r$Údelete_from_gatewayrã:s$€õ*�˜7 C¨¨|¸WÀgÑNÔNÐNÐNÐNr&cóº—t|¦«}|jrtstr|jdvrd |¦«}dj|gt d|¦«¢RŽ}d} |dkrt |¦«} |€i}|d d„t|  ¦«¦«D¦«¦«z }||||d tfg| ¬ ¦«¦«dS) N)ÚhttpÚhttpsz http://{0}z{0}/metrics/{1}/{2}rÚr&râr+c 3ó€K—|]9\}}djtt|¦«t|¦«¦«ŽV—Œ:dS)z/{0}/{1}N)r:Ú_escape_grouping_keyrr]s r$ú z_use_gateway..bs[èè€ð2ð2á ˆAˆqð ˆ ÔÕ/µ°A±´½¸A¹¼Ñ?Ô?Ð@ð2ð2ð2ð2ð2ð2r&r)rÅr»r½ršr¹) rÚschemeÚPYTHON376_OR_NEWERÚPYTHON26_OR_OLDERr:rèr�rcrdrer“) r»rÙrÚrrÛr½rÜÚ gateway_urlrÅr¹s r$r×r×Rs*€Ý˜7Ñ#Ô#€Kà Ô ð/Ý ð/Ý#4ð/àÔ"Ð*;Ð;Ð;à×%Ò% gÑ.Ô.ˆØ &Ð Ô & wÐ RÕ1EÀeÈSÑ1QÔ1QÐ RÐ RÐ R€Cà €DØ �ÒÐݘxÑ(Ô(ˆàÐØˆ ؈2�7Š7ð2ð2å˜<×-Ò-Ñ/Ô/Ñ0Ô0ð2ñ2ô2ñ 2ô 2ñ2€Cð€G€GØ ˜¨Ø Õ"5Ð6Ð7¸dðñôñôðððr&cóÄ—|dkr|dzdfSd|vr?|dztj| d¦«¦« d¦«fS|t |¦«fS)Nr+z@base64ú=ú/r{)rËÚurlsafe_b64encoder„Údecoder)r_r`s r$rèrèlsi€ØˆB‚w€wà�9‰}˜cÐ!Ð!Ø �ˆˆà�9‰}�fÔ6°q·x²xÀÑ7HÔ7HÑIÔI×PÒPÐQXÑYÔYÐYÐYà•*˜Q‘-”-ÐÐr&có—ttjtjtj¦«¦«5}| d¦«d| ¦«dicddd¦«S#1swxYwYdS)z>Grouping key with instance set to the IP Address of this host.)Ú localhostrÚinstancerN)rÚsocketÚAF_INETÚ SOCK_DGRAMÚconnectÚ getsockname)r‰s r$Úinstance_ip_grouping_keyrûwsª€å •”�vœ~­vÔ/@ÑAÔAÑ BÔ Bð0ÀaØ � Š Ð"Ñ#Ô#Ð#ؘAŸMšM™OœO¨AÔ.Ð/ð0ð0ð0ð0ñ0ô0ð0ð0ð0ð0ð0ð0øøøð0ð0ð0ð0ð0ð0s·1A5Á5A9Á<A9)Ú make_asgi_app)NN)>Ú __future__rrËÚ contextlibrr®röÚsysrHÚwsgiref.simple_serverrrrr’r rr Úutilsr ÚBaseHTTPServerr r Ú SocketServerrÚurllib2rrrÚurllibrrrÚ ImportErrorÚ http.serverÚ socketserverÚurllib.requestÚ urllib.parserr“Ú version_inforìrër%r3r5rCrRÚstart_http_serverr�rr–r¶rÇrÒrÝràrãr×rèrûÚasgirür2r&r$úrsÌðØ'Ð'Ð'Ð'Ð'Ð'à € € € ØÐÐÐÐÐØ € € € Ø € € € Ø € € € ØÐÐÐØMÐMÐMÐMÐMÐMÐMÐMÐMÐMà2Ð2Ð2Ð2Ð2Ð2ØÐÐÐÐÐØ"Ð"Ð"Ð"Ð"Ð"ð <ØAÐAÐAÐAÐAÐAÐAÐAØ+Ð+Ð+Ð+Ð+Ð+Ø:Ð:Ð:Ð:Ð:Ð:Ð:Ð:Ð:Ð:Ø!Ð!Ð!Ð!Ð!Ð!Ø+Ð+Ð+Ð+Ð+Ð+Ð+Ð+Ð+øØð<ð<ð<à>Ð>Ð>Ð>Ð>Ð>Ð>Ð>Ø+Ð+Ð+Ð+Ð+Ð+ØAÐAÐAÐAÐAÐAÐAÐAÐAÐAØ;Ð;Ð;Ð;Ð;Ð;Ð;Ð;Ð;Ð;Ð;Ð;ð <øøøð�cÐDÑEÔEÐØ,àÔ$ vÒ-ÐØÔ%¨ Ò1ÐðFðFðFð$ð ð ð ð ð ððððÐ'ñôðððððð˜.¨*ñôðð"$¨hððððð&Ðð&ð<+ð<+ð<+ð<+ð~0ð0ð0ð! ð! ð! ð! ð! Ð+ñ! ô! ð! ðH ð ð ðððð$ðððð(.2¸2Øð)Pð)Pð)Pð)PðZ.2¸2ØðQðQðQðQð6$(°¸_ðOðOðOðOð0ððð4 ð ð ð0ð0ð0ð à#Ð#Ð#Ð#Ð#Ð#Ð#Ð#øð Ø€D€Døøøs¾&A%Á%'BÂBÄ D(Ä(D-