-
Notifications
You must be signed in to change notification settings - Fork 28.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-26928][CORE] Add driver CPU Time to the metrics system
## What changes were proposed in this pull request? This proposes to add instrumentation for the driver's JVM CPU time via the Spark Dropwizard/Codahale metrics system. It follows directly from previous work SPARK-25228 and shares similar motivations: it is intended as an improvement to be used for Spark performance dashboards and monitoring tools/instrumentation. Implementation details: this PR takes the code introduced in SPARK-25228 and moves it to a new separate Source JVMCPUSource, which is then used to register the jvmCpuTime gauge metric for both executor and driver. The registration of the jvmCpuTime metric for the driver is conditional, a new configuration parameter `spark.metrics.cpu.time.driver.enabled` (proposed default: false) is introduced for this purpose. ## How was this patch tested? Manually tested, using local mode and using YARN. Closes #23838 from LucaCanali/addCPUTimeMetricDriver. Authored-by: Luca Canali <luca.canali@cern.ch> Signed-off-by: Marcelo Vanzin <vanzin@cloudera.com>
- Loading branch information
1 parent
6207360
commit 25d2850
Showing
5 changed files
with
58 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
core/src/main/scala/org/apache/spark/metrics/source/JVMCPU.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.spark.metrics.source | ||
|
||
import java.lang.management.ManagementFactory | ||
|
||
import com.codahale.metrics.{Counter, Gauge, MetricRegistry} | ||
import javax.management.{MBeanServer, ObjectName} | ||
import scala.util.control.NonFatal | ||
|
||
private[spark] class JVMCPUSource extends Source { | ||
|
||
override val metricRegistry = new MetricRegistry() | ||
override val sourceName = "JVMCPU" | ||
|
||
// Dropwizard/Codahale metrics gauge measuring the JVM process CPU time. | ||
// This Gauge will try to get and return the JVM Process CPU time or return -1 otherwise. | ||
// The CPU time value is returned in nanoseconds. | ||
// It will use proprietary extensions such as com.sun.management.OperatingSystemMXBean or | ||
// com.ibm.lang.management.OperatingSystemMXBean, if available. | ||
metricRegistry.register(MetricRegistry.name("jvmCpuTime"), new Gauge[Long] { | ||
val mBean: MBeanServer = ManagementFactory.getPlatformMBeanServer | ||
val name = new ObjectName("java.lang", "type", "OperatingSystem") | ||
override def getValue: Long = { | ||
try { | ||
// return JVM process CPU time if the ProcessCpuTime method is available | ||
mBean.getAttribute(name, "ProcessCpuTime").asInstanceOf[Long] | ||
} catch { | ||
case NonFatal(_) => -1L | ||
} | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters