简体   繁体   中英

Measure the rate at which messages arrive in a Akka Streams Flow or a Sink

I have written an Akka Streams application and its working fine.

What I want to do is to attach my JMX console to the JVM intance running the Akka Streams application and then study the amount of messages coming into my Sink and Flows.

Is this possible? I googled but didn't find a concrete way.

The final stage of my application is a sink to a Cassandra database. I want to know the rate of messages per second coming into the Sink.

I also want to pick a random Flow in my graph and then know the number of messages per second flowing through the flow.

Is there anything out of box? or should I just code something like dropwizard into each of my flows to measure the rate.

Presently there is nothing "out of the box" you can leverage to monitor rates inside your Akka Stream.

However, this is a very simple facility you can extract in a monitoring Flow you can place wherever it fits your needs.

The example below is based on Kamon , but you can see it can be ported to Dropwizard very easily:

  def meter[T](name: String): Flow[T, T, NotUsed] = {
    val msgCounter = Kamon.metrics.counter(name)

    Flow[T].map { x =>
      msgCounter.increment()
      x
    }
  }

  mySource
    .via(meter("source"))
    .via(myFlow)
    .via(meter("sink"))
    .runWith(mySink)

The above is part of a demo you can find at this repo . An ad-hoc solution like this has the advantage of being perfectly tailored for your application, whilst keeping simplicity.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM