diff options
author | Ivan Topolnak <ivantopo@gmail.com> | 2013-11-08 18:16:14 -0300 |
---|---|---|
committer | Ivan Topolnak <ivantopo@gmail.com> | 2013-11-08 18:16:14 -0300 |
commit | 0a9d299e56db77481c47e23d05491c091d746f52 (patch) | |
tree | ee1c227fc0c8f3ed6e40863097e5e1e8d20434b4 /kamon-newrelic/src/main/scala/kamon/newrelic | |
parent | bf86900669d649308f4914c54e6fe076510506a6 (diff) | |
download | Kamon-0a9d299e56db77481c47e23d05491c091d746f52.tar.gz Kamon-0a9d299e56db77481c47e23d05491c091d746f52.tar.bz2 Kamon-0a9d299e56db77481c47e23d05491c091d746f52.zip |
wip
Diffstat (limited to 'kamon-newrelic/src/main/scala/kamon/newrelic')
3 files changed, 20 insertions, 16 deletions
diff --git a/kamon-newrelic/src/main/scala/kamon/newrelic/Agent.scala b/kamon-newrelic/src/main/scala/kamon/newrelic/Agent.scala index c4d7c089..65b631f1 100644 --- a/kamon-newrelic/src/main/scala/kamon/newrelic/Agent.scala +++ b/kamon-newrelic/src/main/scala/kamon/newrelic/Agent.scala @@ -1,6 +1,6 @@ package kamon.newrelic -import akka.actor.Actor +import akka.actor.{ActorLogging, Actor} import spray.json._ import scala.concurrent.Future import spray.httpx.{SprayJsonSupport, RequestBuilding, ResponseTransformation} @@ -13,7 +13,7 @@ import spray.client.pipelining._ import scala.util.control.NonFatal import kamon.newrelic.NewRelicMetric.{Data, ID, MetricBatch} -class Agent extends Actor with RequestBuilding with ResponseTransformation with SprayJsonSupport { +class Agent extends Actor with RequestBuilding with ResponseTransformation with SprayJsonSupport with ActorLogging { import context.dispatcher import Agent._ @@ -79,6 +79,8 @@ class Agent extends Actor with RequestBuilding with ResponseTransformation with def sendMetricData(runId: Long, collector: String, metrics: List[(ID, Data)]) = { + log.info("Reporting this to NewRelic: " + metrics.mkString("\n")) + val end = System.currentTimeMillis() / 1000L val start = end - 60 compressedPipeline { diff --git a/kamon-newrelic/src/main/scala/kamon/newrelic/AgentJsonProtocol.scala b/kamon-newrelic/src/main/scala/kamon/newrelic/AgentJsonProtocol.scala index 30e17e77..990f50dd 100644 --- a/kamon-newrelic/src/main/scala/kamon/newrelic/AgentJsonProtocol.scala +++ b/kamon-newrelic/src/main/scala/kamon/newrelic/AgentJsonProtocol.scala @@ -33,12 +33,12 @@ object AgentJsonProtocol extends DefaultJsonProtocol { "name" -> JsString(id.name) // TODO Include scope ), JsArray( + JsNumber(data.callCount), JsNumber(data.total), JsNumber(data.totalExclusive), JsNumber(data.min), JsNumber(data.max), - JsNumber(data.sumOfSquares), - JsNumber(data.callCount) + JsNumber(data.sumOfSquares) ) ) } diff --git a/kamon-newrelic/src/main/scala/kamon/newrelic/NewRelic.scala b/kamon-newrelic/src/main/scala/kamon/newrelic/NewRelic.scala index 2ee7ada0..a2fbc5e9 100644 --- a/kamon-newrelic/src/main/scala/kamon/newrelic/NewRelic.scala +++ b/kamon-newrelic/src/main/scala/kamon/newrelic/NewRelic.scala @@ -37,7 +37,7 @@ class NewRelicManager extends Actor with ActorLogging { object NewRelicMetric { case class ID(name: String, scope: Option[String]) - case class Data(var total: Double, var totalExclusive: Double, var min: Double, var max: Double, var sumOfSquares: Double, var callCount: Long) { + case class Data(var callCount: Long, var total: Double, var totalExclusive: Double, var min: Double, var max: Double, var sumOfSquares: Double) { def record(value: Double): Unit = { if(value > max) max = value if(value < min) min = value @@ -50,7 +50,7 @@ object NewRelicMetric { } object Data { - def apply(): Data = Data(0, 0, 0, 0, 0, 0) + def apply(): Data = Data(0, 0, 0, Double.MaxValue, 0, 0) } case object FlushMetrics @@ -59,7 +59,7 @@ object NewRelicMetric { class WebTransactionMetrics extends Actor with ActorLogging { - val apdexT = 1500000000 + val apdexT = 0.5D var metrics = mutable.Map.empty[NewRelicMetric.ID, NewRelicMetric.Data] var apdex = NewRelicMetric.Data(0, 0, 0, apdexT, apdexT, 0) @@ -80,23 +80,25 @@ class WebTransactionMetrics extends Actor with ActorLogging { def recordApdex(time: Double): Unit = { if(time <= apdexT) - apdex.total += 1 + apdex.callCount += 1 else if(time > apdexT && time <= (4 * apdexT)) - apdex.totalExclusive += 1 + apdex.total += 1 else - apdex.min += 1 + apdex.totalExclusive += 1 } def updateStats(trace: UowTrace): Unit = { // Basic Metrics - recordApdex(trace.elapsed) - recordValue(NewRelicMetric.ID("WebTransaction", None), trace.elapsed) - recordValue(NewRelicMetric.ID("HttpDispatcher", None), trace.elapsed) - recordValue(NewRelicMetric.ID("WebTransaction/Custom/" + trace.name, None), trace.elapsed) + val elapsedSeconds = trace.elapsed / 1E9D + + recordApdex(elapsedSeconds) + recordValue(NewRelicMetric.ID("WebTransaction", None), elapsedSeconds) + recordValue(NewRelicMetric.ID("HttpDispatcher", None), elapsedSeconds) + recordValue(NewRelicMetric.ID("WebTransaction/Custom/" + trace.name, None), elapsedSeconds) - println("Recorded Apdex: " + apdex) - println("Current Metrics: " + metrics.mkString("\n")) + /*println("Recorded Apdex: " + apdex) + println("Current Metrics: \n" + metrics.mkString("\n"))*/ } } |