|9eW ddlmZmZddlmZmZmZmZmZddl Z Gdde Z dedeeeeeffdZ d e defd Zdeeeeeeeefffd Zdeeeffd ZdS) )absolute_importdivision)OptionalDictAnyStrUnionListNceZdZdZdS) NotSupportedz5 Custom error to handle compatibility issues N)__name__ __module__ __qualname____doc__T/opt/cloudlinux/venv/lib64/python3.11/site-packages/clsummary/hardware_statistics.pyr r s Drr file_contentreturncpg}|dD]}t}|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)splitdictlenstripappend)rresult info_object temp_dict info_attrvaluess rget_proc_info_as_list_of_dictsr$s$F#))&11!! FF   $**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(3s$ q! " "T ))rc g}tjj}tjdtjst d|dvrt d|dtdd5}|}dddn #1swxYwYt|}|D]}t| dd | d |t| d d t| d d 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!rN 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=sv"K HJJ E 9_bg . .97888 &&&D5DDDEEE os # # qvvxx                -l;;H % %cggk3//00WW\5115cgglF6S6STT"3779c#:#:;;    8$$$$ s0BBBctjdtjstdt dd5}|}dddn #1swxYwYt |d}t|ddt|ddd }|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,NrMemTotalr/ SwapTotal)ram_mbswap_mb) r4r7r8r9r:r;r$r(r=)r? proc_meminfomem_dictrs rget_memory_metricsrLfs 9_bg . .97888 os # # qvvxx                .l;;A>H 0 Z0P0PQQ0k61R1RSSF MsA  A$'A$) __future__rrtypingrrrrr r4 Exceptionr r$strr'r(r<rDrLrrrrQsL1000000066666666666666      9    (4' ()>******&htF,1&%2D,E-F(GHI&&&&RD/r