diff options
author | Diego <diegolparra@gmail.com> | 2016-12-13 13:06:29 -0300 |
---|---|---|
committer | Diego <diegolparra@gmail.com> | 2016-12-13 13:06:29 -0300 |
commit | a74379942b2c672c9ba507093f27ead5693c1240 (patch) | |
tree | 1a22f1ae9080e4ec7496f0b5536107b35a5acd68 /kamon-examples/kamon-fluentd-example | |
parent | ee7e2218f869eeea8be00441c82b5e6e8f4d99eb (diff) | |
download | Kamon-a74379942b2c672c9ba507093f27ead5693c1240.tar.gz Kamon-a74379942b2c672c9ba507093f27ead5693c1240.tar.bz2 Kamon-a74379942b2c672c9ba507093f27ead5693c1240.zip |
wip
Diffstat (limited to 'kamon-examples/kamon-fluentd-example')
6 files changed, 202 insertions, 0 deletions
diff --git a/kamon-examples/kamon-fluentd-example/README.md b/kamon-examples/kamon-fluentd-example/README.md new file mode 100644 index 00000000..0dc6a250 --- /dev/null +++ b/kamon-examples/kamon-fluentd-example/README.md @@ -0,0 +1,31 @@ +kamon-fluentd-example +------------------------------ + +An example Spray application with Kamon monitoring reporting to Fluentd Server. + +Prerequisites +--------------- +* fluentd: + ```sh + you@host:kamon-fluentd-example $ gem install fluentd + ``` + +* install kamon snapshots to local: + ```sh + you@host:kamon-fluentd-example $ cd ../../ + you@host:Kamon $ sbt "+ publishLocal" + ... snip... + [info] published ivy to /Users/___/.ivy2/local/io.kamon/kamon-akka-remote_2.11/0.5.2-021ffd253e104342e6b4c75ae42717b51e3b6b26/ivys/ivy.xml + [success] Total time: 248 s, completed 2015/10/04 0:27:53 + [info] Setting version to 2.10.4 + [info] Reapplying settings... + [info] Set current project to kamon (in build file:/Users/___/kamon-io/Kamon/) + ``` + +* edit build.sbt. edit `kamonV` variable with installed snapshot version (`0.5.2-021ffd253e104342e6b4c75ae42717b51e3b6b26` in the above example). + +How to run +------------ +1. just do it: `sbt aspectj-runner:run` +2. you'll see kamon-log-reporter outputs on console. +3. you'll also see kamon metrics sent to fluentd on files named `target/fluentd_out.****` diff --git a/kamon-examples/kamon-fluentd-example/build.sbt b/kamon-examples/kamon-fluentd-example/build.sbt new file mode 100644 index 00000000..a240fad3 --- /dev/null +++ b/kamon-examples/kamon-fluentd-example/build.sbt @@ -0,0 +1,31 @@ +import sbt._ +import sbt.Keys._ + +name := "kamon-fluentd-example" + +version := "1.0" + +scalaVersion := "2.11.6" + +resolvers += "Kamon repo" at "http://repo.kamon.io" + +resolvers += "spray repo" at "http://repo.spray.io" + +libraryDependencies ++= { + val akkaV = "2.3.5" + val sprayV = "1.3.1" + val kamonV = "EDIT_HERE" + Seq( + "io.spray" %% "spray-can" % sprayV, + "io.spray" %% "spray-routing" % sprayV, + "io.kamon" %% "kamon-core" % kamonV, + "io.kamon" %% "kamon-system-metrics" % kamonV, + "io.kamon" %% "kamon-akka" % kamonV, + "io.kamon" %% "kamon-scala" % kamonV, + "io.kamon" %% "kamon-spray" % kamonV, + "io.kamon" %% "kamon-fluentd" % kamonV, + "io.kamon" %% "kamon-log-reporter" % kamonV, + "org.aspectj" % "aspectjweaver" % "1.8.4" + ) +} + diff --git a/kamon-examples/kamon-fluentd-example/project/build.properties b/kamon-examples/kamon-fluentd-example/project/build.properties new file mode 100644 index 00000000..df58110a --- /dev/null +++ b/kamon-examples/kamon-fluentd-example/project/build.properties @@ -0,0 +1 @@ +sbt.version=0.13.6
\ No newline at end of file diff --git a/kamon-examples/kamon-fluentd-example/project/plugins.sbt b/kamon-examples/kamon-fluentd-example/project/plugins.sbt new file mode 100644 index 00000000..ab3750e2 --- /dev/null +++ b/kamon-examples/kamon-fluentd-example/project/plugins.sbt @@ -0,0 +1,6 @@ +resolvers += "Sonatype snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/" + +resolvers += "Kamon Releases" at "http://repo.kamon.io" + +addSbtPlugin("io.kamon" % "aspectj-runner" % "0.1.2") + diff --git a/kamon-examples/kamon-fluentd-example/src/main/resources/application.conf b/kamon-examples/kamon-fluentd-example/src/main/resources/application.conf new file mode 100644 index 00000000..bb69abd3 --- /dev/null +++ b/kamon-examples/kamon-fluentd-example/src/main/resources/application.conf @@ -0,0 +1,73 @@ +# ===================================== # +# Kamon-Fluentd Reference Configuration # +# ===================================== # + +kamon { + metric.filters { + akka-actor { + includes = ["**"], + } + + akka-dispatcher { + includes = ["**"] + } + + akka-router { + includes = ["**"] + } + } + + fluentd { + # Hostname and port of fluentd server to which kamon fluentd sends metrics. + hostname = "localhost" + port = 24224 + + # tag prefix of metrics data which is sent to fluentd server + tag = "kamon.fluentd" + + # Interval between metrics data flushes to fluentd server. + # It's value must be equal or greater than the kamon.metric.tick-interval setting. + flush-interval = 10 seconds + + # Your app name + application-name = "kamon-fluentd-example" + + # Subscription patterns used to select which metrics will be pushed to Fluentd. Note that first, metrics + # collection for your desired entities must be activated under the kamon.metrics.filters settings. + subscriptions { + histogram = [ "**" ] + min-max-counter = [ "**" ] + gauge = [ "**" ] + counter = [ "**" ] + trace = [ "**" ] + trace-segment = [ "**" ] + akka-actor = [ "**" ] + akka-dispatcher = [ "**" ] + akka-router = [ "**" ] + system-metric = [ "**" ] + http-server = [ "**" ] + } + + # statistic values to be reported for histogram type metrics + # (i.e. Histogram, MinMaxCounter, Gauge). + histogram-stats { + # stats values: + # "count", "min", "max", "average", "percentiles" are supported. + # you can use "*" for wildcards. + subscription = [ "count", "min", "max", "average", "percentiles" ], + + # percentile points: + # this will be used when you set "percentiles" in "subscription" above. + # In this example, kamon-fluentd reports 50th 90th, 99th and 99.9th percentiles. + percentiles = [50.0, 90.0, 99.0, 99.9] + } + } + + modules { + kamon-fluentd { + auto-start = yes + requires-aspectj = no + extension-class = "kamon.fluentd.Fluentd" + } + } +}
\ No newline at end of file diff --git a/kamon-examples/kamon-fluentd-example/src/main/scala/KamonFluentdExample.scala b/kamon-examples/kamon-fluentd-example/src/main/scala/KamonFluentdExample.scala new file mode 100644 index 00000000..bb1d0f7b --- /dev/null +++ b/kamon-examples/kamon-fluentd-example/src/main/scala/KamonFluentdExample.scala @@ -0,0 +1,60 @@ +/* ========================================================================================= + * Copyright © 2013-2015 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. + * ========================================================================================= + */ + +import akka.actor.ActorSystem +import kamon.Kamon +import spray.routing.SimpleRoutingApp +import xerial.fluentd.{ FluentdConfig, FluentdStandalone } + +import scala.util.Properties + +object KamonFluentdExample extends App with SimpleRoutingApp { + // Start fluentd server only for this sample app + // In real usecase, you will spawn fluentd server independently. + val fluentdServer = FluentdStandalone.start(FluentdConfig(configuration = + """ + |<source> + | type forward + | port 24224 + |</source> + |<match **> + | type file + | path target/fluentd-out + |</match> + """.stripMargin)) + sys.addShutdownHook { + fluentdServer.stop + } + + // start Kamon + Kamon.start() + + implicit val system = ActorSystem("kamon-fluentd-example") + + // server endpoint + val interface = "0.0.0.0" + val port = Properties.envOrElse("PORT", "8080").toInt + + // resource endpoints + startServer(interface = interface, port = port) { + path("hello") { + get { + complete { + <h1>Hello! Kamon Fluentd Example!</h1> + } + } + } + } +} |