Github user zentol commented on a diff in the pull request:

    https://github.com/apache/flink/pull/2146#discussion_r68071928
  
    --- Diff: 
flink-runtime/src/main/scala/org/apache/flink/runtime/jobmanager/JobManager.scala
 ---
    @@ -1737,6 +1766,149 @@ class JobManager(
         // Shutdown and discard all queued messages
         context.system.shutdown()
       }
    +
    +  private def instantiateMetrics(jobManagerMetricGroup: MetricGroup) : 
Unit = {
    +    jobManagerMetricGroup.gauge("taskSlotsAvailable", new Gauge[Long] {
    +      override def getValue: Long = 
JobManager.this.instanceManager.getNumberOfAvailableSlots
    +    })
    +    jobManagerMetricGroup.gauge("taskSlotsTotal", new Gauge[Long] {
    +      override def getValue: Long = 
JobManager.this.instanceManager.getTotalNumberOfSlots
    +    })
    +    jobManagerMetricGroup.gauge("numRegisteredTaskManagers", new 
Gauge[Long] {
    +      override def getValue: Long
    +      = JobManager.this.instanceManager.getNumberOfRegisteredTaskManagers
    +    })
    +    jobManagerMetricGroup.gauge("numRunningJobs", new Gauge[Long] {
    +      override def getValue: Long = JobManager.this.currentJobs.size
    +    })
    +    instantiateStatusMetrics(jobManagerMetricGroup)
    +  }
    +
    +  private def instantiateStatusMetrics(jobManagerMetricGroup: MetricGroup) 
: Unit = {
    +    val jvm = jobManagerMetricGroup
    +      .addGroup("Status")
    +      .addGroup("JVM")
    +
    +    instantiateClassLoaderMetrics(jvm.addGroup("ClassLoader"))
    +    instantiateGarbageCollectorMetrics(jvm.addGroup("GarbageCollector"))
    +    instantiateMemoryMetrics(jvm.addGroup("Memory"))
    +    instantiateThreadMetrics(jvm.addGroup("Threads"))
    +    instantiateCPUMetrics(jvm.addGroup("CPU"))
    +  }
    +
    +  private def instantiateClassLoaderMetrics(metrics: MetricGroup) {
    +    val mxBean = ManagementFactory.getClassLoadingMXBean
    +
    +    metrics
    +      .gauge("ClassesLoaded", new Gauge[Long] {
    +        override def getValue: Long = mxBean.getTotalLoadedClassCount
    +      })
    +    metrics.gauge("ClassesUnloaded", new Gauge[Long] {
    +      override def getValue: Long = mxBean.getUnloadedClassCount
    +    })
    +  }
    +
    +  private def instantiateGarbageCollectorMetrics(metrics: MetricGroup) {
    +    val garbageCollectors = ManagementFactory.getGarbageCollectorMXBeans
    +
    +    for (garbageCollector <- garbageCollectors) {
    +      val gcGroup = metrics.addGroup("\"" + garbageCollector.getName + 
"\"")
    +      gcGroup.gauge("Count", new Gauge[Long] {
    +        override def getValue: Long = garbageCollector.getCollectionCount
    +      })
    +      gcGroup.gauge("Time", new Gauge[Long] {
    +        override def getValue: Long = garbageCollector.getCollectionTime
    +      })
    +    }
    +  }
    +
    +  private def instantiateMemoryMetrics(metrics: MetricGroup) {
    +    val mxBean = ManagementFactory.getMemoryMXBean
    +    val heap = metrics.addGroup("Heap")
    +    heap.gauge("Used", new Gauge[Long] {
    +      override def getValue: Long = mxBean.getHeapMemoryUsage.getUsed
    +    })
    +    heap.gauge("Committed", new Gauge[Long] {
    +      override def getValue: Long = mxBean.getHeapMemoryUsage.getCommitted
    +    })
    +    heap.gauge("Max", new Gauge[Long] {
    +      override def getValue: Long = mxBean.getHeapMemoryUsage.getMax
    +    })
    +
    +    val nonHeap = metrics.addGroup("NonHeap")
    +    nonHeap.gauge("Used", new Gauge[Long] {
    +      override def getValue: Long = mxBean.getNonHeapMemoryUsage.getUsed
    +    })
    +    nonHeap.gauge("Committed", new Gauge[Long] {
    +      override def getValue: Long = 
mxBean.getNonHeapMemoryUsage.getCommitted
    +    })
    +    nonHeap.gauge("Max", new Gauge[Long] {
    +      override def getValue: Long = mxBean.getNonHeapMemoryUsage.getMax
    +    })
    +
    +    val con = ManagementFactory.getPlatformMBeanServer;
    +
    +    val directObjectName = new 
ObjectName("java.nio:type=BufferPool,name=direct")
    +
    +    val direct = metrics.addGroup("Direct")
    +    direct.gauge("Count", new Gauge[Long] {
    +      override def getValue: Long = con
    +        .getAttribute(directObjectName, "Count").asInstanceOf[Long]
    --- End diff --
    
    according to the javadocs this method never returns null.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to