获取非 Spring Java 应用的详细 Metrics 数据
Posted
技术标签:
【中文标题】获取非 Spring Java 应用的详细 Metrics 数据【英文标题】:Fetch detailed Metrics data of non-Spring Java application 【发布时间】:2020-07-19 12:53:58 【问题描述】:我正在使用 JMX 服务器,来获取我在 Karaf 容器中运行的应用程序的指标数据。
使用的 JMX 导出服务器:https://github.com/prometheus/jmx_exporter
我尝试了示例 Spring 应用程序,使用 Micrometer 依赖项,Metric 日志非常详细,包含有关请求数量等数据的数据。
但是,我的目标应用程序不是基于 Spring。 [它在 Talend 上运行]
我收到的日志中没有显示有关应用程序收到的 REST 请求数量的任何数据。
我应该做些什么额外/替代方法来获取更多详细信息,例如请求数等?
为我的应用程序收到的指标日志:
# HELP jmx_config_reload_success_total Number of times configuration have successfully been reloaded.
# TYPE jmx_config_reload_success_total counter
jmx_config_reload_success_total 0.0
# HELP jmx_config_reload_failure_total Number of times configuration have failed to be reloaded.
# TYPE jmx_config_reload_failure_total counter
jmx_config_reload_failure_total 0.0
# HELP jmx_exporter_build_info A metric with a constant '1' value labeled with the version of the JMX exporter.
# TYPE jmx_exporter_build_info gauge
jmx_exporter_build_infoversion="0.12.1-SNAPSHOT",name="jmx_prometheus_httpserver", 1.0
# HELP org_ops4j_pax_web_service_jetty_internal_jettyserverwrapper_stopTimeout The stop timeout in milliseconds (org.ops4j.pax.web.service.jetty.internal<type=jettyserverwrapper, id=0><>stopTimeout)
# TYPE org_ops4j_pax_web_service_jetty_internal_jettyserverwrapper_stopTimeout untyped
org_ops4j_pax_web_service_jetty_internal_jettyserverwrapper_stopTimeoutid="0", 30000.0
# HELP org_apache_karaf_instance_Instances_SSH_Port This type describes Karaf instance (org.apache.karaf<type=instance, name=trun, Name=trun><Instances>SSH Port)
# TYPE org_apache_karaf_instance_Instances_SSH_Port untyped
org_apache_karaf_instance_Instances_SSH_Portname="trun",Name="trun", 8101.0
# HELP jmx4perl_Config_Debug Attribute exposed for management (jmx4perl<type=Config><>Debug)
# TYPE jmx4perl_Config_Debug untyped
jmx4perl_Config_Debug 0.0
# HELP org_eclipse_jetty_server_session_hashsessionidmanager_stopTimeout The stop timeout in milliseconds (org.eclipse.jetty.server.session<type=hashsessionidmanager, id=0><>stopTimeout)
# TYPE org_eclipse_jetty_server_session_hashsessionidmanager_stopTimeout untyped
org_eclipse_jetty_server_session_hashsessionidmanager_stopTimeoutid="0", 30000.0
# HELP org_eclipse_jetty_server_SSL_HTTP_1_1_4ef474b6_outputAggregationSize The maximum size in bytes for HTTP output to be aggregated (org.eclipse.jetty.server<context=SSL|HTTP/1.1@4ef474b6, type=httpconfiguration, id=0><>outputAggregationSize)
# TYPE org_eclipse_jetty_server_SSL_HTTP_1_1_4ef474b6_outputAggregationSize untyped
org_eclipse_jetty_server_SSL_HTTP_1_1_4ef474b6_outputAggregationSizetype="httpconfiguration",id="0", 8192.0
# HELP java_lang_Threading_ThreadContentionMonitoringSupported ThreadContentionMonitoringSupported (java.lang<type=Threading><>ThreadContentionMonitoringSupported)
# TYPE java_lang_Threading_ThreadContentionMonitoringSupported untyped
java_lang_Threading_ThreadContentionMonitoringSupported 1.0
# HELP org_eclipse_jetty_server_HTTP_1_1_15470990_outputAggregationSize The maximum size in bytes for HTTP output to be aggregated (org.eclipse.jetty.server<context=HTTP/1.1@15470990, type=httpconfiguration, id=0><>outputAggregationSize)
# TYPE org_eclipse_jetty_server_HTTP_1_1_15470990_outputAggregationSize untyped
org_eclipse_jetty_server_HTTP_1_1_15470990_outputAggregationSizetype="httpconfiguration",id="0", 8192.0
# HELP java_lang_Runtime_StartTime StartTime (java.lang<type=Runtime><>StartTime)
# TYPE java_lang_Runtime_StartTime untyped
java_lang_Runtime_StartTime 1.586172506622E12
# HELP org_eclipse_jetty_server_HTTP_1_1_137f82d0_acceptQueueSize Accept Queue size (org.eclipse.jetty.server<context=HTTP/1.1@137f82d0, type=serverconnector, id=0><>acceptQueueSize)
# TYPE org_eclipse_jetty_server_HTTP_1_1_137f82d0_acceptQueueSize untyped
org_eclipse_jetty_server_HTTP_1_1_137f82d0_acceptQueueSizetype="serverconnector",id="0", 0.0
# HELP org_eclipse_jetty_io_HTTP_1_1_15470990_stopTimeout The stop timeout in milliseconds (org.eclipse.jetty.io<context=HTTP/1.1@15470990, type=managedselector, id=0><>stopTimeout)
# TYPE org_eclipse_jetty_io_HTTP_1_1_15470990_stopTimeout untyped
org_eclipse_jetty_io_HTTP_1_1_15470990_stopTimeouttype="managedselector",id="0", 30000.0
org_eclipse_jetty_io_HTTP_1_1_15470990_stopTimeouttype="managedselector",id="1", 30000.0
org_eclipse_jetty_io_HTTP_1_1_15470990_stopTimeouttype="managedselector",id="3", 30000.0
org_eclipse_jetty_io_HTTP_1_1_15470990_stopTimeouttype="managedselector",id="2", 30000.0
# HELP java_lang_MemoryPool_UsageThreshold UsageThreshold (java.lang<type=MemoryPool, name=Code Cache><>UsageThreshold)
# TYPE java_lang_MemoryPool_UsageThreshold untyped
java_lang_MemoryPool_UsageThresholdname="Code Cache", 0.0
java_lang_MemoryPool_UsageThresholdname="PS Old Gen", 0.0
java_lang_MemoryPool_UsageThresholdname="Compressed Class Space", 0.0
java_lang_MemoryPool_UsageThresholdname="Metaspace", 0.0
# HELP java_lang_Threading_PeakThreadCount PeakThreadCount (java.lang<type=Threading><>PeakThreadCount)
# TYPE java_lang_Threading_PeakThreadCount untyped
java_lang_Threading_PeakThreadCount 109.0
# HELP org_eclipse_jetty_server_HTTP_1_1_15470990_sendServerVersion Whether to send the Server header in responses (org.eclipse.jetty.server<context=HTTP/1.1@15470990, type=httpconfiguration, id=0><>sendServerVersion)
# TYPE org_eclipse_jetty_server_HTTP_1_1_15470990_sendServerVersion untyped
org_eclipse_jetty_server_HTTP_1_1_15470990_sendServerVersiontype="httpconfiguration",id="0", 1.0
# HELP java_lang_ClassLoading_TotalLoadedClassCount TotalLoadedClassCount (java.lang<type=ClassLoading><>TotalLoadedClassCount)
# TYPE java_lang_ClassLoading_TotalLoadedClassCount untyped
java_lang_ClassLoading_TotalLoadedClassCount 14393.0
# HELP org_eclipse_jetty_server_SSL_HTTP_1_1_4ef474b6_blockingTimeout Total timeout in ms for blocking I/O operations. (org.eclipse.jetty.server<context=SSL|HTTP/1.1@4ef474b6, type=httpconfiguration, id=0><>blockingTimeout)
# TYPE org_eclipse_jetty_server_SSL_HTTP_1_1_4ef474b6_blockingTimeout untyped
org_eclipse_jetty_server_SSL_HTTP_1_1_4ef474b6_blockingTimeouttype="httpconfiguration",id="0", -1.0
# HELP org_eclipse_jetty_server_HTTP_1_1_15470990_blockingTimeout Total timeout in ms for blocking I/O operations. (org.eclipse.jetty.server<context=HTTP/1.1@15470990, type=httpconfiguration, id=0><>blockingTimeout)
# TYPE org_eclipse_jetty_server_HTTP_1_1_15470990_blockingTimeout untyped
org_eclipse_jetty_server_HTTP_1_1_15470990_blockingTimeouttype="httpconfiguration",id="0", -1.0
# HELP org_apache_karaf_instance_Instances_Pid This type describes Karaf instance (org.apache.karaf<type=instance, name=trun, Name=trun><Instances>Pid)
# TYPE org_apache_karaf_instance_Instances_Pid untyped
org_apache_karaf_instance_Instances_Pidname="trun",Name="trun", 2600.0
# HELP org_eclipse_jetty_server_HTTP_1_1_137f82d0_acceptorPriorityDelta The priority delta to apply to acceptor threads (org.eclipse.jetty.server<context=HTTP/1.1@137f82d0, type=serverconnector, id=0><>acceptorPriorityDelta)
# TYPE org_eclipse_jetty_server_HTTP_1_1_137f82d0_acceptorPriorityDelta untyped
org_eclipse_jetty_server_HTTP_1_1_137f82d0_acceptorPriorityDeltatype="serverconnector",id="0", -2.0
# HELP org_ops4j_pax_web_service_jetty_internal_jettyserverwrapper_dumpBeforeStop dump state to stderr before stop (org.ops4j.pax.web.service.jetty.internal<type=jettyserverwrapper, id=0><>dumpBeforeStop)
# TYPE org_ops4j_pax_web_service_jetty_internal_jettyserverwrapper_dumpBeforeStop untyped
org_ops4j_pax_web_service_jetty_internal_jettyserverwrapper_dumpBeforeStopid="0", 0.0
# HELP org_eclipse_jetty_server_HTTP_1_1_15470990_requestHeaderSize The maximum allowed size in bytes for a HTTP request header (org.eclipse.jetty.server<context=HTTP/1.1@15470990, type=httpconfiguration, id=0><>requestHeaderSize)
# TYPE org_eclipse_jetty_server_HTTP_1_1_15470990_requestHeaderSize untyped
org_eclipse_jetty_server_HTTP_1_1_15470990_requestHeaderSizetype="httpconfiguration",id="0", 8192.0
# HELP org_apache_cxf_Shared_WorkQueueMaxSize The WorkQueueMaxSize (org.apache.cxf<bus.id=Shared, type=WorkQueues, name=default, instance.id=131247914><>WorkQueueMaxSize)
# TYPE org_apache_cxf_Shared_WorkQueueMaxSize untyped
org_apache_cxf_Shared_WorkQueueMaxSizetype="WorkQueues",name="default",instance_id="131247914", 50.0
# HELP java_lang_MemoryPool_PeakUsage_committed java.lang.management.MemoryUsage (java.lang<type=MemoryPool, name=Code Cache><PeakUsage>committed)
# TYPE java_lang_MemoryPool_PeakUsage_committed untyped
java_lang_MemoryPool_PeakUsage_committedname="Code Cache", 2.3003136E7
java_lang_MemoryPool_PeakUsage_committedname="PS Old Gen", 2.7000832E8
java_lang_MemoryPool_PeakUsage_committedname="Compressed Class Space", 1.245184E7
java_lang_MemoryPool_PeakUsage_committedname="Metaspace", 8.7031808E7
java_lang_MemoryPool_PeakUsage_committedname="PS Eden Space", 2.92028416E8
java_lang_MemoryPool_PeakUsage_committedname="PS Survivor Space", 2.3068672E7
# HELP org_eclipse_jetty_server_HTTP_1_1_15470990_acceptors number of acceptor threads (org.eclipse.jetty.server<context=HTTP/1.1@15470990, type=serverconnector, id=0><>acceptors)
# TYPE org_eclipse_jetty_server_HTTP_1_1_15470990_acceptors untyped
org_eclipse_jetty_server_HTTP_1_1_15470990_acceptorstype="serverconnector",id="0", 1.0
# HELP org_eclipse_jetty_server_HTTP_1_1_137f82d0_delayDispatchUntilContent Whether to delay the application dispatch until content is available (org.eclipse.jetty.server<context=HTTP/1.1@137f82d0, type=httpconfiguration, id=0><>delayDispatchUntilContent)
# TYPE org_eclipse_jetty_server_HTTP_1_1_137f82d0_delayDispatchUntilContent untyped
org_eclipse_jetty_server_HTTP_1_1_137f82d0_delayDispatchUntilContenttype="httpconfiguration",id="0", 1.0
# HELP org_apache_aries_blueprint_blueprintState_LastEvents_Replay Blueprint event (org.apache.aries.blueprint<service=blueprintState, version=1.0, BundleId=192><LastEvents>Replay)
# TYPE org_apache_aries_blueprint_blueprintState_LastEvents_Replay untyped
org_apache_aries_blueprint_blueprintState_LastEvents_Replayversion="1.0",BundleId="192", 0.0
org_apache_aries_blueprint_blueprintState_LastEvents_Replayversion="1.0",BundleId="98", 1.0
org_apache_aries_blueprint_blueprintState_LastEvents_Replayversion="1.0",BundleId="194", 0.0
org_apache_aries_blueprint_blueprintState_LastEvents_Replayversion="1.0",BundleId="198", 0.0
org_apache_aries_blueprint_blueprintState_LastEvents_Replayversion="1.0",BundleId="199", 0.0
org_apache_aries_blueprint_blueprintState_LastEvents_Replayversion="1.0",BundleId="201", 0.0
org_apache_aries_blueprint_blueprintState_LastEvents_Replayversion="1.0",BundleId="204", 0.0
org_apache_aries_blueprint_blueprintState_LastEvents_Replayversion="1.0",BundleId="12", 0.0
org_apache_aries_blueprint_blueprintState_LastEvents_Replayversion="1.0",BundleId="205", 0.0
org_apache_aries_blueprint_blueprintState_LastEvents_Replayversion="1.0",BundleId="46", 0.0
org_apache_aries_blueprint_blueprintState_LastEvents_Replayversion="1.0",BundleId="112", 1.0
org_apache_aries_blueprint_blueprintState_LastEvents_Replayversion="1.0",BundleId="241", 0.0
org_apache_aries_blueprint_blueprintState_LastEvents_Replayversion="1.0",BundleId="246", 0.0
org_apache_aries_blueprint_blueprintState_LastEvents_Replayversion="1.0",BundleId="248", 0.0
org_apache_aries_blueprint_blueprintState_LastEvents_Replayversion="1.0",BundleId="25", 1.0
org_apache_aries_blueprint_blueprintState_LastEvents_Replayversion="1.0",BundleId="26", 1.0
org_apache_aries_blueprint_blueprintState_LastEvents_Replayversion="1.0",BundleId="221", 1.0
# HELP java_nio_BufferPool_Count Count (java.nio<type=BufferPool, name=direct><>Count)
# TYPE java_nio_BufferPool_Count untyped
java_nio_BufferPool_Countname="direct", 5.0
java_nio_BufferPool_Countname="mapped", 0.0
# HELP java_lang_Threading_ThreadAllocatedMemoryEnabled ThreadAllocatedMemoryEnabled (java.lang<type=Threading><>ThreadAllocatedMemoryEnabled)
# TYPE java_lang_Threading_ThreadAllocatedMemoryEnabled untyped
java_lang_Threading_ThreadAllocatedMemoryEnabled 1.0
# HELP jolokia_Config_HistoryMaxEntries Attribute exposed for management (jolokia<type=Config><>HistoryMaxEntries)
# TYPE jolokia_Config_HistoryMaxEntries untyped
jolokia_Config_HistoryMaxEntries 10.0
# HELP java_lang_OperatingSystem_ProcessCpuLoad ProcessCpuLoad (java.lang<type=OperatingSystem><>ProcessCpuLoad)
# TYPE java_lang_OperatingSystem_ProcessCpuLoad untyped
java_lang_OperatingSystem_ProcessCpuLoad 0.12238162074777716
# HELP org_eclipse_jetty_server_HTTP_1_1_137f82d0_localPort local port (org.eclipse.jetty.server<context=HTTP/1.1@137f82d0, type=serverconnector, id=0><>localPort)
# TYPE org_eclipse_jetty_server_HTTP_1_1_137f82d0_localPort untyped
org_eclipse_jetty_server_HTTP_1_1_137f82d0_localPorttype="serverconnector",id="0", 8040.0
org_apache_cxf_Shared_LowWaterMarktype="WorkQueues",name="default",instance_id="131247914", 5.0
# HELP jmx_scrape_duration_seconds Time this JMX scrape took, in seconds.
# TYPE jmx_scrape_duration_seconds gauge
jmx_scrape_duration_seconds 7.527235
# HELP jmx_scrape_error Non-zero if this scrape failed.
# TYPE jmx_scrape_error gauge
jmx_scrape_error 0.0
【问题讨论】:
【参考方案1】:Apache CXF 库为我提供了这些数据。
附上jconsole
的屏幕截图,我正在计算 REST 命中数。
在 5 个 HTTP POST 请求后收集的数据。
【讨论】:
以上是关于获取非 Spring Java 应用的详细 Metrics 数据的主要内容,如果未能解决你的问题,请参考以下文章
资源服务器获取用户信息,java - Spring Security OAuth2资源服务器无法获取包含详细信息的主体 - 堆栈内存溢出...
资源服务器获取用户信息,java - Spring Security OAuth2资源服务器无法获取包含详细信息的主体 - 堆栈内存溢出...