gf]ydZddlZddlZddlZddlZddlmcmZddl m Z ddl m Z ddl m Z ddl mZddl mZdd l mZdd l mZdd l mZdd l mZdd l mZddl mZddl mZddl mZddl mZddl mZddl mZddl mZddlmZddlm Z ddlm!Z!ddlm"Z"gZ#erWej$e j%ej&e j'ej(e j)ej*e j+ej,e j-ej.e j/ej0e j1iZ2nerWej$e j%ej(e j)ej*e j+ej3e j-ej,e j-ej&e j4ej5e j'iZ2nLerJej$e j%ej(e j)ej*e j+ej,e j-ej&e j4ej5e j'iZ2ej6e j7ej8e j9ej:e j;ej<e j=ej>e j?ej@e jAejBe jCejDe jEejFe jGejHe jIejJe jKejLe jMi ZNejOZPejQZQeRedZSeRedZTeRedZUeRedZVeWdvidddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLZXe dMgdNZYe dOgdPZZe dQgdRZ[e[Z\e dSgdTZ]e dUdVZ^e dWdXZ_ere dYgdZZ`ne dYgd[Z`d\Zad]Zbd^ZceSrd_Zdn d`Zddaed_edbZfeserdcZgnddZgdeZhdwdfZiejjZjejkZkejlZlejmZmdgZndhZoer diZpdjZqdkZrdlZsdmZtednZudoZveserdpZwnejwZwdqZxdrZyejzdsZ{Gdtdue|Z}dS)xz5FreeBSD, OpenBSD and NetBSD platforms implementation.N) namedtuple) defaultdict)_common)_psposix) _psutil_bsd) _psutil_posix) AccessDenied) conn_tmap)conn_to_ntuple)FREEBSD)memoize)memoize_when_activated)NETBSD) NoSuchProcess)OPENBSD) usage_percent) ZombieProcess)FileNotFoundError)PermissionError)ProcessLookupError)which per_cpu_timesproc_num_threadsproc_open_files proc_num_fdsppidstatusreal_uid effective_uid saved_uidreal_gid effective_gid saved_gidttynr create_time ctx_switches_vol ctx_switches_unvol read_io_count write_io_count user_timesys_time ch_user_time ch_sys_timerssvmsmemtextmemdatamemstackcpunumnamesvmem) total availablepercentusedfreeactiveinactivebufferscachedsharedwired scputimesusernicesystemidleirqpmem)r?rAtextdatastack pcputimes)r[r] children_userchildren_system pmmap_grouped*path rss, private, ref_count, shadow_count pmmap_ext6addr, perms path rss, private, ref_count, shadow_countsdiskio) read_count write_count read_bytes write_bytes read_time write_time busy_time)rlrmrnroc "tj}|\}}}}}}}}trtdd5} | D]} | dr+t | ddz}B| dr*t | ddz} dddn #1swxYwY||z|z} ||z|z} t|| z |d} t|| | | ||||||| S) z&System virtual memory as a namedtuple.z /proc/meminforbsBuffers:ris MemShared:Nround_) cext virtual_memropen startswithintsplitrrM)memrNrRrSrTrXrVrUrWflineavailrQrPs o/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib64/python3.11/site-packages/psutil/_psbsd.pyvirtual_memoryrsp    CDGAE45&'6 9/4 ( ( 9A 9 9??;//9!$**,,q/22T9GG__]339 a11D8F  9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 v  $E E>F "DUU]U1===G wd7FFE C CCsBCC C ctj\}}}}}t||d}tj||||||S)z@System swap memory as (total, used, free, sin, sout) namedtuple.rru)rwswap_memrrsswap)rNrQrRsinsoutrPs r swap_memoryrsF#'=?? E4sDD%222G =dGS$ ? ??cZtj\}}}}}t|||||S)z+Return system per-CPU times as a namedtuple)rw cpu_timesrYrZs rrrs0$(N$4$4!D$c T4s 3 33rcg}tjD]2}|\}}}}}t|||||}||3|S)'Return system CPU times as a namedtuple)rwrrYappend)retcpu_tr[r\r]r^r_items rrrs^'))  E,1 )D$cT4s;;D JJt     rctdkrtgStjrt ddt_tgS)rr&supported only starting from FreeBSD 8T)cpu_count_logicalrr __called__NotImplementedErrorrrrrsN   ! # #KK=  # P%&NOO O#'   }rFc(tjS)z0Return the number of logical CPUs in the system.)rwrrrrrrs  ! # ##rc.tdkrdndS)Nr)rrrrcpu_count_physicalrs%''1,,qq$6rc~d}tj}||d}|dkrt|d|dz}tj|} t |dpd}|n#|wxYw|stdkrdS|S)z1Return the number of physical CPUs in the system.Nz r.zgroup/children/group/cpur) rwcpu_count_physrfindET fromstringlenfindallclearr)rsindexroots rrrs   ! ! =GGK((E{{juqyjM}Q''!dll+EFFGGO4CJJLLLLDJJLLLL !""a''q s $BB$ctrtj\}}}}}ntrtj\}}}}}}}t dd5}|D]>}|dr't |d}? dddn #1swxYwYn"trtj\}}}}}}}tj ||||S)z*Return various CPU stats as a named tuple.z /proc/statrtsintrrN) r rw cpu_statsrryrzr{r|rr scpustats) ctxswintrs soft_intrssyscallstrapsfaultsforksr~rs rrrs659N4D4D1uj(EE  N   Auj(E65 , % % 1 1 1??7++1 Q00E 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1  N   Auj(E65  UE:x @ @@sAB##B'*B'c g}tj}|D];}|\}}}}dx}} tj|||||| } || <|S)zReturn mounted disk partitions as a list of namedtuples. 'all' argument is ignored, see: https://github.com/giampaolo/psutil/issues/906 N)rwdisk_partitionsr sdiskpartr) allretlist partitions partitiondevice mountpointfstypeoptsmaxfilemaxpathntuples rrr?sw G%''J +4( FD  '"6:vt#*G55v Nrct}i}|D]} tj|}tj|}tj|\}}t tdrtj|}tj ||||||<#t$r }|j tj krYd}~d}~wwxYw|S)z)Get NIC stats (isup, duplex, speed, mtu). NicDuplexN) net_io_counterskeys cext_posix net_if_mtunet_if_is_runningnet_if_duplex_speedhasattrrr snicstatsOSErrorerrnoENODEV)namesrrKmtuisupduplexspeederrs r net_if_statsr\s    " " $ $E C D D D'--C/55D&:4@@MFE w ,, 3 *622)$sCCCII   yEL(()((((  Js?B++ C5CCc trg}tD]} t||}|D]G}t |}|||t j|Hp#ttf$rYwxYw|S|t j vr7td|dd dtDt|\}}t}trtjd}ntj}|D]D}|\} } } } } }}| |vr4| |vr0t#| | | | | |t$|}||Et |S)z System-wide network connections.invalid  kind argument; choose between , c,g|]}t|Srrepr.0xs r z#net_connections..s,H,H,HT!WW,H,H,Hrr)rpidsProcess connectionslistrrsconnrrr ValueErrorjoinsetrrwnet_connectionsr TCP_STATUSESadd)kindrpidconsconnfamiliestypesrawlistrfdfamtypeladdrraddrrnts rrrps 66 5 5C 5s||//55!55D::DKK$$$JJw}d344445"=1      7$$$j DD$)),H,Hi,H,H,H"I"I"IKLL LoOHe %%C )&r**&((370CueVS (??tu}}CueV ,c33B GGBKKK 99s"BBBc tj\}}}n#t$rYdSwxYw|dk}|r tj}n|dkr tj}n|dz}tj|||S)zReturn battery info.Nrr<)rwsensors_batteryrrPOWER_TIME_UNLIMITEDPOWER_TIME_UNKNOWNsbattery)rPminsleft power_pluggedsecslefts rrrs /3/C/E/E ,GX}}"   44 &*  %3HH ^^1HH"}H=AAAs  ((c 8tt}t}t|D]g} t j|\}}|dkrd}d|z}|dtj||||X#t$rYdwxYw|S)z?Return CPU cores temperatures if available, else an empty dict.rNzCore %scoretemp) rrrrangerwsensors_cpu_temperaturerrshwtempr)rnum_cpuscpucurrenthighrKs rsensors_temperaturesrs$$&&??  C  $ >@@@@&     sAB  BBcfg}t}t|D]} tj|\}}n#t$rY(wxYw|r t |dddd}n#ttf$rd}YnwxYw t |dddd}n#ttf$rd}YnwxYw| tj ||||S)zReturn frequency metrics for CPUs. As of Dec 2018 only CPU 0 appears to be supported by FreeBSD and all other cores match the frequency of CPU 0.  r/rN) rrrw cpu_frequencyrr{r| IndexErrorrrrscpufreq)rrrravailable_freqmin_freqmax_freqs rcpu_freqrs^ $&&?? F FC *.*#7#7#<##7#7#<#  rcg}tj}|D]Q}|\}}}}}|dkr tsJd}|dkr"tj||pd|||}||R|S)z:Return currently connected users as a list of namedtuples.rN~)rwusersrrsuserr) rrrr[ttyhostnametstamprrs rrrsGjllG+/(c8VS "99NN7C #::  ]4h D Dr Nrc tddS#t$rYdSt$rYdSwxYw)NrTF)rrKrr rrr _pid_0_existsrsa  t uu tts!% ? ??ctj}tr(d|vr$tr|dd|S)z7Returns a list of PIDs currently running on the system.r)rwrrrinsert)rs rrrs@ )++CASLLmooL 1a JrcRtj|}|s|tvSdS)zReturn True if pid exists.T)r pid_existsr)rexistss rr!r! s/$S)) $&&= 4rc tj|td}|tjkS#t$rYdSwxYw)NrF)rwproc_oneshot_infokinfo_proc_mapSZOMB Exception)rsts r is_zombier)sP  #C ( ()A BTZ uus47 AAcFtjfd}|S)z`Decorator which translates bare OSError exceptions into NoSuchProcess and AccessDenied. c |g|Ri|S#t$rOt|jr t|j|j|jt |j|jt$rt|j|jt$r8|jdkr+dtvrt|j|jwxYwNr) rr)rr_name_ppidrrr rr)selfargskwargsfuns rwrapperz wrap_exceptions..wrapper#s 3t-d---f-- -! : : :"" :#DHdj$*EEE#DHdj999 5 5 5tx44 4   x1}};;&tx<<<   s B >{>DH#<== > > > > > > > > > > > > > > > > > >llnnG WQZ((.B.rsA::A>A>ctr |jdkrgStr tj|jS#t $r}|jt jkrot|jr t|j|j |j t|js t|j|j |j gcYd}~Sd}~wwxYwtj|jSr,)rrrrw proc_cmdlinerrEINVALr)rr-r.r!r)r/rs rrRzProcess.cmdlines  /tx1}}I  / (222   9 ,, **"+DHdj$*MMM'11"+DHdj$*MMM "  $TX.. .s"6 C A>C>C CC c4tj|jSr=)rw proc_environrrAs renvironzProcess.environs ***rc|td}tj} ||S#t$rYdSwxYw)Nr+)rEr%rget_terminal_mapKeyError)r/tty_nrtmaps rterminalzProcess.terminalsXw 78(** <    44 sA AAcd|td|_|jS)Nr)rEr%r.rAs rrz Process.ppids#\\^^N6$:; zrc|}tj|td|td|tdS)Nrr!r#)rErpuidsr%r/rawtuples ruidsz Process.uidsJ<<>>} ^J/ 0 ^O4 5 ^K0 133 3rc|}tj|td|td|tdS)Nr%r'r))rErpgidsr%rcs rgidsz Process.gidsrfrc|}tj|td|td|td|tdS)Nr7r9r;r=)rErrdr%rcs rrzProcess.cpu_timessX<<>> ^K0 1 ^J/ 0 ^N3 4 ^M2 3 55 5rcL|tdS)NrIrEr%rAs rcpu_numzProcess.cpu_nums<<>>.":; ;rc |}t|td|td|td|td|tdS)Nr?rArCrErG)rEr`r%rcs r memory_infozProcess.memory_infosb<<>> ^E* + ^E* + ^I. / ^I. / ^J/ 0 22 2rcL|tdS)Nr-rlrAs rr-zProcess.create_times||~~n];<>~ ^$67 8 ^$89 :<< .s0L0L0LQa0L0L0Lr)r rrrrwrrr rrrBrproc_connectionsr)r/rrrrrrrrrrrrrrs rrzProcess.connectionss y * $dii0L0L)0L0L0L&M&M&MOPP P  'oOHeC*4844G # #;?8CueVSdh(??tu}}'CueV(466BJJrNNN    99 #D/%'(EBB  D26 /BT5%CueV ,..B JJrNNNN  !     rNcBtj|j||jSr=)rwait_pidrr-)r/timeouts rwaitz Process.waits 7DJ???rc4tj|jSr=)r getpriorityrrAs rnice_getzProcess.nice_gets%dh///rc6tj|j|Sr=)r setpriorityr)r/values rnice_setzProcess.nice_set#s%dh666rc|td}t|dS)Nr?)rEr% PROC_STATUSESget)r/codes rrzProcess.status's/||~~nX67  s+++rc|}tj|td|tdddS)Nr3r5r)rErpior%rcs r io_counterszProcess.io_counters-sD<<>>{ ^O4 5 ^$45 6    rctr |jdkrdStstrt j|jpdSt trdnd)z)Return process current working directory.rNrrN)rrrHAS_PROC_OPEN_FILESrwproc_cwdrr rAs rcwdz Process.cwd6sg  !tx1}}4  !* !=**2d 2% 88!! !rmmaprhrjctr=)rrAs r_not_implementedzProcess._not_implementedKs!!rcLtj|j}d|DS)z8Return files opened by process as a list of namedtuples.c>g|]\}}tj||Sr)r popenfile)rpathrs rrz&Process.open_files..Us)HHHHD"G%dB//HHHr)rwrr)r/rs r open_fileszProcess.open_filesQs**4844GHHHHH Hrcntj|j}tr||S)z=Return the number of file descriptors opened by this process.)rwrrrrBrDs rnum_fdszProcess.num_fds\s5#DH--C %""$$$Jrc4tj|jSr=)rwproc_cpu_affinity_getrrAs rcpu_affinity_getzProcess.cpu_affinity_getjs-dh77 7rc~tttt}|D]}||vrt d||fz t j|j|dS#t$rB}|j tj tj fvr|D]}||vrt d||fzd}~wwxYw)Nz#invalid CPU #%i (choose between %s)) tuplerrrrrwproc_cpu_affinity_setrrrrVEDEADLK)r/cpusallcpusrrs rcpu_affinity_setzProcess.cpu_affinity_setns E#moo"6"67788G 7 7g%%$%J(+W~&6777& *48T:::::    9u} ===#33g--", E$'I2!2#3#33. sA00 B<:=B77B<c4tj|jSr=)rwproc_memory_mapsrrAs r memory_mapszProcess.memory_mapss(22 2rc|tj|j|St|dkrt dt |z|\}}tj|j|||S)Nr z4second argument must be a (soft, hard) tuple, got %s)rwproc_getrlimitrrrrproc_setrlimit)r/resourcelimitssofthards rrlimitzProcess.rlimitsv~*48X>>>v;;!##$!#'<<0111$ d*48XtTJJJr)r~r=)0__name__ __module__ __qualname____doc__ __slots__r>rBr6rrErHrKrKrSrRrYr_rrerirr rmromemory_full_infor-rtrwrsrrrrrrrrnt_mmap_grouped nt_mmap_extrrrHAS_PROC_NUM_FDSrrrrrrrrrrIs);;333I !!! _ ***,,,FF_F_.//_/2++_+__33_333_355_5<  < <  <22_2#==_=''_'<<_<   _ _B@@@_@00_077_7,,_, _ ! !_ !!j<>>O*HJJK""" &  I I  I I &  #      #-K  8 8  8     0  3 3  3  K K K  K K KI-K-Krrr)F)~r contextlibrr4rPxml.etree.ElementTreeetree ElementTreer collectionsrrrNrrrrwr rr r r r rrrrrrr_compatrrrr__extra__all__SIDL STATUS_IDLESRUNSTATUS_RUNNINGSSLEEPSTATUS_SLEEPINGSSTOPSTATUS_STOPPEDr& STATUS_ZOMBIESWAITSTATUS_WAITINGSLOCK STATUS_LOCKEDrSDEAD STATUS_WAKINGSONPROCTCPS_ESTABLISHEDCONN_ESTABLISHED TCPS_SYN_SENT CONN_SYN_SENTTCPS_SYN_RECEIVED CONN_SYN_RECVTCPS_FIN_WAIT_1CONN_FIN_WAIT1TCPS_FIN_WAIT_2CONN_FIN_WAIT2TCPS_TIME_WAITCONN_TIME_WAIT TCPS_CLOSED CONN_CLOSETCPS_CLOSE_WAITCONN_CLOSE_WAIT TCPS_LAST_ACK CONN_LAST_ACK TCPS_LISTEN CONN_LISTEN TCPS_CLOSING CONN_CLOSINGPSUTIL_CONN_NONE CONN_NONEr getpagesizePAGESIZEAF_LINKrHAS_PER_CPU_TIMESrrrrdictr%rMrYr`pfullmemrdrgrirkrrrrrrrrr disk_usagedisk_io_countersr net_if_addrsrrrrrrrrrr!r)r6contextmanagerr9objectrrrrrsh <;  """""""""""""""######!!!!!!))))))!!!!!!######++++++""""""""""""""""""&&&&&&$$$$$$'''''' ( 7& 7) W, G* G) G* G)MM  7& W, G* G) G) 7( g,'MM*  7& W, G* G) 7( g, M 73-G1'0'0/g('1-g)w+7,   ": ! # #  GD/22wt%788gd$5667400  1Q!  a  Q !a !Rr"2b R!"#$%& '( )* B+, B-.R/0 212 3F   LLL M M J::: < < z&AAABB  J{MMM O O  ACC  JI K K  Cj%2%2%233GG j%B%B%BCCGCCC(@@@444 %  %M$$$  f77778AAAF      (&& (   P 9BBB "<   *   %f %$J2  1 1 1 LKLKLKLKLKfLKLKLKLKLKr