HEX
Server: Apache
System: Linux 185.122.168.184.host.secureserver.net 5.14.0-570.52.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Oct 15 06:39:08 EDT 2025 x86_64
User: barbeatleanalyti (1024)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //proc/self/root/lib/fm-agent/plugins/__pycache__/tomcat_jmx.cpython-39.pyc
a

��ipL�@sHddlZddlZddlZddlmZmZe�e�ZGdd�dej�Z	dS)�N)�java�javaxc"@s�eZdZdZdZdZdddddd	d
ddd
ddddddddddddddddddd d!d"d#d$d%�!Zed&d'��Ze	d(d)��Z
e	d*d+��Ze	d,d-��Ze	d.d/��Z
d0S)1�TomcatJMXPluginzCTomcat Plugin for the FortiMonitor Agent using JMX to collect data.Z
tomcat_jmxzTomcat (JMX))zHeap Memory Usage Used�	java.lang�MemoryN�HeapMemoryUsage�used�bytes)zHeap Memory Usage CommittedrrNr�	committedr	)zHeap Memory Usage InitrrNr�initr	)zHeap Memory Usage MaxrrNr�maxr	)zNon-Heap Memory Usage UsedrrN�NonHeapMemoryUsagerr	)zNon-Heap Memory Usage CommittedrrNr
r
r	)zNon-Heap Memory Usage InitrrNr
rr	)zNon-Heap Memory Usage MaxrrNr
rr	)zThread CountrZ	ThreadingNZThreadCountN�count)zOS Process CPU Loadr�OperatingSystemNZProcessCpuLoadN�percent)zOS System CPU LoadrrNZ
SystemCpuLoadNr)zOS Open File Descriptor CountrrNZOpenFileDescriptorCountNr)zLoaded Class CountrZClassLoadingNZLoadedClassCountNr)�
Eden Spacer�
MemoryPoolr�Usagerr	)�
PS Eden Spacerrrrrr	)�Par Eden Spacerrrrrr	)�
G1 Eden Spacerrrrrr	)�Survivor Spacerrrrrr	)�PS Survivor Spacerrrrrr	)�Par Survivor Spacerrrrrr	)�G1 Survivor Spacerrrrrr	)�
PS Old Genrrrrrr	)�CMS Old Genrrrrrr	)�
G1 Old Genrrrrrr	)�Copyr�GarbageCollectorr�CollectionCountNr)�PS Scavengerrr!r Nr)�ParNewrrr"r Nr)�G1 Young Generationrrr#r Nr)�G1 Mixed Generationrrr$r Nr)�MarkSweepCompactrrr%r Nr)�PS MarkSweeprrr&r Nr)�ConcurrentMarkSweeprrr'r Nr)�G1 Old Generationrrr(r Nr)!zmemory.heapzmemory.heap.committedzmemory.heap.initzmemory.heap.maxzmemory.non_heapzmemory.non_heap.committedzmemory.non_heap.initzmemory.non_heap.maxzthreading.countzos.cpu_load.processzos.cpu_load.systemzos.open_file_descriptorszclass_loading.loaded_classeszmemory_pool.edenzmemory_pool.eden.pszmemory_pool.eden.parzmemory_pool.eden.g1zmemory_pool.survivorzmemory_pool.survivor.pszmemory_pool.survivor.parzmemory_pool.survivor.g1zmemory_pool.old.pszmemory_pool.old.cmszmemory_pool.old.g1z
gc.young.copyzgc.young.ps_scavengezgc.young.par_newzgc.young.g1_generationzgc.mixed.g1_generationzgc.old.mark_sweep_compactzgc.old.ps_mark_sweepzgc.old.concurrent_mark_sweepzgc.old.g1_generationcCsP|d|d|d}}}d|}|r4|d|7}|rD|d|7}tj�|�S)a�returns a constructed ObjectName.

        :type tuple_:  tuple (label, domain, type, bean_name, attribute_name,
        composite_data_key, unit)
        :param tuple_: A tuple with all the information for an ObjectName. A
        string that represents the label, a string that represents the domain,
        and so on and so forth.

        :rtype: javax.management.ObjectName
        :return: An ObjectName object that can be used to lookup a MBean.
        ���z%s:zname=%s,ztype=%s)r�
managementZ
ObjectName)�tuple_�domain�type_Z	bean_nameZcanonical_name�r0�'/usr/lib/fm-agent/plugins/tomcat_jmx.pyZ__get_object_name_from_tupleBs
z,TomcatJMXPlugin.__get_object_name_from_tuplecCsgd�}i}|D]T}|�|�}|s8|dvr8td|��q|sH|dvrHqqdd�|�d�D�}|||<qi}|d}t|�D]�\}	}
d|
i||	<dD]l}t|�|g��d	kr�|||	}n:t|�|g��d	kr�||d
}n|dvr�td|��nq�|||	|<q�qz|S)a�
        Parse the config object to build a structure of connections parameters
        based on the number of entries that are in each key. The main parameter we base on
        to split off is host.

        :type config: dict (host, port, username, password, jvm_path)
        :param config: Dictionary with the information stored in the config file.

        :rtype: Dict
        :return: Dictionary with connection information split up in multiple if needed.
        )�host�port�username�password�jvm_path)r4r5z"Missing %s information from configcSsg|]}|�d��qS)� )�strip)�.0�valuer0r0r1�
<listcomp>q�z?TomcatJMXPlugin.get_connections_from_config.<locals>.<listcomp>�,r2)r3r4r5r6r)r)�get�
ValueError�split�	enumerate�len)�cls�config�keys�data�key�	key_value�values�connections�hosts�indexr2r:r0r0r1�get_connections_from_configZs2


�z+TomcatJMXPlugin.get_connections_from_configcCs�tj}d}|s$d}|j�|�tj}d|vs4d|vrPd|j}|j�|�tj}|�d�}|s�z,t��}|s�tj}d|j}|j�|�Wn(tj}d|j}|j�|�Yn0z |tjur�t�	�s�t�
|�Wn"tj}d}|j�|�Yn0|tju�r�z�t�	��st�
|�tj�
�}|�d	��rr|�d
��rrt�tjj�|�d	�|�d
�g�}|�tjjjj|�d|�d�t|�d��f}tjj�|�}tjjj�||�}	|	��}
||
dfWSt�y�d}|j�|�Yn0|d|fS)
a�
        returns a list of connections from the jpype library - a python interface to
        the Java Native Interface. Wheter there are 1 or many connections depends on the
        number of entries in the host, port and optionally username/password/jvm entries.

        :type config: dict
        :param config: Mapping of information under the application block for
         this plugin.

        :rtype: tuple (status, connection, error_message)
        :return: A tuple containing a numeric value corresponding to the
        agent_util status'. A MBeanServerConnection object. And, a string with
        an error message if any.
        NzNo JMX configuration foundr2r3zJMissing value in the [%s] block of the agent config file (e.g host, port).r6zYUnable to find JVM, please specify 'jvm_path' in the [%s] block of the agent config file.z;Unable to access JMX metrics because JVM cannot be started.r4r5z*service:jmx:rmi:///jndi/rmi://%s:%s/jmxrmizBUnable to access JMX metrics, JMX is not running or not installed.)�
agent_util�	SUPPORTED�log�info�
MISCONFIGURED�textkeyr>�jpypeZgetDefaultJVMPathZisJVMStartedZstartJVMr�utilZHashMapZJArray�lang�String�putrr,ZremoteZJMXConnectorZCREDENTIALS�intZ
JMXServiceURLZJMXConnectorFactory�connectZgetMBeanServerConnection�	Exception�	exception)rCrD�status�msgr6Zj_hashZj_array�urlZjmx_urlZjmx_soc�
connectionr0r0r1Z__get_connection�s|�
��


���
��z TomcatJMXPlugin.__get_connectionc
Cs�i}|�|�}i}g}|��D]H}|�|�\}}}	d|d|df}
|	r^|�d|
|	f�q|||
<q|��s�|j�d�|D]}	|j�|	�q�|Stj	}d}	|D]}|j�
|�q�|j��D]�\}}
|�
|
�}g}|��D]N\}
}z|�|�|�|
�Wq�t�y*|j�d||
f�Yq�Yq�0q�t|���dk�rZ|�sZd	}tj}d
|}	n
d}	tj	}|
d|
d}}||||	|d
�||<q�|S)areturns a json object who's textkeys correspond to a given metric
        available on the JVM.

        :type config: dict
        :param config: Mapping of information under the application block for
         this plugin.

         :return: JSON Object for all metrics
        �%s:%sr2r3z%s %sz#Unable to connect to any connection�z.Tomcat (JMX) plugin - %s bean not found at %s.r)Nz Unreachable %s at any connectionr�)�label�optionsr]�
error_message�unit)rMrI� _TomcatJMXPlugin__get_connection�appendrErPrQ�errorrNrO�warning�JMX_MAPPING�items�,_TomcatJMXPlugin__get_object_name_from_tuple�getObjectInstancer[r\rB�UNSUPPORTED)rCrD�resultZconfigsrJ�errors�entryr]r`r^Zconnection_keyrjrGr-�object_namererdrgr0r0r1�get_metadata�s^



��
�zTomcatJMXPlugin.get_metadatacCs|�|�}|r>|��D]$}d|d|df}||kr|}qn|d}|�|�\}}}	|	rn|j�d|	�dS|j�|�}
|
d|
d}}|�|
�}
zX|�|
�}|�	|�
�|�}|jj}d	|vr�|�
�WS|�|�s�WdS|�|�}|�
�WS|j�d
|
�YdS0dS)a�returns a value for the metric.

        :type textkey: string
        :param textkey: Canonical name for a metric.

        :type data: string
        :param data: Specific option to check for.

        :type config: dict
        :param config: Mapping of information under the application block for
         this plugin.

        :rtype: double
        :return: Value for a specific metric
        rar2r3rzFailed to get a connection: %sN��ZCompositeDataSupportz(Tomcat (JMX) plugin - %s bean not found.)rMrIrhrPrQrlr>rnroZgetAttributeZ
getObjectName�	__class__�__name__Z
floatValueZcontainsKey)rCrSrFrD�entriesrsZpossible_matchr]r`r^r-Zattribute_nameZcomposite_data_keyrtZobject_instanceZattribute_valueZattribute_class_nameZcheck_resultr0r0r1�check;s:


�



zTomcatJMXPlugin.checkN)ry�
__module__�__qualname__�__doc__rSrdrl�staticmethodrn�classmethodrMrhrur{r0r0r0r1r
sf							

		

										
								���4

-
j
Gr)
�loggingrNrTrr�	getLoggerry�logger�Pluginrr0r0r0r1�<module>s