U mf@sZddlZddlmZddlZddlmZmZGdddZejfddZ d d Z e Z dS) NLock)mmap_key MmapedDictc@sFeZdZdZdZddZddZddd Zd d Zd d Z ddZ dS) MutexValuezA float protected by a mutex.FcKsd|_d|_t|_dSNg)_value _exemplarr_lock)selftyp metric_namename labelnames labelvalues help_textkwargsrF/opt/hc_python/lib/python3.8/site-packages/prometheus_client/values.py__init__ szMutexValue.__init__c Cs$|j|j|7_W5QRXdSNr r r amountrrrincszMutexValue.incNc Cs|j ||_W5QRXdSrrr value timestamprrrsetszMutexValue.setc Cs|j ||_W5QRXdSrr r r Zexemplarrrr set_exemplarszMutexValue.set_exemplarc Cs$|j|jW5QRSQRXdSrrr rrrgetszMutexValue.getc Cs$|j|jW5QRSQRXdSrr r#rrr get_exemplar"szMutexValue.get_exemplar)N) __name__ __module__ __qualname____doc__ _multiprocessrrrr"r$r%rrrrrs rcs6igditGfddd}|S)a8Returns a MmapedValue class based on a process_identifier function. The 'process_identifier' function MUST comply with this simple rule: when called in simultaneously running processes it MUST return distinct values. Using a different function than the default 'os.getpid' is at your own risk. rcszeZdZdZdZdfdd ZfddZfdd Zfd d Zdfd d Z ddZ fddZ ddZ d S)z&MultiProcessValue..MmapedValuezAA float protected by a mutex backed by a per-process mmaped file.Tc sr|||||||f|_dtjkrDdtjkrDtjdtjd<tdt |||W5QRXdS)Nprometheus_multiproc_dirPROMETHEUS_MULTIPROC_DIRzpprometheus_multiproc_dir variable has been deprecated in favor of the upper case naming PROMETHEUS_MULTIPROC_DIR) _paramsosenvironwarningswarnDeprecationWarning"_MmapedValue__check_for_pid_change_MmapedValue__resetappend) r r rrrrrmultiprocess_moder)lockvaluesrrr<s z/MultiProcessValue..MmapedValue.__init__c s|j\}}}}}}}|dkr*|d|}n|}|krdtjtjdd|d} t| |<||_t ||||||_ |j |j \|_ |_ dS)NZgauge_r-z{}_{}.dbr)r.r/pathjoinr0r$formatr_filer_keyZ read_valuer _timestamp) r r rrrrrr7Z file_prefixfilename)filespidrrZ__resetGs   z.MultiProcessValue..MmapedValue.__resetcsN}d|krJ|d<D] }|q"D] }|q.MmapedValue.__check_for_pid_changec sF8||j|7_d|_|j|j|j|jW5QRXdSrr4r r@r> write_valuer?rr8rrrbs z*MultiProcessValue..MmapedValue.incNc sB4|||_|pd|_|j|j|j|jW5QRXdSrrHrrJrrris  z*MultiProcessValue..MmapedValue.setcSsdSrrr!rrrr"psz3MultiProcessValue..MmapedValue.set_exemplarc s*||jW5QRSQRXdSr)r4r r#rJrrr$tsz*MultiProcessValue..MmapedValue.getcSsdSrrr#rrrr%ysz3MultiProcessValue..MmapedValue.get_exemplar)r+)N) r&r'r(r)r*rr5r4rrr"r$r%rrBr8rCrGr9rr MmapedValue7s   rLr)rGrLrrKrMultiProcessValue's  FrMcCs"dtjksdtjkrtStSdS)Nr,r-)r/r0rMrrrrrget_value_classsrN) r/ threadingrr1Z mmap_dictrrrgetpidrMrNZ ValueClassrrrrs Y