Your IP : 216.73.216.86


Current Path : /lib/fm-agent/plugins/__pycache__/
Upload File :
Current File : //lib/fm-agent/plugins/__pycache__/tomcat_jmx.cpython-36.pyc

3

q��ipL�@sHddlZddlZddlZddlmZmZeje�ZGdd�dej�Z	dS)�N)�java�javaxc'@s�eZdZdZdZdZdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhd=�!Zed>d?��Ze	d@dA��Z
e	dBdC��Ze	dDdE��Ze	dFdG��Z
dS)i�TomcatJMXPluginzCTomcat Plugin for the FortiMonitor Agent using JMX to collect data.Z
tomcat_jmxzTomcat (JMX)�Heap Memory Usage Used�	java.lang�MemoryN�HeapMemoryUsage�used�bytes�Heap Memory Usage Committed�	committed�Heap Memory Usage Init�init�Heap Memory Usage Max�max�Non-Heap Memory Usage Used�NonHeapMemoryUsage�Non-Heap Memory Usage Committed�Non-Heap Memory Usage Init�Non-Heap Memory Usage Max�Thread Count�	Threading�ThreadCount�count�OS Process CPU Load�OperatingSystem�ProcessCpuLoad�percent�OS System CPU Load�
SystemCpuLoad�OS Open File Descriptor Count�OpenFileDescriptorCount�Loaded Class Count�ClassLoading�LoadedClassCount�
Eden Space�
MemoryPool�Usage�
PS Eden Space�Par Eden Space�
G1 Eden Space�Survivor Space�PS Survivor Space�Par Survivor Space�G1 Survivor Space�
PS Old Gen�CMS Old Gen�
G1 Old Gen�Copy�GarbageCollector�CollectionCount�PS Scavenge�ParNew�G1 Young Generation�G1 Mixed Generation�MarkSweepCompact�PS MarkSweep�ConcurrentMarkSweep�G1 Old Generation)!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}tjj|�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�rD�'/usr/lib/fm-agent/plugins/tomcat_jmx.pyZ__get_object_name_from_tupleBs
z,TomcatJMXPlugin.__get_object_name_from_tuplecCsdddddg}i}x`|D]X}|j|�}|rB|dkrBtd|��q|rT|d
krTqqdd�|jd	�D�}|||<qWi}|d}x�t|�D]�\}	}
d|
i||	<xtdD]l}t|j|g��d
kr�|||	}n:t|j|g��d
kr�||d}n|dkr�td|��nq�|||	|<q�Wq�W|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_pathz"Missing %s information from configcSsg|]}|jd��qS)� )�strip)�.0�valuerDrDrE�
<listcomp>qsz?TomcatJMXPlugin.get_connections_from_config.<locals>.<listcomp>�,r=r)rHrI)rHrI)rGrHrIrJ)rHrI)�get�
ValueError�split�	enumerate�len)�cls�config�keys�data�key�	key_value�values�connections�hosts�indexrFrNrDrDrE�get_connections_from_configZs0



z+TomcatJMXPlugin.get_connections_from_configcCs�tj}d}|s$d}|jj|�tj}d|ks4d|krPd|j}|jj|�tj}|jd�}|s�y,tj�}|s�tj}d|j}|jj|�Wn(tj}d|j}|jj|�YnXy"|tjkr�tj	�r�tj
|�Wn"tj}d}|jj|�YnX|tjk�r�y�tj	��stj
|�tjj
�}|jd	��rt|jd
��rttjtjj�|jd	�|jd
�g�}|jtjjjj|�d|jd�t|jd��f}tjjj|�}tjjjj||�}	|	j�}
||
dfStk
�r�d}|jj|�YnX|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 foundrFrGzJMissing value in the [%s] block of the agent config file (e.g host, port).rJzYUnable 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.rHrIz*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�textkeyrQ�jpypeZgetDefaultJVMPathZisJVMStartedZstartJVMr�utilZHashMapZJArray�lang�String�putrr@ZremoteZJMXConnectorZCREDENTIALS�intZ
JMXServiceURLZJMXConnectorFactory�connectZgetMBeanServerConnection�	Exception�	exception)rVrW�status�msgrJZj_hashZj_array�urlZjmx_urlZjmx_soc�
connectionrDrDrEZ__get_connection�sl





z TomcatJMXPlugin.__get_connectionc
Cs�i}|j|�}i}g}xT|j�D]H}|j|�\}}}	d|d|df}
|	r`|jd|
|	f�q |||
<q W|j�s�|jjd�x|D]}	|jj|	�q�W|Stj	}d}	x|D]}|jj
|�q�Wx�|jj�D]�\}}
|j
|
�}g}xZ|j�D]N\}
}y|j|�|j|
�Wq�tk
�r:|jjd||
f�w�Yq�Xq�Wt|j��dk�rn|�rnd	}tj}d
|}	n
d}	tj	}|
d|
d}}||||	|d
�||<q�W|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
        z%s:%srFrGz%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�optionsrp�
error_message�unit)r`r\� _TomcatJMXPlugin__get_connection�appendrXrcrd�errorrarb�warning�JMX_MAPPING�items�,_TomcatJMXPlugin__get_object_name_from_tuple�getObjectInstancernrorU�UNSUPPORTED)rVrW�resultZconfigsr]�errors�entryrprsrqZconnection_keyr|rZrA�object_namerwrvryrDrDrE�get_metadata�sX





zTomcatJMXPlugin.get_metadatac	Cs|j|�}|rBx:|j�D]$}d|d|df}||kr|}qWn|d}|j|�\}}}	|	rr|jjd|	�dS|jj|�}
|
d|
d}}|j|
�}
yR|j|
�}|j	|j
�|�}|jj}d	|kr�|j
�S|j|�s�dS|j|�}|j
�S|jjd
|
�dSdS)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
        z%s:%srFrGrzFailed to get a connection: %sN��ZCompositeDataSupportz(Tomcat (JMX) plugin - %s bean not found.)r`r\rzrcrdr~rQr�r�ZgetAttributeZ
getObjectName�	__class__�__name__Z
floatValueZcontainsKey)rVrfrYrW�entriesr�Zpossible_matchrprsrqrAZattribute_nameZcomposite_data_keyr�Zobject_instanceZattribute_valueZattribute_class_nameZcheck_resultrDrDrE�check;s8





zTomcatJMXPlugin.check)rrrNrr	r
)rrrNrrr
)r
rrNrrr
)rrrNrrr
)rrrNrr	r
)rrrNrrr
)rrrNrrr
)rrrNrrr
)rrrNrNr)rrrNrNr)rrrNrNr)r rrNr!Nr)r"rr#Nr$Nr)r%rr&r%r'r	r
)r(rr&r(r'r	r
)r)rr&r)r'r	r
)r*rr&r*r'r	r
)r+rr&r+r'r	r
)r,rr&r,r'r	r
)r-rr&r-r'r	r
)r.rr&r.r'r	r
)r/rr&r/r'r	r
)r0rr&r0r'r	r
)r1rr&r1r'r	r
)r2rr3r2r4Nr)r5rr&r5r4Nr)r6rr3r6r4Nr)r7rr3r7r4Nr)r8rr3r8r4Nr)r9rr3r9r4Nr)r:rr3r:r4Nr)r;rr3r;r4Nr)r<rr3r<r4Nr)r��
__module__�__qualname__�__doc__rfrvr~�staticmethodr��classmethodr`rzr�r�rDrDrDrEr
s�.kHr)
�loggingrargrr�	getLoggerr��logger�PluginrrDrDrDrE�<module>s