当前位置:网站首页>The manual is not complete. How to manually dig out the monitoring information of tongweb?

The manual is not complete. How to manually dig out the monitoring information of tongweb?

2022-07-19 14:20:00 Radish and cabbage.

Preface

        TongWeb Provide several types of monitoring interfaces , How to get information through these interfaces ?    We go through TongWeb7.0.4.2 How to get the version . notes : Changing the version is not necessarily right .

One 、 adopt JMX Interface acquisition Mbean Information

       TongWeb Of JMX Default on , adopt server.log obtain JMX  url, See more :https://blog.csdn.net/realwangpu/article/details/109506744

 [INFO] [main] [systemout] [tuserport:0;jcport:0]
 [INFO] [main] [admin] [URL for the Standard JMXConnectorServer : (service:jmx:rmi:///jndi/rmi://192.168.163.1:7200/jmxrmi)]
 [INFO] [main] [core] [Starting service TONGWEB]
 [INFO] [main] [core] [Starting Servlet Engine: TongWeb]

        To write JMX Program , The main information obtained can often be :JVM Memory 、 Thread pool 、 Data source connection pool 、 application session Count 、 Number of application requests ,demo as follows :

package com.tong;
import java.util.HashMap;
import java.util.Map;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;

public class TestJMX {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try {
			//  establish JMX  Of URL
			JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://127.0.0.1:7200/jmxrmi");
			//  Construct the authentication information used to obtain the connection , Users using the security domain .
			Map env = new HashMap();
			env.put("jmx.remote.credentials", new String[] { "thanos", "thanos123.com" });
			JMXConnector connector = JMXConnectorFactory.connect(url, env);
			MBeanServerConnection mbsc = connector.getMBeanServerConnection();
			// Appoint ObjectName 
			ObjectName mbeanName = new ObjectName("TONGWEB:type=ThreadPool,name=\"http-nio2-0.0.0.0-8088\"");
			Object obj = mbsc.getAttribute(mbeanName, "maxThreads");
			System.out.println("8088 maxThreads Attribute is " + obj.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

        Want to get relevant monitoring values , The main problem is ObjectName Acquisition . because TongWeb The manual is incomplete 、 Different TongWeb Small version of ObjectName Are not the same as , So I want to get the real ObjectName There's only one way : By opening the  jconsole Manually find the corresponding monitoring value , One word formula : Planing .

        Be careful : Be sure to pay attention to TongWeb Small version number of , such as : yes , we have TongWeb edition 8088 Port of ObjectName by : TONGWEB:type=ThreadPool,name="http-nio2-0.0.0.0-8088" , Others TongWeb edition 8088 Port of ObjectName by :   TONGWEB:type=ThreadPool,name="http-nio2-8088" ; As shown in the figure below, it is replaced by invincible hawk Hulk After data source , The monitoring value is even different .

Two 、 adopt rest Interface acquisition TongWeb Information

          Import... In the application HttpClient4 what is needed jar package httpclient-4.x.jar、 httpcore-4.x.jar、commons-logging.jar,${TW_HOME}/lib/agent In the catalog common-7.0.jar file .demo as follows :

package com.tong;

import com.tongweb.httpclient.utils.HttpClient4Util;

public class TestRest {

	public static void main(String[] args) {
		String result = null;
		try {
            // Notice to use a thanos Users outside , Otherwise, the logged in console will be kicked out thanos user 
			result = HttpClient4Util.execute("/rest/api/listener_detail", "GET", "thanos", "thanos123.com", "127.0.0.1",
					"9060", null);
			System.out.println(result);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

          Be careful : This rest  Only some interfaces provided by the manual , The manual provides , I don't know what I haven't provided , Can not be like jconsole Do the same .

3、 ... and 、 Get the monitoring values of all nodes through centralized management

          Adopt centralized management , adopt heimdall management TongWeb Each node , And then visit  http://127.0.0.1:9060/heimdall/notinrealm/rest/monitor/ibm/view  You can get each TongWeb The running state of the node 、 Memory 、JDBC data source 、 Thread pool 、 Application monitoring information json data .

{
    "nodes": [
        {
            "monitorList": [
                {
                    "appname": "", 
                    "dbname": "", 
                    "monitorName": "nodestatus", 
                    "monitorType": "warn", 
                    "monitorValue": "stopped", 
                    "servletName": "", 
                    "threadPoolName": ""
                }, 
                {
                    "appname": "", 
                    "dbname": "", 
                    "monitorName": "OOM", 
                    "monitorType": "warn", 
                    "monitorValue": "", 
                    "servletName": "", 
                    "threadPoolName": ""
                }
            ], 
            "nodeHome": "D:\\TongWeb7042\\TW7E\\domains\\aa", 
            "nodeIp": "192.168.163.1", 
            "nodeStatus": "stopped"
        }
    ]
}

原网站

版权声明
本文为[Radish and cabbage.]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/200/202207172046050848.html