diff --git a/Documentation/dev-contributing.txt b/Documentation/dev-contributing.txt index 6671cf0ed0..cdc7d357a3 100644 --- a/Documentation/dev-contributing.txt +++ b/Documentation/dev-contributing.txt @@ -171,7 +171,7 @@ To format Java source code, Gerrit uses the link:https://github.com/google/google-java-format[`google-java-format`] tool (version 1.7), and to format Bazel BUILD, WORKSPACE and .bzl files the link:https://github.com/bazelbuild/buildtools/tree/master/buildifier[`buildifier`] -tool (version 1.0.0). Unused dependencies are found and removed using the +tool (version 2.0.0). Unused dependencies are found and removed using the link:https://github.com/bazelbuild/buildtools/tree/master/unused_deps[`unused_deps`] build tool, a sibling of `buildifier`. diff --git a/Documentation/metrics.txt b/Documentation/metrics.txt index b6ae25fe0f..cee5012ec9 100644 --- a/Documentation/metrics.txt +++ b/Documentation/metrics.txt @@ -35,7 +35,9 @@ split up by update type (create+replace, autoclose, normal) * `proc/birth_timestamp`: Time at which the Gerrit process started. * `proc/uptime`: Uptime of the Gerrit process. +* `proc/cpu/num_cores`: Number of processors available to the Java virtual machine. * `proc/cpu/usage`: CPU time used by the Gerrit process. +* `proc/cpu/system_load`: System load average for the last minute. * `proc/num_open_fds`: Number of open file descriptors. * `proc/jvm/memory/heap_committed`: Amount of memory guaranteed for user objects. * `proc/jvm/memory/heap_used`: Amount of memory holding user objects. @@ -47,6 +49,9 @@ objects needing finalization. * `proc/jvm/gc/count`: Number of GCs. * `proc/jvm/gc/time`: Approximate accumulated GC elapsed time. * `proc/jvm/thread/num_live`: Current live thread count. +* `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. === Caches diff --git a/java/com/google/gerrit/metrics/proc/ProcMetricModule.java b/java/com/google/gerrit/metrics/proc/ProcMetricModule.java index 939560fc8c..3d1cd1f103 100644 --- a/java/com/google/gerrit/metrics/proc/ProcMetricModule.java +++ b/java/com/google/gerrit/metrics/proc/ProcMetricModule.java @@ -27,6 +27,7 @@ import java.lang.management.GarbageCollectorMXBean; import java.lang.management.ManagementFactory; import java.lang.management.MemoryMXBean; import java.lang.management.MemoryUsage; +import java.lang.management.OperatingSystemMXBean; import java.lang.management.ThreadMXBean; import java.util.concurrent.TimeUnit; @@ -36,6 +37,7 @@ public class ProcMetricModule extends MetricModule { buildLabel(metrics); procUptime(metrics); procCpuUsage(metrics); + procCpuLoad(metrics); procJvmGc(metrics); procJvmMemory(metrics); procJvmThread(metrics); @@ -83,6 +85,23 @@ public class ProcMetricModule extends MetricModule { new Description("Number of open file descriptors").setGauge().setUnit("fds"), provider::getOpenFileDescriptorCount); } + metrics.newCallbackMetric( + "proc/cpu/num_cores", + Integer.class, + new Description("Number of processors available to the Java virtual machine").setGauge(), + Runtime.getRuntime()::availableProcessors); + } + + private void procCpuLoad(MetricMaker metrics) { + OperatingSystemMXBean provider = + ManagementFactory.getPlatformMXBean(OperatingSystemMXBean.class); + if (provider.getSystemLoadAverage() != -1) { + metrics.newCallbackMetric( + "proc/cpu/system_load", + Double.class, + new Description("System load average for the last minute").setGauge(), + provider::getSystemLoadAverage); + } } private void procJvmMemory(MetricMaker metrics) { @@ -188,5 +207,26 @@ public class ProcMetricModule extends MetricModule { Integer.class, new Description("Current live thread count").setGauge().setUnit("threads"), thread::getThreadCount); + metrics.newCallbackMetric( + "proc/jvm/thread/num_daemon_live", + Integer.class, + new Description("Current live daemon threads count").setGauge().setUnit("threads"), + thread::getDaemonThreadCount); + metrics.newCallbackMetric( + "proc/jvm/thread/num_peak_live", + Integer.class, + new Description( + "Peak live thread count since the Java virtual machine started or peak was reset") + .setGauge() + .setUnit("threads"), + thread::getPeakThreadCount); + metrics.newCallbackMetric( + "proc/jvm/thread/num_total_started", + Long.class, + new Description( + "Total number of threads created and also started since the Java virtual machine started") + .setGauge() + .setUnit("threads"), + thread::getTotalStartedThreadCount); } }