Merge changes I12d74ea2,Iae424c75,I1a47821b into stable-2.16 * changes: Proc metrics: add average system load for the last minute Proc metrics: add available number of cores Add more metrics about Java threads
diff --git a/Documentation/metrics.txt b/Documentation/metrics.txt index e6654c3..f729f54 100644 --- a/Documentation/metrics.txt +++ b/Documentation/metrics.txt
@@ -33,7 +33,9 @@ * `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. @@ -45,6 +47,9 @@ * `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 5af2672..be70b8c 100644 --- a/java/com/google/gerrit/metrics/proc/ProcMetricModule.java +++ b/java/com/google/gerrit/metrics/proc/ProcMetricModule.java
@@ -29,6 +29,7 @@ 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; @@ -38,6 +39,7 @@ buildLabel(metrics); procUptime(metrics); procCpuUsage(metrics); + procCpuLoad(metrics); procJvmGc(metrics); procJvmMemory(metrics); procJvmThread(metrics); @@ -90,6 +92,23 @@ 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) { @@ -195,5 +214,26 @@ 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); } }