一、tomcat 可監控的內容
tomcat 通過 jmx 的形式對外提供 tomcat 的監控數據,比如:堆內存使用情況、線程使用情況等。一般通過 jdk 的工具 jconsole、jvisualvm 工具連接 在 tomcat 上開的 jmx 端口,可以界面化看到。監控數據項在 tomcat 本身是通過 Mbean 提供的,要想知道 tomcat 有哪些 Mbean,可以使用 jconsole 進行查看,該工具默認就有 Mbean 這個 tab。
監控項類別 | 監控項 | 說明 |
Catalina:type=Connector,port=<端口> | URIEncoding | 編碼方式,默認 UTF-8 |
acceptCount | 可以建立的最大 tcp 連接數 | |
address | ||
ajpFlush | ||
allowTrace | ||
allowedRequestAttributesPattern | ||
ciphers | ||
ciphersUsed | ||
className | ||
connectionLinger | ||
enableLookups | ||
connectionTimeout | tcp 連接建立超時時間 | |
executorName | ||
keepAliveTimeout | 連接 keepalived 超時時間 | |
localPort | tomcat 啟動端口 | |
maxHeaderCount | ||
maxKeepAliveRequests | ||
maxParameterCount | ||
maxPostSize | ||
maxSavePostSize | ||
maxSwallowSize | ||
maxThreads | 最大http並發請求數 | |
minSpareThreads | 允許的最小http空閑請求線程數 | |
modelerType | ||
packetSize | ||
port | ||
processorCache | ||
protocol | http 請求所使用的協議 | |
protocolHandlerClassName | ||
proxyName | ||
proxyPort | ||
redirectPort | 默認是 8443 | |
scheme | 默認是 http | |
secret | ||
secretRequired | ||
secure | ||
sslProtocols | ||
stateName | ||
tcpNoDelay | ||
threadPriority | ||
useBodyEncodingForURI | ||
useIPVHosts | ||
xpoweredBy | ||
Catalina:type=GlobalRequestProcessor,name="http-nio-<端口>" 在代碼中Mbean 獲取時,可以配置 Catalina:type=GlobalRequestProcessor,name="*" |
bytesReceived | |
bytesSent | ||
errorCount | 從tomcat啟動以來 ,其處理的請求失敗的個數 | |
maxTime | 從tomcat啟動以來 ,處理的請求中耗時最長的時間 | |
modelerType | ||
processingTime | 從tomcat 啟動以來,處理請求所耗費的總時長 | |
Catalina:type=Host,host=localhost (localhost的信息,一般是在server.xml 中 host (localhost)的靜態配置信息) |
aliases | |
appBase | war包所在父目錄,默認為 webapps | |
autoDeploy | boolean 值,是否自動加載 | |
backgroundProcessorDelay | ||
children | 部署在 appBase下的war包列表 | |
configClass | ||
contextClass | ||
copyXML | ||
createDirs | ||
deployIgnore | ||
deployXML | ||
errorReportValveClass | ||
modelerType | ||
name | ||
startChildren | ||
startStopThreads | ||
stateName | 運行狀態 | |
undeployOldVersions | ||
unpackWARs | 布爾值,是否自動解壓war包 | |
valveNames | ||
workDir | ||
xmlBase | ||
Catalina:type=ProtocolHandler,port=8080 | acceptCount | |
acceptorThreadCount | ||
acceptorThreadPriority | ||
algorithm | ||
allowHostHeaderMismatch | ||
allowedTrailerHeaders | ||
aprRequired | ||
backlog | ||
ciphers | ||
clientAuth | ||
clientCertProvider | ||
compressableMimeType | ||
compressableMimeTypes | ||
compressibleMimeType | ||
compressibleMimeTypes | ||
compression | ||
compressionMinSize | ||
connectionCount | ||
connectionLinger | ||
connectionTimeout | ||
connectionUploadTimeout | ||
continueResponseTiming | ||
crlFile | ||
defaultSSLHostConfigName | ||
disableUploadTimeout | ||
domain | ||
globalRequestProcessorMBeanName | ||
keepAliveTimeout | ||
keyAlias | ||
keyPass | ||
keystoreFile | ||
keystorePass | ||
keystoreProvider | ||
keystoreType | ||
localPort | ||
maxConnections | ||
maxExtensionSize | ||
maxHeaderCount | ||
maxHttpHeaderSize | ||
maxKeepAliveRequests | ||
maxSavePostSize | ||
maxSwallowSize | ||
maxThreads | ||
maxTrailerSize | ||
minSpareThreads | ||
modelerType | ||
name | ||
nameIndex | ||
noCompressionStrongETag | ||
noCompressionUserAgents | ||
objectName | ||
pollerThreadCount | ||
pollerThreadPriority | ||
port | ||
processorCache | ||
rejectIllegalHeader | ||
rejectIllegalHeaderName | ||
relaxedPathChars | ||
relaxedQueryChars | ||
restrictedUserAgents | ||
sSLCACertificateFile | ||
sSLCACertificatePath | ||
sSLCARevocationFile | ||
sSLCARevocationPath | ||
sSLCertificateChainFile | ||
sSLCertificateFile | ||
sSLCertificateKeyFile | ||
sSLCipherSuite | ||
sSLDisableCompression | ||
sSLDisableSessionTickets | ||
sSLEnabled | ||
sSLHonorCipherOrder | ||
sSLPassword | ||
sSLProtocol | ||
sSLVerifyClient | ||
sSLVerifyDepth | ||
secure | ||
selectorTimeout | ||
sendReasonPhrase | ||
sendfileSupported | ||
server | ||
serverRemoveAppProvidedValues | ||
sessionCacheSize | ||
sessionTimeout | ||
sniParseLimit | ||
soLinger | ||
soTimeout | ||
sslEnabledProtocols | ||
sslImplementationName | ||
sslProtocol | ||
tcpNoDelay | ||
threadPriority | ||
trustManagerClassName | ||
trustMaxCertLength | ||
truststoreAlgorithm | ||
truststoreFile | ||
truststorePass | ||
truststoreProvider | ||
truststoreType | ||
useKeepAliveResponseHeader | ||
useSendfile | ||
useServerCipherSuitesOrder | ||
waitingProcessorCount | ||
Catalina:type=Server (tomcat 本身信息)
|
address | |
serverBuilt | tomcat 被編譯的版本 | |
serverInfo | tomcat 名稱 | |
serverNumber | ||
serviceNames | ||
shutdown | ||
stateName | 運行狀態 | |
Catalina:type=SocketProperties,name="http-nio-<端口>" | appReadBufSize | |
appWriteBufSize | ||
bufferPool | ||
bufferPoolSize | ||
directBuffer | ||
directBufferPool | ||
directSslBuffer | ||
eventCache | ||
processorCache | ||
soLingerOn | ||
soLingerTime | ||
soTimeout | ||
tcpNoDelay | ||
timeoutInterval | ||
unlockTimeout | ||
Catalina:type=StringCache | accessCount | |
byteEnabled | ||
cacheSize | ||
charEnabled | ||
hitCount | ||
trainThreshold | ||
Catalina:type=ThreadPool,name="http-nio-<端口>" (Catalina:type=ThreadPool,name=*) |
acceptCount | |
acceptorThreadCount | ||
acceptorThreadPriority | ||
alpnSupported | ||
bindOnInit | ||
connectionCount | 連接數 | |
connectionLinger | ||
connectionTimeout | 連接超時時間 | |
currentThreadCount | 當前線程池中總共可用線程數 | |
currentThreadsBusy | 當前並發正在處理的請求數 | |
daemon | 默認 true | |
executorTerminationTimeoutMillis | ||
keepAliveCount | ||
keepAliveTimeout | ||
localPort | ||
maxConnections | 最大連接數 | |
maxKeepAliveRequests | ||
maxThreads | 最大可並發處理的請求數 | |
minSpareThreads | ||
pollerThreadCount | ||
pollerThreadPriority | ||
port | tomcat 啟動端口 | |
running | ||
sSLEnabled | ||
selectorTimeout | ||
sniParseLimit | ||
sslImplementation | ||
sslImplementationName | ||
tcpNoDelay | ||
threadPriority | ||
useInheritedChannel | ||
useSendfile | ||
java.lang:name=G1 Old Generation,type=GarbageCollector | CollectionCount | 從 tomcat 啟動到目前為止,垃圾回收的次數 |
CollectionTime | 從 tomcat 啟動到目前為止,垃圾回收總共耗時時間 | |
LastGcInfo | ||
MemoryPoolNames | ||
Name | ||
Valid | ||
java.lang:name=G1 Young Generation,type=GarbageCollector | 監控項同 “java.lang:name=G1 Old Generation,type=GarbageCollector” | |
java.lang:type=Memory | HeapMemoryUsage | 堆內存使用情況 |
NonHeapMemoryUsage | 非內存使用情況 | |
java.lang:type=MemoryPool,name=CodeHeap 'non-nmethods' | PeakUsage | |
Usage | ||
UsageThreshold | ||
UsageThresholdCount | ||
UsageThresholdExceeded | ||
UsageThresholdSupported | ||
Type | NON_HEAP : 非堆 | |
java.lang:type=MemoryPool,name=CodeHeap 'non-profiled nmethods' | 同 “java.lang:type=MemoryPool,name=CodeHeap 'non-nmethods'” | |
java.lang:type=MemoryPool,name=CodeHeap 'profiled nmethods' | 同 “java.lang:type=MemoryPool,name=CodeHeap 'non-nmethods'” | |
java.lang:type=MemoryPool,name=Compressed Class Space | 同 “java.lang:type=MemoryPool,name=CodeHeap 'non-nmethods'” | |
java.lang:type=MemoryPool,name=G1 Eden Space | CollectionUsage | |
CollectionUsageThreshold | ||
CollectionUsageThresholdCount | ||
CollectionUsageThresholdExceeded | ||
CollectionUsageThresholdSupported | ||
PeakUsage | ||
Usage | ||
Type | HEAP:堆 | |
UsageThresholdSupported | ||
java.lang:type=MemoryPool,name=G1 Old Gen | CollectionUsage | |
CollectionUsageThreshold | ||
CollectionUsageThresholdCount | ||
CollectionUsageThresholdExceeded | ||
CollectionUsageThresholdSupported | ||
PeakUsage | ||
Usage | ||
Type | HEAP:堆 | |
UsageThreshold | ||
UsageThresholdCount | ||
UsageThresholdExceeded | ||
UsageThresholdSupported | ||
java.lang:type=MemoryPool,name=G1 Survivor Space | 同 “java.lang:type=MemoryPool,name=G1 Eden Space” | |
java.lang:type=MemoryPool,name=Metaspace | 同 “java.lang:type=MemoryPool,name=CodeHeap 'non-nmethods'” | |
java.lang:type=OperatingSystem | Arch | |
AvailableProcessors | 系統中 CPU 核數 | |
CommittedVirtualMemorySize | ||
FreePhysicalMemorySize | ||
FreeSwapSpaceSize | ||
MaxFileDescriptorCount | ||
Name | 操作系統名稱 | |
OpenFileDescriptorCount | ||
ProcessCpuLoad | ||
ProcessCpuTime | ||
SystemCpuLoad | ||
SystemLoadAverage | ||
TotalPhysicalMemorySize | ||
TotalSwapSpaceSize | ||
Version | 操作系統版本 | |
java.lang:type=Runtime | BootClassPathSupported | |
ClassPath | tomcat 運行時的 classpath | |
InputArguments | 設置給 tomcat 的 jvm 參數 | |
LibraryPath | ||
ManagementSpecVersion | ||
Name | PID + 系統的 hostname | |
Pid | tomcat 進程號 | |
SpecName | 如:Java Virtual Machine Specification | |
SpecVendor | 如:Oracle Corporation | |
SpecVersion | 如:11 | |
StartTime | tomcat 啟動時間,單位 毫秒 | |
SystemProperties | ||
Uptime | tomcat 持續運行時間,單位毫秒 | |
VmName | 如:OpenJDK 64-Bit Server VM | |
VmVendor | 如:Oracle Corporation | |
VmVersion | 如:11.0.5+10-LTS | |
java.lang:type=Threading | AllThreadIds | 活動的線程Id ,是一個 long 類型的數組 |
CurrentThreadCpuTime | ||
CurrentThreadCpuTimeSupported | ||
CurrentThreadUserTime | ||
DaemonThreadCount | 守護線程數 | |
ObjectMonitorUsageSupported | ||
PeakThreadCount | 實時峰值 | |
SynchronizerUsageSupported | ||
ThreadAllocatedMemoryEnabled | ||
ThreadAllocatedMemorySupported | ||
ThreadContentionMonitoringEnabled | ||
ThreadContentionMonitoringSupported | ||
ThreadCount | 活動的線程數 | |
ThreadCpuTimeEnabled | ||
ThreadCpuTimeSupported | ||
TotalStartedThreadCount | 已啟動的總數 | |
java.nio:name=direct,type=BufferPool | Count | |
MemoryUsed | ||
TotalCapacity | ||
java.nio:name=mapped,type=BufferPool | Count | |
MemoryUsed | ||
TotalCapacity | ||
java.lang:type=ClassLoading | LoadedClassCount | 已載入類數 |
TotalLoadedClassCount | 總共載入的類數量 | |
UnloadedClassCount | 已卸載的類數量 |
這個是各個 webapp 應用可監控的指標。
二、開啟 tomcat jmx 監控
1、在 tomcat jvm 參數中配置 jmx 參數
1) 查看 tomcat 的啟動腳本,閱讀腳本內容,查看該腳本中設置jvm參數是哪里,在其中加上 jmx 參數:
-Dcom.sun.management.jmxremote -Djava.rmi.server.hostname=192.168.23.1 -Dcom.sun.management.jmxremote.port=9999 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false
其中:
hostname 是你要查看的遠程服務器的真實IP
port 是遠程服務上 tomcat 要開啟的 jmx 端口,這個端口只要選擇服務器上沒有被占用的端口即可。
一般上述內容加入: 進入Tomcat/bin目錄,修改catalina.sh,找到如下內容 “#—–Execute The Requested Command”
2) 重啟 tomcat
3) 使用 ps -ef|grep tomcat 查下 tomcat 進程,看下現在其啟動參數中 jvm 參數里是否有 這個 jmx 參數
上述圖中可以看出 jvm 參數中成功加入 jmx 參數。
2、通過 jconsole
圖中的 1 處填寫 你要遠程的 tomcat 所在 IP 以及 開放的 jmx 端口;
MBean 頁 中記錄了所有 可以監控 tomcat 的監控項。
可以看到 堆內存 使用情況,其它 Tab 亦然。
其實:圖中所有 Tab (除了 Mbean) 的內容都是從 Mbean 中獲取的。
3、通過 jvisualvm 工具監控
三、集成監控軟件
1、集成 prometheus
1) 在虛擬機上安裝 prometheus 軟件
可以查看該篇博客:https://www.cnblogs.com/fatyao/p/11007357.html
2、集成 zabbix