diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2014-11-09 18:44:39 +0100 |
---|---|---|
committer | Ivan Topolnjak <ivantopo@gmail.com> | 2014-11-09 18:44:39 +0100 |
commit | 6adfad4127d8fad73000d3c47e6a0f89d1e58fa5 (patch) | |
tree | 1e10d93c760542e9c95333c03e9756ee291eb7d1 /kamon-newrelic/src/main/scala/kamon/newrelic/JsonProtocol.scala | |
parent | 5681a09bdd1fdbc6a7e0a42bb51f18406b70eaff (diff) | |
parent | 01117944af0363e37807a071f8f22ecaca0931f6 (diff) | |
download | Kamon-6adfad4127d8fad73000d3c47e6a0f89d1e58fa5.tar.gz Kamon-6adfad4127d8fad73000d3c47e6a0f89d1e58fa5.tar.bz2 Kamon-6adfad4127d8fad73000d3c47e6a0f89d1e58fa5.zip |
Merge branch 'wip/newrelic-agent-rewrite'
Diffstat (limited to 'kamon-newrelic/src/main/scala/kamon/newrelic/JsonProtocol.scala')
-rw-r--r-- | kamon-newrelic/src/main/scala/kamon/newrelic/JsonProtocol.scala | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/kamon-newrelic/src/main/scala/kamon/newrelic/JsonProtocol.scala b/kamon-newrelic/src/main/scala/kamon/newrelic/JsonProtocol.scala new file mode 100644 index 00000000..c573d04d --- /dev/null +++ b/kamon-newrelic/src/main/scala/kamon/newrelic/JsonProtocol.scala @@ -0,0 +1,65 @@ +/* =================================================== + * Copyright © 2013 the kamon project <http://kamon.io/> + * + * Licensed 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 kamon.newrelic + +import spray.json._ +import kamon.newrelic.Agent._ + +object JsonProtocol extends DefaultJsonProtocol { + + implicit object ConnectJsonWriter extends RootJsonWriter[Settings] { + def write(obj: Settings): JsValue = + JsArray( + JsObject( + "agent_version" -> JsString("3.1.0"), + "app_name" -> JsArray(JsString(obj.appName)), + "host" -> JsString(obj.host), + "identifier" -> JsString(s"java:${obj.appName}"), + "language" -> JsString("java"), + "pid" -> JsNumber(obj.pid))) + } + + implicit def seqWriter[T: JsonWriter] = new JsonWriter[Seq[T]] { + def write(seq: Seq[T]) = JsArray(seq.map(_.toJson).toVector) + } + + implicit object MetricDetailWriter extends JsonWriter[Metric] { + def write(obj: Metric): JsValue = { + val (metricID, metricData) = obj + + JsArray( + JsObject( + "name" -> JsString(metricID.name) // TODO Include scope + ), + JsArray( + JsNumber(metricData.callCount), + JsNumber(metricData.total), + JsNumber(metricData.totalExclusive), + JsNumber(metricData.min), + JsNumber(metricData.max), + JsNumber(metricData.sumOfSquares))) + } + } + + implicit object MetricBatchWriter extends RootJsonWriter[MetricBatch] { + def write(obj: MetricBatch): JsValue = + JsArray( + JsNumber(obj.runID), + JsNumber(obj.timeSliceMetrics.from), + JsNumber(obj.timeSliceMetrics.to), + obj.timeSliceMetrics.metrics.toSeq.toJson) + } +} |