U mfQ @sddlZddlZddlZddlZddlZddlmZddlmZm Z ddl m Z m Z e dZddZGd d d ejZGd d d ZdS) N) default_timer)CallableTuple)CollectorRegistryREGISTRYz[^a-zA-Z0-9_-]cCs td|S)N_)_INVALID_GRAPHITE_CHARSsub)sr O/opt/hc_python/lib/python3.8/site-packages/prometheus_client/bridge/graphite.py _sanitizesrcs$eZdZfddZddZZS) _RegularPushcs t||_||_||_dSN)super__init___pusher _interval_prefix)selfZpusherintervalprefix __class__r r rs z_RegularPush.__init__cCstt}t}||kr*||kr:||j7}qq:t||qz|jj|jdWqtk rlt dYqXqdS)N)rz Push failed) rrtimesleeprpushrOSErrorlogging exception)rZ wait_untilnowr r r runs z_RegularPush.run)__name__ __module__ __qualname__rr" __classcell__r r rr rs rc@sdeZdZedejdfeeefee e ge fe dddZ deddd d Z de edd d dZdS)GraphiteBridgeF)addressregistrytimeout_seconds_timertagscCs"||_||_||_||_||_dSr)_address _registry_tags_timeoutr,)rr)r*r+r,r-r r r r1s zGraphiteBridge.__init__N)rreturnc st|}g}d}|r |d}|jD]}|jD]~}|jr~|jrNd}dnd}d||fddt|j D}nd}| |t |j |dt |jd|d q4q*t|j|j} | d|d | dS) Nr2.;z{0}={1}z{0}.{1}cs$g|]\}}t|t|qSr )formatr).0kvfmtr r Ps z'GraphiteBridge.push..  ascii)intr,r/ZcollectZsampleslabelsr0joinsorteditemsappendrnamefloatvaluesocketcreate_connectionr.r1sendallencodeclose) rrr!outputZ prefixstrZmetricr sepZlabelstrconnr r:r r>s.    4zGraphiteBridge.pushN@)rrr3cCst|||}d|_|dS)NT)rdaemonstart)rrrtr r r rS[s zGraphiteBridge.start)r2)rQr2)r#r$r%rrrstrr@rrGrboolrrrSr r r r r'0s   r')rrerI threadingrZtimeitrtypingrrr*rrcompiler rThreadrr'r r r r s