-
Notifications
You must be signed in to change notification settings - Fork 54
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
Possibility to get metrics in code #4
Comments
Hi @darkjh, there's currently no way to get metrics from individual instances of metrics like this, but it should be possible to get the aggregated metrics using Spark's API. It's a bit convoluted at the moment though, so I'll make a note of this to see if I can add a cleaner API for this. Here's a quick example which should work, I haven't ran it myself though so let me know if there are any issues: import collection.JavaConverters._
val sc = SparkContext.getOrCreate()
val metricNamespace = "myMetricNamespace"
UserMetricsSystem.initialize(sc, metricNamespace)
UserMetricSystem.getGauge("myGauge").set(1)
// Obtained from here: https://github.com/groupon/spark-metrics/blob/spark-metrics-1.0/src/main/scala/org/apache/spark/groupon/metrics/MetricsReceiver.scala#L172
val sourceName = s"${sc.appName}.$metricNamespace"
val gauges = for {
source <- sc.metricsSystem.getSourcesByName(sourceName)
(gaugeName, gauge) <- source.metricRegistry.getGauges.asScala
} yield {
gaugeName -> gauge
}
val myGaugeValue = gauges.toMap.get("myGauge").map(gauge => gauge.getValue)
One caveat with this though is that calling I'll keep this use case in mind for a future release, thanks for bringing it up! |
I used your approach and it works perfectly. |
Hi,
I'm wondering with this library or spark's metric system itself, is it possible to get the metrics directly in code?
For example I've an spark application:
The text was updated successfully, but these errors were encountered: