简体   繁体   English

测量消息在“ Akka流”或“接收器”中到达的速率

[英]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. 我已经编写了一个Akka Streams应用程序,并且可以正常工作。

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. 我要做的是将JMX控制台附加到运行Akka Streams应用程序的JVM实例上,然后研究流入我的Sink和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. 我的应用程序的最后阶段是Cassandra数据库的接收器。 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. 还是我应该在每个流程中编写诸如dropwizard之类的代码来测量速率。

Presently there is nothing "out of the box" you can leverage to monitor rates inside your Akka Stream. 目前,您没有什么可以“开箱即用”来监控Akka Stream中的费率。

However, this is a very simple facility you can extract in a monitoring Flow you can place wherever it fits your needs. 但是,这是一个非常简单的工具,您可以提取一个监视Flow ,将其放置在适合您需要的任何位置。

The example below is based on Kamon , but you can see it can be ported to Dropwizard very easily: 以下示例基于Kamon ,但是您可以看到它可以很容易地移植到Dropwizard:

  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. 这样的临时解决方案的优势是可以为您的应用程序量身定制,同时保持简单性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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