-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathDemoMetricsPlugin.scala
39 lines (33 loc) · 1.25 KB
/
DemoMetricsPlugin.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package ch.cern
import java.util.{Map => JMap}
import scala.collection.JavaConverters._
import com.codahale.metrics.{Gauge, MetricRegistry}
import org.apache.spark.api.plugin.{DriverPlugin, ExecutorPlugin, PluginContext, SparkPlugin}
import org.apache.spark.SparkContext
class DemoMetricsPlugin extends SparkPlugin {
// Return the plugin's driver-side component.
override def driverPlugin(): DriverPlugin = {
new DriverPlugin() {
override def init(sc: SparkContext, myContext: PluginContext): JMap[String, String] = {
val metricRegistry = myContext.metricRegistry
// Gauge for testing
metricRegistry.register(MetricRegistry.name("DriverTest42"), new Gauge[Int] {
override def getValue: Int = 42
})
Map.empty[String, String].asJava
}
}
}
// Return the plugin's executor-side component.
override def executorPlugin(): ExecutorPlugin = {
new ExecutorPlugin {
override def init(myContext:PluginContext, extraConf:JMap[String, String]) = {
// Gauge for testing
val metricRegistry = myContext.metricRegistry
metricRegistry.register(MetricRegistry.name("ExecutorTest42"), new Gauge[Int] {
override def getValue: Int = 42
})
}
}
}
}