Search code examples
kamon

Where are the Kamon Counters?


I am learning how to do instrumentation using Kamon library.

This is my build.sbt

libraryDependencies ++= Seq(
   "io.kamon" %% "kamon-core" % "0.6.7"
)

This is my plugins.sbt (in project folder)

addSbtPlugin("io.kamon" % "sbt-aspectj-runner" % "1.0.1")

This is my code

import kamon.Kamon

object KamonTest extends App {
   Kamon.start()
   val counter = Kamon.metrics.counter("foo")
   1 to 100000 foreach { x =>
      Thread.sleep(10)
      counter.increment()
   }
   readLine()
   print("press any key to exit")
   readLine()
   Kamon.shutdown()
}

Now when I run this app and run jmc and then go inside the MBEAN browser. I see this

enter image description here

So I cannot find the counter "foo" which I defined in my code.


Solution

  • I was able to solve the issue by the help of the gitter channel of Kamon

    In order to publish to JMX console, we need the following two dependencies more in build.sbt

    "io.kamon" %% "kamon-scala" % "0.6.7",
    "io.kamon" %% "kamon-jmx" % "0.6.7"
    

    We also need the following entries in application.conf

    kamon.jmx {
      subscriptions {
        histogram       = [ "**" ]
        min-max-counter = [ "**" ]
        gauge           = [ "**" ]
        counter         = [ "**" ]
        trace           = [ "**" ]
        trace-segment   = [ "**" ]
        system-metric   = [ "**" ]
        http-server     = [ "**" ]
        kamon-mxbeans   = [ "**" ]
      }
    }
    
    kamon.modules {
      kamon-mxbeans {
        auto-start = yes
        requires-aspectj = no
        extension-class = "kamon.jmx.extension.JMXMetricImporter"
      }
    }
    
    kamon.kamon-mxbeans {
      mbeans = [
        { "name": "example-mbean", "jmxQuery": "example:type=myBean,name=*",
          "attributes": [
            { "name": "foo", "type": "counter" }
          ]
        }
      ],
      identify-delay-interval-ms = 1000,
      identify-interval-ms = 1000,
      value-check-interval-ms = 1000
    }