From bd2b6473c5eebb37969fc9a9535326888b8adf55 Mon Sep 17 00:00:00 2001 From: Diego Date: Wed, 22 Jan 2014 00:38:19 -0300 Subject: added kamon-newrelic-example and updated newrelic documentation --- examples/kamon-newrelic-example/build.sbt | 26 ++++ .../project/build.properties | 1 + .../kamon-newrelic-example/project/plugins.sbt | 9 ++ .../src/main/resources/application.conf | 10 ++ .../src/main/scala/NewRelicExample.scala | 40 ++++++ site/src/jekyll/assets/img/newrelic.png | Bin 0 -> 131322 bytes site/src/jekyll/assets/img/newrelicdifu2.png | Bin 139178 -> 0 bytes site/src/jekyll/newrelic/index.md | 134 ++++++++++----------- 8 files changed, 153 insertions(+), 67 deletions(-) create mode 100644 examples/kamon-newrelic-example/build.sbt create mode 100644 examples/kamon-newrelic-example/project/build.properties create mode 100644 examples/kamon-newrelic-example/project/plugins.sbt create mode 100644 examples/kamon-newrelic-example/src/main/resources/application.conf create mode 100644 examples/kamon-newrelic-example/src/main/scala/NewRelicExample.scala create mode 100644 site/src/jekyll/assets/img/newrelic.png delete mode 100644 site/src/jekyll/assets/img/newrelicdifu2.png diff --git a/examples/kamon-newrelic-example/build.sbt b/examples/kamon-newrelic-example/build.sbt new file mode 100644 index 00000000..89b1b3d3 --- /dev/null +++ b/examples/kamon-newrelic-example/build.sbt @@ -0,0 +1,26 @@ +import sbt._ +import sbt.Keys._ + +import com.typesafe.sbt.SbtAspectj._ + +aspectjSettings + +name := "kamon-newrelic-example" + +version := "1.0" + +scalaVersion := "2.10.2" + +resolvers += "Kamon repo" at "http://repo.kamon.io" + +resolvers += "spray repo" at "http://repo.spray.io" + +libraryDependencies += "kamon" %% "kamon-core" % "0.0.12" + +libraryDependencies += "kamon" %% "kamon-spray" % "0.0.12" + +libraryDependencies += "kamon" %% "kamon-newrelic" % "0.0.12" + +libraryDependencies += "io.spray" % "spray-can" % "1.2.0" + +javaOptions <++= AspectjKeys.weaverOptions in Aspectj diff --git a/examples/kamon-newrelic-example/project/build.properties b/examples/kamon-newrelic-example/project/build.properties new file mode 100644 index 00000000..db255c25 --- /dev/null +++ b/examples/kamon-newrelic-example/project/build.properties @@ -0,0 +1 @@ +sbt.version=0.12.3 \ No newline at end of file diff --git a/examples/kamon-newrelic-example/project/plugins.sbt b/examples/kamon-newrelic-example/project/plugins.sbt new file mode 100644 index 00000000..6e42c696 --- /dev/null +++ b/examples/kamon-newrelic-example/project/plugins.sbt @@ -0,0 +1,9 @@ +resolvers += "Sonatype snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/" + +resolvers += "Kamon Releases" at "http://repo.kamon.io" + +addSbtPlugin("com.ivantopo.sbt" % "sbt-newrelic" % "0.0.1") + +addSbtPlugin("com.typesafe.sbt" % "sbt-aspectj" % "0.9.4") + +addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.5.2") \ No newline at end of file diff --git a/examples/kamon-newrelic-example/src/main/resources/application.conf b/examples/kamon-newrelic-example/src/main/resources/application.conf new file mode 100644 index 00000000..52944172 --- /dev/null +++ b/examples/kamon-newrelic-example/src/main/resources/application.conf @@ -0,0 +1,10 @@ +akka { + extensions = ["kamon.newrelic.NewRelic"] +} + +kamon { + newrelic { + app-name = "KamonNewRelicExample[Development]" + license-key = <> + } +} diff --git a/examples/kamon-newrelic-example/src/main/scala/NewRelicExample.scala b/examples/kamon-newrelic-example/src/main/scala/NewRelicExample.scala new file mode 100644 index 00000000..e111e473 --- /dev/null +++ b/examples/kamon-newrelic-example/src/main/scala/NewRelicExample.scala @@ -0,0 +1,40 @@ +/* =================================================== + * Copyright © 2013 2014 the kamon project + * + * 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. + * ========================================================== */ + +import akka.actor.ActorSystem +import spray.routing.SimpleRoutingApp + +object NewRelicExample extends App with SimpleRoutingApp { + + implicit val system = ActorSystem("kamon-system") + + startServer(interface = "localhost", port = 8080) { + path("helloKamon") { + get { + complete { +

Say hello to Kamon

+ } + } + } ~ + path("helloNewRelic") { + get { + complete { +

Say hello to NewRelic

+ } + } + } + } +} \ No newline at end of file diff --git a/site/src/jekyll/assets/img/newrelic.png b/site/src/jekyll/assets/img/newrelic.png new file mode 100644 index 00000000..ea5e1ec7 Binary files /dev/null and b/site/src/jekyll/assets/img/newrelic.png differ diff --git a/site/src/jekyll/assets/img/newrelicdifu2.png b/site/src/jekyll/assets/img/newrelicdifu2.png deleted file mode 100644 index 82bcc87d..00000000 Binary files a/site/src/jekyll/assets/img/newrelicdifu2.png and /dev/null differ diff --git a/site/src/jekyll/newrelic/index.md b/site/src/jekyll/newrelic/index.md index 3ce6d29d..be182cc4 100644 --- a/site/src/jekyll/newrelic/index.md +++ b/site/src/jekyll/newrelic/index.md @@ -7,112 +7,112 @@ NewRelic Module === A simple module to report some application metrics like External Services, Errors and Apdex. ---- -Dependencies ---- - -Apart from scala library kamon depends on: - -- aspectj -- new relic agent -- spray-io -- akka-actor - - -Installation ---- -Kamon works with SBT, so you need to add Kamon.io repository to your resolvers. - Configuration --- -Just like other products in the scala ecosystem, it relies on the typesafe configuration library. If you are a new relic user, you will requiere to add a logger to the application.conf file - -Since kamon uses the same configuration technique as [Spray](http://spray.io/documentation "Spray") / [Akka](http://akka.io/docs "Akka") you might want to check out the [Akka-Documentation-configuration](http://doc.akka.io/docs/akka/2.1.4/general/configuration.html "Akka Documentation on configuration"). +**In order to see Kamon in action you just follow this Simple Example:** -In order to see Kamon in action you need first to set up your sbt project. Add the following sbt dependencies to your project settings: -1) Add Kamon repository to resolvers +1) All Kamon libraries are available through the official Kamon repository: ```scala - "Kamon Repository" at "http://repo.kamon.io" +"Kamon Repository" at "http://repo.kamon.io" ``` -2) Add libraryDepenency +2) Add the libraries to your project: + +```scala +resolvers += "Kamon Repository" at "http://repo.kamon.io" + +"kamon" %% "kamon-core" % "0.0.12" + +"kamon" %% "kamon-spray" % "0.0.12" -```scala - "kamon" %% "kamon-spray" % "0.0.11", - "kamon" %% "kamon-newrelic" % "0.0.11" +"kamon" %% "kamon-newrelic" % "0.0.12" ``` -In addition we suggest to create aspectj.sbt file and add this content +Also you need add this lines into the build.sbt in order to configure the [sbt-aspectj](https://github.com/sbt/sbt-aspectj/) plugin: ```scala - import com.typesafe.sbt.SbtAspectj._ +import com.typesafe.sbt.SbtAspectj._ - aspectjSettings +aspectjSettings - javaOptions <++= AspectjKeys.weaverOptions in Aspectj +javaOptions <++= AspectjKeys.weaverOptions in Aspectj ``` -3) Add to your plugins.sbt in project folder (if you don't have one yet, create the file) and add the Kamon release to the resolver and the aspecj. You need to add the sbt-newrelic plugin +3) Add to your `plugins.sbt` in project folder (if you don't have one yet, create the file) and add this content: ```scala - resolvers += Resolver.url("Kamon Releases", url("http://repo.kamon.io"))(Resolver.ivyStylePatterns) +resolvers += "Kamon Releases" at "http://repo.kamon.io" - addSbtPlugin("com.ivantopo.sbt" %% "sbt-newrelic" % "0.0.1") +addSbtPlugin("com.ivantopo.sbt" %% "sbt-newrelic" % "0.0.1") - addSbtPlugin("com.typesafe.sbt" % "sbt-aspectj" % "0.9.2") +addSbtPlugin("com.typesafe.sbt" % "sbt-aspectj" % "0.9.4") ``` -In addittion, you have to provide the new relic agent and configure a logger in application.conf file. - -**application.conf** +4) Our Reactive Application: ```scala - akka { - loggers = ["akka.event.slf4j.Slf4jLogger","kamon.newrelic.NewRelicErrorLogger"] - - extensions = ["kamon.newrelic.NewRelic"] - actor { - debug { - unhandled = on - } - } - } +import akka.actor.ActorSystem +import spray.routing.SimpleRoutingApp + +object NewRelicExample extends App with SimpleRoutingApp { + + implicit val system = ActorSystem("kamon-system") + + startServer(interface = "localhost", port = 8080) { + path("helloKamon") { + get { + complete { +

Say hello to Kamon

+ } + } + } ~ + path("helloNewRelic") { + get { + complete { +

Say hello to NewRelic

+ } + } + } + } +} ``` -Optionally you can add the newrelic agent in the command line + +5) In addition, you have to provide some information about NewRelic configuration in the **application.conf**: ```scala --javaagent:/path-to-newrelic-agent.jar, -Dnewrelic.environment=production, -Dnewrelic.config.file=/path-to-newrelic.yml +akka { + extensions = ["kamon.newrelic.NewRelic"] +} + +kamon { + newrelic { + app-name = "KamonNewRelicExample[Development]" + license-key = <> + } +} ``` +6) Add the [NewRelic](http://newrelic.com/) Agent: -Examples ---- - -The examples will start a spray server with akka, new relic and logback configuration. Adjust it to your needs in order to see the data in your new relic service. - -Follow the steps in order to clone the repository - -1. git clone git://github.com/kamon/kamon.git - -2. cd kamon - -run - -```bash - sbt "project kamon-new-relic-uow-example" +```scala +-javaagent:/path-to-newrelic-agent.jar -Dnewrelic.environment=production -Dnewrelic.config.file=/path-to-newrelic.yml ``` +In case you want to keep the NewRelic Agent related setting, take a look at [NewRelic](https://docs.newrelic.com/docs/java/new-relic-for-java) + -In order to see how it works, you need to send a message to the rest service +7) To see how it works, you need to send a messages to the rest services ```bash - curl -v --header 'X-UOW:YOUR_TRACER_ID' -X GET 'http://0.0.0.0:6666/fibonacci' +ab -k -n 2000 http://localhost:8080/helloNewRelic ``` +### Example +This and others examples are found in the [GitHub](https://github.com/kamon-io/Kamon/tree/master/examples/) Kamon repository inside examples folder. ### Screenshot -![newrelic](/assets/img/newrelicdifu2.png "Screenshot NewRelic") +![newrelic](/assets/img/newrelic.png "NewRelic Screenshot") ## Limitations -- cgit v1.2.3