j }ddlZddlZddlZddlmZddlmZmZmZm Z m Z m Z m Z m Z mZmZmZmZddlmZddlmZmZgdZdZdZd Zd Zd ZGd d ejZGddeZGddeZ ddZ!dZ"ddZ#dS)N) uidconverter) BY_USAGE_PERCENT ParseDatetimeSmartFormatter alias_actionargparse_process_periodcheck_from_zero_to_max_intcheck_non_negative_intcheck_percentagescheck_positive_intformat_aliases period_type period_type2)prepare_attention_json)get_lve_versionget_supported_columns)lveinfo_parser dbgov_parsertime_unit_type-)ALIAS 1ALIAS 2zALIAS 3 DESCRIPTION)cpu_avgcpuaCPUaverage CPU usage)cpu_maxrmCPU max CPU usage)vmem_avgvmemaVMemaverage virtual memory usage)vmem_maxr&mVMemmax virtual memory usage)mep_avgepaEP:average number of entry processes (concurrent connections))mep_maxmepmEP6max number of entry processes (concurrent connections))pmem_avgpmemaPMemaverage physical memory usage)pmem_maxr5mPMemmax physical memory usage) nproc_avgnprocaNprocaverage number of processes) nproc_maxr<mNprocmax number of processes)io_avgioaIOaverage io usage)io_maxrCmIO max io usage)iops_avgiopsaIOPS)average io operations; (LVE version >= 8))iops_maxrJmIOPS%max io operations; (LVE version >= 8)) r)mcpurCPUf$total number of max CPU usage faults)memr#VMemF,total number of out of virtual memory faults)r.r*EPf*total number of max entry processes faults)r2r2PMemF-total number of out of physical memory faults)r9r9NprocF$total number of max processes faults)r@r@IOftotal number of max io faults)rGrGIOPSf= 8)) any_faultsanyanyF#total number of faults of all types))rrr)rrr)rr r!)total_cpu_faultsrNrO)r"r$r%)r&r'r()total_vmem_faultsrQrR)r)r+r,)r-r/r0)total_ep_faultsrSrT)r1r3r4)r5r6r7)r8r:r;)r<r=r>)r?rArB)rCrDrE)total_pmem_faultsrUrV)total_nproc_faultsrWrX)total_io_faultsrYrZ)rFrHrI)rJrKrL)total_iops_faultsr[r\)r]r_r`)') COLUMN_NAMEr)FromzShow start period statistics)TozShow end period statistics)IDzLVE Id or username)rzAverage CPU usage)uCPUz-The percentage of user-allocated resource CPU)r deprecated)lCPUz CPU Limit)rNzOut Of CPU usage Faults)r+zAverage Entry Processes)uEPz9The percentage of user-allocated resource Entry processes)r/rm)lEPzmaxEntryProc limit)r$zAverage Virtual Memory Usage)uVMemz8The percentage of user-allocated resource Virtual Memory)r'rm)lVMemzVirtual Memory Limit)rQzOut Of Memory Faults)rSzEntry processes faults)r3zAverage Physical Memory Usage)uPMemz9The percentage of user-allocated resource Physical Memory)r6rm)lPMemzPhysical Memory Limit)r:zAverage Number of processes)uNprocz=The percentage of user-allocated resource Number of processes)r=rm)lNproczLimit of Number of processes)rUzOut Of Physical Memory Faults)rWzNumber of processes faults)rAz Average I/O)uIOz-The percentage of user-allocated resource I/O)rDrm)lIOz I/O Limit)rYzOut Of I/O usage Faults)rHz*Average I/O Operations; (LVE version >= 8))rKzdeprecated; (LVE version >= 8))uIOPSzLThe percentage of user-allocated resource I/O Operations; (LVE version >= 8))lIOPSz(I/O Operations Limit; (LVE version >= 8))r[z0Out Of I/O Operations Faults; (LVE version >= 8)c(eZdZdZdZddZdZdS)ArgParsecd|vr|dnd|_d|_d|_d|_t jj|g|Ri|dS)Ndbengine)popr~ lve_versionchanged_optionsoutput_error_handlerargparseArgumentParser__init__)selfargskwargss /builddir/build/BUILDROOT/lve-stats-4.3.2-1.el9.x86_64/opt/cloudlinux/venv/lib/python3.11/site-packages/lvestats/lib/parsers/lveinfoargparse.pyrzArgParse.__init__sf2<2F2F :...D #$(!(?????????cd|jD}||vr(td|dd||jt d||jvS)Ncg|] }|j S)dest).0actions r z,ArgParse.was_not_changed..s@@@ @@@rz no such item z; you can use only z, zIYou can use method "was_not_changed" only after used method "parse_args")_actions ValueErrorjoinrAttributeError)rr actions_dests rwas_not_changedzArgParse.was_not_changedst@@$-@@@ | # #_T__diiP\F]F]__`` `   ' !lmm m4///rNc :|tjdd}d|vsd|vr t|_tj|||}tt| |t j d|_ t||j rB|d}tj|j ||j|jpd|_|dr|js|jrd|_|S) N-j--jsonr namespacer server_idlimit)sysargvrrrr parse_argstuplevars_parse_known_args Namespacerruser get_defaultrusername_to_uidrr~idrcsvjsonr)rrrlocal_server_ids rrzArgParse.parse_argss <8ABBD %+66t$R[6\\  %T$*@*@xGYG[G[*\*\]^*_%`%`aa *** > ["..{;;O'71DdmUU[XZ L    ( ( im y~ IOrct|jdr.||}|d|dStj||dS)N__call__r)statusmessage)hasattrrexitrrerror)rr error_strs rrzArgParse.errorse 4,j 9 9 911'::I IIQ I 2 2 2 2 2  # ) )$ 8 8 8 8 8rNN)__name__ __module__ __qualname__rrrrrrrr|r|sX@@@000299999rr|ceZdZddZdS)ArgParseLVEInfoNc*t|||}|jrtj|j|_|jrtj|j|_|ds#|js|j s| d|j '|j t|j |j|_ d|jvs|jr-|jdkr"gdt%dz|_d |_nX|d s d|jvr:t%|j |j }|jr d d g|z|_n dg|z|_|dr8|js1|jt)|dz }||_|dr+|jr$|jr|jdks |jdkrd|_|dr|jd|_|S)Nr time_unit:--id or --user option should be specified with --time_unit)r~rallv2)rirjrk)rT show_columns)rmoderirjrkfromrv1rrr)r|r reseller_namerconvert_name_to_lvp_idr reseller_idconvert_id_to_lvp_idrrrrr~rrrshow_allcompatrtogetattr total_secondsrrstyler)rrr show_columns_dts rrzArgParseLVEInfo.parse_argssH''49'MM  " X'>y?VWWIL   T'T5T5T1d>NU^UefffM| @*0$-)G &&*.-)? &    , , 5Y\ 5 6 : ::B"$"2"2"4"4I     , , % %)- %_..)2Bd2J2J"$I     ( ( Y\-EIOrrrrrrrrrrrs())))))rrceZdZddZdS)ArgParseDBGOVInfoNc<t|||}t|jtr2t|jdtr|jd|_|jr d|jvs|jrt |d|_|jrOd|jvrF|jd}|jd|ddgz|j|dzdz|_| ds|js| d |S) Nrrall_columns_namesTSFROMTOrrr) r|r isinstanceformatlistrrrindexrr)rrrts_indexs rrzArgParseDBGOVInfo.parse_argss+''dI>> i& - - 3*Y=Ma=PRV2W2W 3(/2I    B)9 9 9Y=O 9&t-@AAI  < nDI$444 '--d33H(/  :fd^KiN^_gjk_k_l_lNmmI ##K00 U), U JJS T T Trrrrrrrrs(rrc H d}d}d}|ptj tt|d}t |dgd|}|dd t tjd z d d |ddt d d|d fdd| }|ddtd|dtd|ddtd|dd t|dtd t|d!"|d#d$t td%d&'|d(d)t|d*t|d!+| } | d,d-d t|t#|dd.t|d!/| d0d1d2d34|d5d6t|d7d8d9:|d;t&t)|d:| } | d?d@dAt+jdBCdDdEdFG| dHdId1d2dJ4|S)Kz Parser for dbgov statistics (use as subparser) :param config: parsed config :param _datetime_now: time now :param dbengine: database engine :return: ))ALIASr)conaverage connections; deprecated)rr)readaverage READ usage)writeaverage WRITE usage)r@zaverage READ+WRITE usage) rhrr)tsrztimestamp records)usernameUSERz user name)rrkzuser idrCPUr)rREADr)rWRITEr)rCONr)lcpurnz CPU limit)lreadlREADz READ limit)lwritelWRITEz WRITE limit)RESTRICTz3C-cpu restrict, R- read restrict, W- write restrict)rr)r@IOzaverage IO usagezF%(prog)s - Utility to display historical information about MySQL usage)formatter_classr~ descriptionr) rrrrrrrnrrr-f--from minutes+hrun report from date and time in [YY]YY-MM-DD[ HH:MM] format; if not present last 10 minutes are assumed)rdefaultnargshelp-t--tohrun report up to date and time in [YY]YY-MM-DD[ HH:MM] format; if not present, reports results up to now--periodc$t|SNrvalue datetime_nows rzdbgov_parser..E|E<'H'Hrtime period; specify minutes with m, h - hours, days with d, and values: today, yesterday; 5m - last 5 minutes, 4h -- last four hours, 2d - last 2 days, as well as todaytyper-u--userzSystem user name--idzUser id-l--limitz/max number of results to display, if 0 no limit --by-usage)R|show LVEs with usage (averaged) within z) percent 'of the limit available values: rrrrmetavar-p --percentage=defines percentage for --by-usage option; default %(default)s0..100rrrr-o --order-by*R|orders results by one of the following: rrr-bz--formatz)R|show only specific fields into output: rrrrr --show-all store_trueFz6full output (show all limits); brief output is defaultrrr --server_id --server-idr localhostFused with central database for multiple servers, default "%(default)s"rrr --time-unitaggregation_period<time step for grouping statistic in minutes; 1 min., by default; can use m|h|d suffixes;or can use dyn[amic] for using in v1 mode for example: 1h or 1h30m or 1d12h-c--csv?wrrHsave statistics in CSV format; "%(const)s" by default (output to screen)PATHrrconstrrrrdisplay output in JSON format)datetimenowrrsetattradd_argument_group add_argumentr timedeltaadd_mutually_exclusive_groupstrr r rrr r rgetrintrFileType) config _datetime_nowr~dbgov_order_by_dscrdbgov_columns_dscrdbgov_by_usage_dscrparser group_period group_user group_fieldsgroup_output_formatr s @rrrs:? n@!;H$5$9$9$;$;L ~(0+suuuF F' ` ` `bbb,,..L h}x1"==== w yyy  fm w yyy HHHHdeee 4466J hS !!!+   i8 >@@@ C 5H(I(IW9IWW1?@S1T1TWW    n#4>N LV^```  l<0C#D#D `>J];^;^ ` `6688L jL9K,L,L 344 ^.I[:\:\ ^ ^  \5 EGGG }3 ;P[8\8\ UWWW NC CWY[8\8\4]4]2333 !==??$$ gSx'8c'B'B'B# Wag%iii$$ h|U ,%... Mrc,|dvrdSt|S)zO ArgParse type for parsing time-unit with additional support dyn[amic] )dyndynamicr)r)r s rrr|s# """r5!!!rlveinfoc  |ptj gdt|ddz}t t d||d}dt d d D}||_|d d d ||dd| }|ddt tj dz ddd|ddt ddd|d fdd | } | d!d"td# | d$td% | d&td' | d(td) |d*d+d,d-d./|d0d1tt d2t#t d34|d5d6dtt$d7t&d8t#t$d39|d:d;t(t&d| } | d?dtt*d@t#t*d39| dAdBt,d dCdD>|dEdFdGgdGdHI|dJdKt.ddLM| } | dNdOdPt1jdQdRdSdTU| dVdWd,d-dX/|dYdZt|d[d\d]M|d^d,d-d_/| } | d`d,d-da/| dbdtt dczt5|ddt#t def|dgt6t9|dhdidjM|dkdltdm|dddno|dpdPt:dqr|S)sz Function for parsing command line arguments :param config: :param name: :param _datetime_now: :param ver: :param dbengine: :return: parsed arguments )rkrirjrrr7zD%(prog)s - Utility to display historical information about LVE usagez0Prefixes Kb, Mb and Gb indicates powers of 1024.)rrprogr~epilogcg|] }|d S)rr)r_s rrz"lveinfo_parser..s888!1888rrNz-vz --versionversion)rr[z--dbgovzshow MySql governor statistic)rrrrrrrzYYYY-MM-DD[ HH:MM])rrrrrrrrrc$t|Sr r r s rrz lveinfo_parser..rrrrrrzBUse username instead of LVE id, and show only record for that userrz(will display record only for that LVE idz--reseller-namezKUse reseller name instead of LVP id, and show only record for that resellerz --reseller-idz(will display record only for that LVP idz-dz--display-usernamer(Fz1try to convert LVE id into username when possibler)r!r"r#rr$r%rrz( percent of the limit available values: rrrrrr z --by-faultz@R|show LVEs which failed on max processes limit or memory limit z-rz --thresholdz`in combination with --by-fault, shows only LVEs with number of faults above; default %(default)sFAULTSz--styleradminzdeprecated, not used.)choicesrrrrzDmax number of results to display, if 0 no limit; default %(default)sr.r3r4r5r6rr8r9r:rrr<r*r+rr,r-z--servers-infozShow servers LVE versions"r'zUfull output (show all limits); brief output is default; equivalent --show-columns allz--show-columns))rrz@R|show only the listed columns; "all" for all supported columns rhr&r/r0r1r2z-mz--compat)rrzav1 - return old output mode; v2 - new mode; default %(default)s; you can change default in config)rr_rrz --blank-valuez3Use to fill unsupported limits; default "%(const)s")rr;r)r=r>rrErr COLUMNS_DSCRrrAr@rrBrCrDr r ORDER_BY_DSCRr BY_USAGE_DSCRrr BY_FAULT_DSCRr r rrGrrrFDEF_BLANK_VALUE)rHnamerIverr~ default_col cl_parserrrNrO group_by_faulrQgroup_show_columnsr s @rrrsN!;H$5$9$9$;$;L&&&)>FJJvW[D\D\)])])]]K&Z A CCCI98|ABB'7888"3I 4YLLL 9+JKKK//11L h}x1"==== w$ &&&  f]L w$ &&& HHHHdeee 7799J hS QSSS+ 7999 Z\\\4 7999 "< @BBB l< #>#> Z>-;X;X Z Zdkmmm l#l=.I.IP9IPP0>}0M0MPP   n#4>N LV^```0022MC ](C(C pQ_`mQnQn p p m"4a o9vw.?Wnooo  i8" SUUU$@@BB$$ gSx'8c'B'B'B# Wag%iii$$ h|U ,%...}3 ;P[8\8\ UWWWu )+++#??AA##\5 d$fff##L9V,W,Wk"" oQ_`lQmQm o o $ NC CWY[8\8\4]4]2333  jsL&**VUYBZBZ prrrs/ BDDD rr)rUNNN)$rr=r lvestats.libr#lvestats.lib.commons.argparse_utilsrrrrrr r r r r rrlvestats.lib.jsonhandlerrlvestats.lib.lveinfolibrr__all__rdrbrcrar`rr|rrrrrrrrrps %%%%%%                            <;;;;;JJJJJJJJ > > >e 0Z $P D*F ^2929292929x&292929j*****h***Z(eeeeP"""zzzzzzr