-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-25228][CORE]Add executor CPU time metric. #22218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
c715096
438bf90
807119b
d522fa2
b7fdec2
95d31f6
e72966e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,9 @@ | |
|
|
||
| package org.apache.spark.executor | ||
|
|
||
| import java.lang.management.ManagementFactory | ||
| import java.util.concurrent.ThreadPoolExecutor | ||
| import javax.management.{MBeanServer, ObjectName} | ||
|
|
||
| import scala.collection.JavaConverters._ | ||
|
|
||
|
|
@@ -73,6 +75,29 @@ class ExecutorSource(threadPool: ThreadPoolExecutor, executorId: String) extends | |
| registerFileSystemStat(scheme, "write_ops", _.getWriteOps(), 0) | ||
| } | ||
|
|
||
| /** Dropwizard metrics gauge measuring the executor's process CPU time. | ||
| * This code will try to get JVM Process CPU time or return -1 otherwise. | ||
| * The CPU time value is returned in nanoseconds. | ||
| * It will use proprietary extensions as com.sun.management.OperatingSystemMXBean or | ||
| * com.ibm.lang.management.OperatingSystemMXBean if available | ||
| */ | ||
| val mBean: MBeanServer = ManagementFactory.getPlatformMBeanServer | ||
|
||
| val name = new ObjectName("java.lang", "type", "OperatingSystem") | ||
| metricRegistry.register(MetricRegistry.name("executorCPUTime" ), new Gauge[Long] { | ||
|
||
| override def getValue: Long = { | ||
| try { | ||
| val attribute = mBean.getAttribute(name, "ProcessCpuTime") | ||
| if (attribute != null) { | ||
|
||
| attribute.asInstanceOf[Long] | ||
| } else { | ||
| -1L | ||
|
||
| } | ||
| } catch { | ||
| case _ : Exception => -1L | ||
|
||
| } | ||
| } | ||
| }) | ||
|
|
||
| // Expose executor task metrics using the Dropwizard metrics system. | ||
| // The list is taken from TaskMetrics.scala | ||
| val METRIC_CPU_TIME = metricRegistry.counter(MetricRegistry.name("cpuTime")) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: the comments should begin on the next line. But this is scaladoc syntax, and inside a code block, normally we just use
//block comments.