
    F-i                     x    d dl Z d dlmZ d dlmZ d dl d dlmZ  G d dej                  j                        Zy)    N)Path)Response)*)get_metrics_textc                   ^    e Zd ZdZedefd       Zej                  j                  d        Z
y)CmfMetricsViewz/metricsreturnc                  &   t         j                         } d}d}d}d}i }i }g }t        j                         }t        d      j	                         D ]  }	|	j
                  j                         s	 |	dz  j                         j                         }
|
d   t        |       k7  rR|j                  |	       |t        |
d         z  }t        |
d         ||	j
                  <   t        |
d         ||	j
                  <    t        j                  d       t        j                         }|D ]k  }		 |	dz  j                         j                         }
|d	z  }|t        |
d         ||	j
                     z
  z  }|t        |
d         ||	j
                     z
  z  }m t         j                  d
      }|}|dz  dz  }|||z
  z  |z  }|||z
  z  |z  }d|dd|dd|dd|dgddddddddddddddddddS # t        $ r Y w xY w# t        $ r Y w xY w)Nr   z/procstat            g      ?   
SC_CLK_TCKi   eva_app_process)namevalueeva_app_user_cpuseva_app_sys_cpus eva_app_memory_consumption_bytesgaugezEva App process quantityprocess)TYPEHELPUNITz"Eva App CPU units user utilizationcpusz!Eva App CPU units sys utilizationzEva App memory utilizationbytes)r   r   r   r   )recordsmeta)osgetpgrptimer   iterdirr   isdigit	read_textsplitFileNotFoundErrorstrappendintsleepsysconf)pgrouptotal_proccess	total_rsstotal_user_ticstotal_sys_ticks
user_times	sys_timessub_path_liststart_timestampproc_sub_pathr   stop_timestampticksr   r   r   r   s                    $./cmf/modules/index/views/metrics.py_get_metricszCmfMetricsView._get_metrics   s   
 	
	))+!E^335 	:M %%--/%.99;AAC Aw#f+%  /T"X&I-0b]J}))*,/RMIm(()	:" 	

3* 	MM%.99;AAC aNs48}z-:L:L/MMMOs48}y9K9K/LLLO	M 

<((+4q=4+?(+~/OPSXX*n.NORWW
 .,
 0.
 /-
 ?=( $6%$ $@"& $?"% $8#5!')
 )	
A % $ % s$   /!G4+!H4	H H	HHc           
         t        j                          }d}| j                         }|d   D ]B  }|d   }|d   |   j                         D ]  \  }}|d| d| d| dz  } || d|d    dz  }D t        j                  r5|t               z  }|d	z  }|d
z  }|dt        j                          |z
   dz  }|dz  }t        |d      S )N r   r   r    z#  
r   ud   # HELP eva_metrics_gen_duration_seconds Время генерации страницы метрик
z.# TYPE eva_metrics_gen_duration_seconds gauge
z!eva_metrics_gen_duration_seconds z# EOF
z:application/openmetrics-text; version=1.0.0; charset=utf-8)content_type)r#   r;   itemsconfigMETRICS_API_STATS_COLLECTr   r   )selfstbodymetricsrecordr   	meta_name
meta_values           r:   getzCmfMetricsView.getr   s    YY[##%i( 	2F&>D+26?4+@+F+F+H ?'J"YKqa
|2>>?tfAfWo.b11D		2
 ++$&&D{{DEED7		B7GrJJD	+ghh    N)__name__
__module____qualname____url__staticmethoddictr;   cmfviewsactionrK    rL   r:   r   r      sD    G`
$ `
 `
D 	YYi irL   r   )r#   pathlibr   flaskr   cmf.includecmf.util.metricsr   rS   rT   BaseViewr   rV   rL   r:   <module>r\      s.        -ziSYY'' zirL   