summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Pursehouse <dpursehouse@digital.ai>2020-05-20 23:59:17 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2020-05-20 23:59:17 +0000
commit7d5e24c3d81d897ad178571972eac190a2a3afd4 (patch)
tree87b281ee58559184144729abc88ca97f0c0db960
parent78ab47965cc33c193fb23a310762f15cc79884b5 (diff)
parent74fbf8d1e37a98e09443b6204bf9689de30113ec (diff)
Merge "Add metric monitoring Java deadlocks" into stable-2.16
-rw-r--r--Documentation/metrics.txt2
-rw-r--r--java/com/google/gerrit/metrics/proc/ProcMetricModule.java31
2 files changed, 33 insertions, 0 deletions
diff --git a/Documentation/metrics.txt b/Documentation/metrics.txt
index f729f549da..cb3eb2179d 100644
--- a/Documentation/metrics.txt
+++ b/Documentation/metrics.txt
@@ -50,6 +50,8 @@ objects needing finalization.
* `proc/jvm/thread/num_daemon_live`: Current live daemon threads count.
* `proc/jvm/thread/num_peak_live`: Peak live thread count since the Java virtual machine started or peak was reset.
* `proc/jvm/thread/num_total_started`: Total number of threads created and also started since the Java virtual machine started.
+* `proc/jvm/thread/num_deadlocked_threads`: Number of threads that are deadlocked waiting for object monitors or ownable synchronizers.
+ If deadlocks waiting for ownable synchronizers can be monitored depends on the capabilities of the used JVM.
=== Caches
diff --git a/java/com/google/gerrit/metrics/proc/ProcMetricModule.java b/java/com/google/gerrit/metrics/proc/ProcMetricModule.java
index be70b8c4e8..2395e3d622 100644
--- a/java/com/google/gerrit/metrics/proc/ProcMetricModule.java
+++ b/java/com/google/gerrit/metrics/proc/ProcMetricModule.java
@@ -235,5 +235,36 @@ public class ProcMetricModule extends MetricModule {
.setGauge()
.setUnit("threads"),
thread::getTotalStartedThreadCount);
+ if (thread.isSynchronizerUsageSupported()) {
+ metrics.newCallbackMetric(
+ "proc/jvm/thread/num_deadlocked_threads",
+ Integer.class,
+ new Description(
+ "number of threads that are deadlocked waiting for object monitors or ownable synchronizers")
+ .setGauge()
+ .setUnit("threads"),
+ () -> {
+ long[] deadlocked = thread.findDeadlockedThreads();
+ if (deadlocked == null) {
+ return 0;
+ }
+ return deadlocked.length;
+ });
+ } else {
+ metrics.newCallbackMetric(
+ "proc/jvm/thread/num_deadlocked_threads",
+ Integer.class,
+ new Description(
+ "number of threads that are deadlocked waiting to acquire object monitors")
+ .setGauge()
+ .setUnit("threads"),
+ () -> {
+ long[] deadlocked = thread.findMonitorDeadlockedThreads();
+ if (deadlocked == null) {
+ return 0;
+ }
+ return deadlocked.length;
+ });
+ }
}
}