Github user tillrohrmann commented on a diff in the pull request: https://github.com/apache/flink/pull/2146#discussion_r68741425 --- Diff: flink-runtime/src/main/scala/org/apache/flink/runtime/jobmanager/JobManager.scala --- @@ -1727,6 +1764,160 @@ 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 + + garbageCollectors.asScala foreach { + case gc => + val gcGroup = metrics.addGroup("\"" + gc.getName + "\"") + gcGroup.gauge("Count", new Gauge[Long] { + override def getValue: Long = gc.getCollectionCount + }) + gcGroup.gauge("Time", new Gauge[Long] { + override def getValue: Long = gc.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") + try { + direct.gauge("Count", new Gauge[Long] { + override def getValue: Long = con + .getAttribute(directObjectName, "Count").asInstanceOf[Long] + }) + direct.gauge("MemoryUsed", new Gauge[Long] { + override def getValue: Long = con + .getAttribute(directObjectName, "MemoryUsed").asInstanceOf[Long] + }) + direct.gauge("TotalCapacity", new Gauge[Long] { + override def getValue: Long = con + .getAttribute(directObjectName, "TotalCapacity").asInstanceOf[Long] + }) + } catch { + case e: Exception => + log.debug("Failed to add TaskManager metric.", e); + } + + val mappedObjectName = new ObjectName("java.nio:type=BufferPool,name=mapped") + + val mapped = metrics.addGroup("Mapped") + try { + mapped.gauge("Count", new Gauge[Long] { --- End diff -- Thanks for the info :-)
--- 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. ---