diff options
author | Diego Parra <diegolparra@gmail.com> | 2014-12-04 08:16:07 -0600 |
---|---|---|
committer | Diego Parra <diegolparra@gmail.com> | 2014-12-04 08:16:07 -0600 |
commit | f2e3eec7cb324a183345f7338b152c4293721d38 (patch) | |
tree | 2d9be3524a1b0df6c29c96a3e1b455f1147ab0ff | |
parent | 3905757c2eb9658d136c50de82180a74b002df7e (diff) | |
parent | fe724251011c177aabdf2810dfb5d4eb3a97852c (diff) | |
download | Kamon-f2e3eec7cb324a183345f7338b152c4293721d38.tar.gz Kamon-f2e3eec7cb324a183345f7338b152c4293721d38.tar.bz2 Kamon-f2e3eec7cb324a183345f7338b152c4293721d38.zip |
Merge pull request #124 from carrot-garden/sigar-review-1
+ system-metrics: two-phase sigar loading
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | kamon-core/src/test/resources/logback.xml | 5 | ||||
-rw-r--r-- | kamon-system-metrics/src/main/resources/reference.conf | 4 | ||||
-rw-r--r-- | kamon-system-metrics/src/main/scala/kamon/system/SystemMetricsCollector.scala | 30 | ||||
-rw-r--r-- | kamon-system-metrics/src/test/scala/kamon/metrics/RedirectLogging.scala | 34 | ||||
-rw-r--r-- | kamon-system-metrics/src/test/scala/kamon/metrics/SystemMetricsSpec.scala | 2 | ||||
-rw-r--r-- | project/Dependencies.scala | 4 | ||||
-rw-r--r-- | project/Projects.scala | 4 |
8 files changed, 76 insertions, 10 deletions
@@ -48,3 +48,6 @@ test-result server.pid *.iml *.eml + +# Default sigar library provision location. +native/ diff --git a/kamon-core/src/test/resources/logback.xml b/kamon-core/src/test/resources/logback.xml index 2ae1e3bd..eb578346 100644 --- a/kamon-core/src/test/resources/logback.xml +++ b/kamon-core/src/test/resources/logback.xml @@ -1,4 +1,9 @@ <configuration scan="true"> + + <contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator"> + <resetJUL>true</resetJUL> + </contextListener> + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>%date{HH:mm:ss.SSS} %-5level [%X{uow}][%X{requestId}] [%thread] %logger{55} - %msg%n</pattern> diff --git a/kamon-system-metrics/src/main/resources/reference.conf b/kamon-system-metrics/src/main/resources/reference.conf index 0fab129f..4d564e38 100644 --- a/kamon-system-metrics/src/main/resources/reference.conf +++ b/kamon-system-metrics/src/main/resources/reference.conf @@ -2,6 +2,10 @@ # Kamon-System-Metrics Reference Configuration # # ============================================ # +# Sigar provisioner native library extract location. +# Use per-application-instance scoped location, such as program working directory. +kamon.sigar.folder = ${user.dir}"/native" + kamon { metrics { precision { diff --git a/kamon-system-metrics/src/main/scala/kamon/system/SystemMetricsCollector.scala b/kamon-system-metrics/src/main/scala/kamon/system/SystemMetricsCollector.scala index bb7fa105..8094cac4 100644 --- a/kamon-system-metrics/src/main/scala/kamon/system/SystemMetricsCollector.scala +++ b/kamon-system-metrics/src/main/scala/kamon/system/SystemMetricsCollector.scala @@ -158,16 +158,34 @@ class SystemMetricsCollector(collectInterval: FiniteDuration) extends Actor with rcs.global.record(contextSwitches) } + def verifiedSigarInstance: SigarProxy = { + val sigar = new Sigar() + printBanner(sigar) + sigar + } + + def provisionSigarLibrary: Unit = { + val folder = context.system.settings.config.getString("kamon.sigar.folder") + SigarProvisioner.provision(new File(folder)) + } + def createSigarInstance: SigarProxy = { - val tempFolder = new File(System.getProperty("java.io.tmpdir")) + // 1) Assume that library is already provisioned. + try { + return verifiedSigarInstance + } catch { + // Not using [[Try]] - any error is non-fatal in this case. + case e: Throwable ⇒ log.info(s"Sigar is not yet provisioned: ${e}") + } + + // 2) Attempt to provision library via sigar-loader. try { - SigarProvisioner.provision(tempFolder) - val sigar = new Sigar() - printBanner(sigar) - sigar + provisionSigarLibrary + return verifiedSigarInstance } catch { - case NonFatal(t) ⇒ throw new UnexpectedSigarException("Failed to load sigar") + // Not using [[Try]] - any error is non-fatal in this case. + case e: Throwable ⇒ throw new UnexpectedSigarException(s"Failed to load Sigar: ${e}") } } } diff --git a/kamon-system-metrics/src/test/scala/kamon/metrics/RedirectLogging.scala b/kamon-system-metrics/src/test/scala/kamon/metrics/RedirectLogging.scala new file mode 100644 index 00000000..fbf42cf0 --- /dev/null +++ b/kamon-system-metrics/src/test/scala/kamon/metrics/RedirectLogging.scala @@ -0,0 +1,34 @@ +/* ========================================================================================= + * Copyright © 2013-2014 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.metric + +import java.util.logging.LogManager +import org.slf4j.bridge.SLF4JBridgeHandler + +/** + * Redirect different logging sources to SLF4J. + */ +trait RedirectLogging { + + def redirectLogging(): Unit = { + // Redirect JUL to SLF4J. + LogManager.getLogManager().reset(); + SLF4JBridgeHandler.install(); + } + + redirectLogging() + +} diff --git a/kamon-system-metrics/src/test/scala/kamon/metrics/SystemMetricsSpec.scala b/kamon-system-metrics/src/test/scala/kamon/metrics/SystemMetricsSpec.scala index 058dafb4..714a1e6d 100644 --- a/kamon-system-metrics/src/test/scala/kamon/metrics/SystemMetricsSpec.scala +++ b/kamon-system-metrics/src/test/scala/kamon/metrics/SystemMetricsSpec.scala @@ -33,7 +33,7 @@ import org.scalatest.{ Matchers, WordSpecLike } import scala.concurrent.duration._ -class SystemMetricsSpec extends TestKitBase with WordSpecLike with Matchers { +class SystemMetricsSpec extends TestKitBase with WordSpecLike with Matchers with RedirectLogging { implicit lazy val system: ActorSystem = ActorSystem("system-metrics-spec", ConfigFactory.parseString( """ |akka { diff --git a/project/Dependencies.scala b/project/Dependencies.scala index c66d77a1..761db941 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -25,7 +25,7 @@ object Dependencies { val sprayVersion = "1.3.2" val akkaVersion = "2.3.6" val aspectjVersion = "1.8.4" - val slf4jVersion = "1.7.6" + val slf4jVersion = "1.7.7" val playVersion = "2.3.5" val sigarVersion = "1.6.5.132" @@ -50,6 +50,8 @@ object Dependencies { val playTest = "org.scalatestplus" %% "play" % "1.2.0" val slf4Api = "org.slf4j" % "slf4j-api" % slf4jVersion val slf4nop = "org.slf4j" % "slf4j-nop" % slf4jVersion + val slf4Jul = "org.slf4j" % "jul-to-slf4j" % slf4jVersion + val slf4Log4j = "org.slf4j" % "log4j-over-slf4j" % slf4jVersion val scalaCompiler = "org.scala-lang" % "scala-compiler" % Settings.ScalaVersion val scalazConcurrent = "org.scalaz" %% "scalaz-concurrent" % "7.1.0" val sigarLoader = "io.kamon" % "sigar-loader" % "1.6.5-rev001" diff --git a/project/Projects.scala b/project/Projects.scala index aa583e2e..83bf13a0 100644 --- a/project/Projects.scala +++ b/project/Projects.scala @@ -42,7 +42,7 @@ object Projects extends Build { compile(akkaActor, hdrHistogram) ++ provided(aspectJ) ++ optional(logback, scalazConcurrent) ++ - test(scalatest, akkaTestKit, akkaSlf4j, logback)) + test(scalatest, akkaTestKit, akkaSlf4j, slf4Jul, slf4Log4j, logback)) lazy val kamonAkkaRemote = Project("kamon-akka-remote", file("kamon-akka-remote")) @@ -169,7 +169,7 @@ object Projects extends Build { .settings( libraryDependencies ++= compile(sigarLoader) ++ - test(scalatest, akkaTestKit, slf4Api, slf4nop)) + test(scalatest, akkaTestKit, slf4Api, slf4Jul, slf4Log4j, logback)) .dependsOn(kamonCore) lazy val kamonJdbc = Project("kamon-jdbc", file("kamon-jdbc")) |