热线程 API编辑

热线程 API 获取 Logstash 的当前热线程。热线程是指 CPU 使用率高且执行时间比正常时间长的 Java 线程。

curl -XGET 'localhost:9600/_node/hot_threads?pretty'

输出是一个 JSON 文档,其中包含 Logstash 的顶级热线程的细分。

示例响应

{
  "hot_threads" : {
    "time" : "2017-06-06T18:25:28-07:00",
    "busiest_threads" : 3,
    "threads" : [ {
      "name" : "Ruby-0-Thread-7",
      "percent_of_cpu_time" : 0.0,
      "state" : "timed_waiting",
      "path" : "/path/to/logstash-8.14.2/vendor/bundle/jruby/1.9/gems/puma-2.16.0-java/lib/puma/thread_pool.rb:187",
      "traces" : [ "java.lang.Object.wait(Native Method)", "org.jruby.RubyThread.sleep(RubyThread.java:1002)", "org.jruby.RubyKernel.sleep(RubyKernel.java:803)" ]
    }, {
      "name" : "[test2]>worker3",
      "percent_of_cpu_time" : 0.85,
      "state" : "waiting",
      "traces" : [ "sun.misc.Unsafe.park(Native Method)", "java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)", "java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:836)" ]
    }, {
      "name" : "[test2]>worker2",
      "percent_of_cpu_time" : 0.85,
      "state" : "runnable",
      "traces" : [ "org.jruby.RubyClass.allocate(RubyClass.java:225)", "org.jruby.RubyClass.newInstance(RubyClass.java:856)", "org.jruby.RubyClass$INVOKER$i$newInstance.call(RubyClass$INVOKER$i$newInstance.gen)" ]
    } ]
  }
}

允许的参数为

线程

要返回的热线程数量。默认值为 10。

堆栈跟踪大小

为每个线程报告的堆栈跟踪深度。默认值为 50。

人类

如果为真,则返回纯文本而不是 JSON 格式。默认值为 false。

忽略空闲线程

如果为真,则不返回空闲线程。默认值为 true。

有关可应用于所有 Logstash 监控 API 的选项列表,请参阅 常见选项

您可以使用 ?human 参数以人类可读的格式返回文档。

curl -XGET 'localhost:9600/_node/hot_threads?human=true'

人类可读响应的示例

 ::: {}
 Hot threads at 2017-06-06T18:31:17-07:00, busiestThreads=3:
 ================================================================================
 0.0 % of cpu usage, state: timed_waiting, thread name: 'Ruby-0-Thread-7'
 /path/to/logstash-8.14.2/vendor/bundle/jruby/1.9/gems/puma-2.16.0-java/lib/puma/thread_pool.rb:187
	 java.lang.Object.wait(Native Method)
	 org.jruby.RubyThread.sleep(RubyThread.java:1002)
	 org.jruby.RubyKernel.sleep(RubyKernel.java:803)
 --------------------------------------------------------------------------------
 0.0 % of cpu usage, state: waiting, thread name: 'defaultEventExecutorGroup-5-4'
	 sun.misc.Unsafe.park(Native Method)
	 java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
	 java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
 --------------------------------------------------------------------------------
 0.05 % of cpu usage, state: timed_waiting, thread name: '[test]-pipeline-manager'
	 java.lang.Object.wait(Native Method)
	 java.lang.Thread.join(Thread.java:1253)
	 org.jruby.internal.runtime.NativeThread.join(NativeThread.java:75)