Skywalking-04:扩展Metric监控信息 (2)

org.apache.skywalking.oap.server.analyzer.provider.jvm.JVMSourceDispatcher 是一个 Source 分发类,将从 agent 接收到的 JVM 相关 Metrics 拆分成对应的 Source 。例如: ServiceInstanceJVMMemory 、 ServiceInstanceJVMThread 。
修改方法org.apache.skywalking.oap.server.analyzer.provider.jvm.JVMSourceDispatcher#sendToThreadMetricProcess 为如下代码:

private void sendToThreadMetricProcess(String service, String serviceId, String serviceInstance, String serviceInstanceId, long timeBucket, Thread thread) { ServiceInstanceJVMThread serviceInstanceJVMThread = new ServiceInstanceJVMThread(); serviceInstanceJVMThread.setId(serviceInstanceId); serviceInstanceJVMThread.setName(serviceInstance); serviceInstanceJVMThread.setServiceId(serviceId); serviceInstanceJVMThread.setServiceName(service); serviceInstanceJVMThread.setLiveCount(thread.getLiveCount()); serviceInstanceJVMThread.setDaemonCount(thread.getDaemonCount()); serviceInstanceJVMThread.setPeakCount(thread.getPeakCount()); serviceInstanceJVMThread.setTimeBucket(timeBucket); serviceInstanceJVMThread.setDeadlocked(thread.getDeadlocked()); serviceInstanceJVMThread.setMonitorDeadlocked(thread.getMonitorDeadlocked()); serviceInstanceJVMThread.setNewThreadCount(thread.getNewThreadCount()); serviceInstanceJVMThread.setRunnableThreadCount(thread.getRunnableThreadCount()); serviceInstanceJVMThread.setBlockedThreadCount(thread.getBlockedThreadCount()); serviceInstanceJVMThread.setWaitThreadCount(thread.getWaitThreadCount()); serviceInstanceJVMThread.setTimeWaitThreadCount(thread.getTimeWaitThreadCount()); serviceInstanceJVMThread.setTerminatedThreadCount(thread.getTerminatedThreadCount()); sourceReceiver.receive(serviceInstanceJVMThread); } 在 java-agent.oal 增加相关指标

在oap-server/server-bootstrap/src/main/resources/oal/java-agent.oal 添加如下语句

// 参考oal语法 instance_jvm_thread_deadlocked = from(ServiceInstanceJVMThread.deadlocked).longAvg(); instance_jvm_thread_monitor_deadlocked = from(ServiceInstanceJVMThread.monitorDeadlocked).longAvg(); instance_jvm_thread_new_thread_count = from(ServiceInstanceJVMThread.newThreadCount).longAvg(); instance_jvm_thread_runnable_thread_count = from(ServiceInstanceJVMThread.runnableThreadCount).longAvg(); instance_jvm_thread_blocked_thread_count = from(ServiceInstanceJVMThread.blockedThreadCount).longAvg(); instance_jvm_thread_wait_thread_count = from(ServiceInstanceJVMThread.waitThreadCount).longAvg(); instance_jvm_thread_time_wait_thread_count = from(ServiceInstanceJVMThread.timeWaitThreadCount).longAvg(); instance_jvm_thread_terminated_thread_count = from(ServiceInstanceJVMThread.terminatedThreadCount).longAvg(); 修改 apm.yml

在 oap-server/server-bootstrap/src/main/resources/ui-initialized-templates/apm.yml 文件的 APM 面板下的 Instance 项增加如下配置

{ "width": 3, "title": "JVM Thread Count (Java Service)", "height": "250", "entityType": "ServiceInstance", "independentSelector": false, "metricType": "REGULAR_VALUE", "queryMetricType": "readMetricsValues", "chartType": "ChartLine", "metricName": "instance_jvm_thread_live_count, instance_jvm_thread_daemon_count, instance_jvm_thread_peak_count,instance_jvm_thread_deadlocked,instance_jvm_thread_monitor_deadlocked" }, { "width": 3, "title": "JVM Thread State Count (Java Service)", "height": "250", "entityType": "ServiceInstance", "independentSelector": false, "metricType": "REGULAR_VALUE", "metricName": "instance_jvm_thread_new_thread_count,instance_jvm_thread_runnable_thread_count,instance_jvm_thread_blocked_thread_count,instance_jvm_thread_wait_thread_count,instance_jvm_thread_time_wait_thread_count,instance_jvm_thread_terminated_thread_count", "queryMetricType": "readMetricsValues", "chartType": "ChartBar" }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zwzdsg.html