?HgF ddlZddlmZmZmZmZmZGddeZdedeeeeeffdZ de de fd Z deeeeeee e fffd Zdeee ffd ZdS) N)OptionalDictAnyStrUnionListceZdZdZdS) NotSupportedz5 Custom error to handle compatibility issues N)__name__ __module__ __qualname____doc__R/opt/cloudlinux/venv/lib/python3.11/site-packages/clsummary/hardware_statistics.pyr r s Drr file_contentreturncXg}|dD]}i}|s|dD]_}|d}t|dkr5|d||d<`|||S)a Parses the response of /proc files Since this file has a possibility to include multiple objects info, we need to parse all of them in the separate dicts :file_content: /proc file content. Example: processor : 0 vendor_id : AuthenticAMD processor : 1 vendor_id : AuthenticAMD_1 return: list of dicts with each node z  :r)splitlenstripappend)rresult info_object temp_dict info_attrvaluess rget_proc_info_as_list_of_dictsr!s$F#))&11!!    $**400 A AI__S))F6{{a/5ay/@/@ &)//++, i    MrvaluecVt|ddz S)z Helper to get numeric value of string record and convert it to mb :value: metric value from /proc file. Example: '512 KB' return: converted value. Example: 0.5 ri)floatr)r"s rconvert_string_kb_to_mb_valuer%2s$ q! " "T ))rc g}tjj}tjdtjst d|dvrt d|dtddd5}|}d d d n #1swxYwYt|}|D]}t| d d | d |t| d dt| dd d}|||S)a_ Prepare list of dicts with required cpu metrics The base of this method was taken from rhn_client_tools (src/up2date_client/hardware.py) Each CPU will be represented with a dict { "model": "foo", "cache_mb": 100, "frequency_mhz": 100, "id": 0 } return: list of dicts with cpu metrics z /proc/cpuinfozFile for cpuinfo is restricted!)x86_64i386z Machine arch z isn't compatible!rutf-8encodingN processor0z model namez cache size0 KBzcpu MHz)idmodelcache_mb frequency_mhz)osunamemachineaccessR_OKOSErrorr openreadr!intgetr%r$r) result_listr5f proc_cpuinfocpu_listcpucpu_dicts rget_cpu_metricsrD<s{"K HJJ E 9_bg . .97888 &&&D5DDDEEE osW 5 5 5 vvxx                -l;;H % %cggk3//00WW\5115cgglF6S6STT"3779c#:#:;;    8$$$$ s2BBBctjdtjstdt ddd5}|}dddn #1swxYwYt |d}t|dd t|d d d }|S) z Prepare dict of memory metrics Dict will be represented as: { "ram_mb": 8.5 "swap_mb": 2.04 } z /proc/meminfozFile for meminfo is restricted!r)r*r+NrMemTotalr/ SwapTotal)ram_mbswap_mb) r4r7r8r9r:r;r!r%r=)r? proc_meminfomem_dictrs rget_memory_metricsrLes 9_bg . .97888 osW 5 5 5 vvxx                .l;;A>H 0 Z0P0PQQ0k61R1RSSF MsA""A&)A&)r4typingrrrrr Exceptionr r!strr$r%r<rDrLrrrrPs4 66666666666666     9    (4' ()>******&htF,1&%2D,E-F(GHI&&&&RD/r