Switch-vov commented on a change in pull request #52:
URL:
https://github.com/apache/skywalking-data-collect-protocol/pull/52#discussion_r663003621
##########
File path: language-agent/JVMMetric.proto
##########
@@ -84,9 +85,25 @@ enum GCPhrase {
OLD = 1;
}
+// see:
https://docs.oracle.com/javase/8/docs/api/java/lang/management/ThreadMXBean.html
message Thread {
- int64 liveCount = 1;
- int64 daemonCount = 2;
- int64 peakCount = 3;
+ int64 liveCount = 1;
+ int64 daemonCount = 2;
+ int64 peakCount = 3;
+ int64 deadlockedCount = 4;
+ int64 monitorDeadlockedCount = 5;
Review comment:
[ThreadExports.java](https://github.com/prometheus/client_java/blob/master/simpleclient_hotspot/src/main/java/io/prometheus/client/hotspot/ThreadExports.java)
use it.
```java
void addThreadMetrics(List<MetricFamilySamples> sampleFamilies) {
// etc...
sampleFamilies.add(
new GaugeMetricFamily(
"jvm_threads_deadlocked",
"Cycles of JVM-threads that are in deadlock waiting to acquire
object monitors or ownable synchronizers",
nullSafeArrayLength(threadBean.findDeadlockedThreads())));
sampleFamilies.add(
new GaugeMetricFamily(
"jvm_threads_deadlocked_monitor",
"Cycles of JVM-threads that are in deadlock waiting to acquire
object monitors",
nullSafeArrayLength(threadBean.findMonitorDeadlockedThreads())));
// etc...
}
public List<MetricFamilySamples> collect() {
List<MetricFamilySamples> mfs = new ArrayList<MetricFamilySamples>();
addThreadMetrics(mfs);
return mfs;
}
```
## Benchmark
```java
package io.prometheus.client.hotspot;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.profile.GCProfiler;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import java.util.concurrent.TimeUnit;
public class ThreadExportsBenchmark {
@Benchmark
@Fork(value = 1, warmups = 1)
@OutputTimeUnit(TimeUnit.SECONDS)
@BenchmarkMode(Mode.Throughput)
public void getThreadMetrics() {
new ThreadExports().collect();
}
public static void main(String[] args) throws Exception {
Options opt = new
OptionsBuilder().include(ThreadExportsBenchmark.class.getSimpleName())
.build();
new Runner(opt).run();
}
/**
* # JMH version: 1.21
* # VM version: JDK 1.8.0_231, Java HotSpot(TM) 64-Bit Server VM,
25.231-b11
* # VM invoker:
/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/bin/java
* # VM options: -javaagent:/Users/switch/Library/Application
Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/211.7442.40/IntelliJ
IDEA.app/Contents/lib/idea_rt.jar=50050:/Users/switch/Library/Application
Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/211.7442.40/IntelliJ
IDEA.app/Contents/bin -Dfile.encoding=UTF-8
* # Warmup: 5 iterations, 10 s each
* # Measurement: 5 iterations, 10 s each
* # Timeout: 10 min per iteration
* # Threads: 1 thread, will synchronize iterations
* # Benchmark mode: Throughput, ops/time
*
* Benchmark Mode Cnt Score
Error Units
* ThreadExportsBenchmark.getThreadMetrics thrpt 5 14423.128 ±
2422.329 ops/s
*/
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]