当前位置:网站首页>手册不全,如何手工刨出TongWeb的監控信息?
手册不全,如何手工刨出TongWeb的監控信息?
2022-07-19 14:18:00 【蘿蔔白菜。】
前言
TongWeb提供幾類監控接口,如何通過這些接口獲取信息? 我們通過TongWeb7.0.4.2版本講解下獲取方式。注:換個版本就不一定對了。
一、通過JMX接口獲取Mbean信息
TongWeb的JMX默認開啟,通過server.log獲取JMX url,更多見: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]
編寫JMX程序,主要獲取的信息能常有:JVM內存、線程池、數據源連接池、應用session數、應用請求數等,demo如下:
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 {
// 創建JMX 的URL
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://127.0.0.1:7200/jmxrmi");
// 構造獲取連接所使用的認證信息,使用安全域的用戶。
Map env = new HashMap();
env.put("jmx.remote.credentials", new String[] { "thanos", "thanos123.com" });
JMXConnector connector = JMXConnectorFactory.connect(url, env);
MBeanServerConnection mbsc = connector.getMBeanServerConnection();
//指定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();
}
}
}想獲取相關的監控值,主要問題是ObjectName的獲取。因為TongWeb手册上不全、不同TongWeb小版本號的ObjectName也不一樣,所以想獲取真正的ObjectName只有一條路:通過打開 jconsole手工查找相應的監控值,一字訣:刨。
注意:一定要注意TongWeb的小版本號,比如:有的TongWeb版本8088端口的ObjectName為: TONGWEB:type=ThreadPool,name="http-nio2-0.0.0.0-8088" ,而有的TongWeb版本8088端口的ObjectName為: TONGWEB:type=ThreadPool,name="http-nio2-8088" ;如下圖換為無敵浩克Hulk數據源後,監控值更不同了。

二、通過rest接口獲取TongWeb信息
在應用程序中導入 HttpClient4 所需 jar 包 httpclient-4.x.jar、 httpcore-4.x.jar、commons-logging.jar,${TW_HOME}/lib/agent 目錄下的 common-7.0.jar 文件。demo如下:
package com.tong;
import com.tongweb.httpclient.utils.HttpClient4Util;
public class TestRest {
public static void main(String[] args) {
String result = null;
try {
//注意改用一個thanos外的用戶,否則會踢出已登錄控制臺的thanos用戶
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();
}
}
}注意:這個rest 接口只有手册提供的部分接口,手册提供就提供了,沒提供的就不知道了,不能像jconsole一樣去刨。
三、通過集中管理獲取所有節點監控值
采用集中管理方式,通過heimdall管理TongWeb各個節點,然後訪問 http://127.0.0.1:9060/heimdall/notinrealm/rest/monitor/ibm/view 即可得到各個TongWeb節點的運行狀態、內存、JDBC數據源、線程池、應用的監控信息的json數據。
{
"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"
}
]
}边栏推荐
- 【ACWing】2492. HH Necklace
- Logu: p4516 [jsoi2018] stealth action (tree DP, tree grouping knapsack statistical scheme number)
- Luo Gu: p3092 [usaco13nov]no change G
- 009 面试题 SQL语句各部分的执行顺序
- Unveil the mystery of service grid istio service mesh
- 洛谷P2422 良好的感觉 题解
- 4 a company has branches in six cities C1, C2, C3... C6. The connection between cities Ci and CJ (I, j=1,2,3,... 6) and the cost are listed in the following weighted adjacency matrix C
- Tke (k8s) deploy MySQL using CFS storage
- matplotlib绘制多折线图(解决matplotlib中文无法显示问题)
- 贝塞尔曲线简单介绍
猜你喜欢

A Classical Review of nonconvex optimization problems from Symmetry to Geometry, Rochester University, etc.

(with source code) a variety of machine learning models (knn\lr\rf\ada\xg\gbdt...) Model training in precipitation downscaling under

华为无线设备配置智能漫游

Several small open source projects of mine over the years

面额10exp(303)的钞票
![[acwing] solution of the 60th weekly match](/img/79/5cc097c7a432e40c4bda3ef5a167de.gif)
[acwing] solution of the 60th weekly match

Ranking of top ten ERP software systems at home and abroad!

unity 实现UI-背包装备拖拽功能

Use of Google browser developer tools (Master!)

华为无线设备配置静态负载均衡
随机推荐
Interview records
Is it true that tongdaxin opens an account? Is it safe for tongdaxin to open an account?
JSON path syntax introduction and usage scenarios
After 2000, he was hired as a special associate researcher of Nanjing University. He went to primary school at the age of 4 and was admitted to Nanjing University at the age of 14!
函数初认识-下
活动预告|Apache Doris x Apache SeaTunnel 联合 Meetup 开启报名!
Introduction:Multiple DataFrames
Event preview | Apache Doris x Apache seatunnel joint meetup to start registration!
unity 字幕滚动
Ranking of mainstream ERP systems, comparison of mainstream ERP systems
iVX低代码平台系列详解 -- 概述篇(二)
STL string find substring
FreeRTOS-空闲任务和阻塞延时的实现
Okaleido或杀出NFT重围,你看好它吗?
数据库的增删改查
洛谷:P4516 [JSOI2018] 潜入行动(树形dp、树上分组背包统计方案数)
类3实践
asterisk:No compatible codecs, not accepting this offer!
asterisk:No compatible codecs, not accepting this offer!
Silent AI: how does shengteng AI solve the problem of sign language learning with large models?