在黎曼中找到一个字符串

Find a string in Riemann

我想在riemann中使用clojure查找句子中的字符串。我已经使用重新匹配编写了代码,但在执行时遇到了一些错误。

(smap
     (fn [events]
         (let [count-of-failures (count (re-matches #("POST*" (:Webservice %)) events))]

这是我得到的错误

java.lang.ClassCastException: riemann.config$eval96$fn__97$fn__98 cannot be cast to java.util.regex.Pattern
    at clojure.core$re_matcher.invoke(core.clj:4460)
    at clojure.core$re_matches.invoke(core.clj:4497)
    at riemann.config$eval96$fn__97.invoke(riemann_v1.config:31)
    at riemann.streams$smap$stream__3695.invoke(streams.clj:161)
    at riemann.streams$fixed_time_window_fn$stream__3946$fn__3979.invoke(streams.clj:381)
    at riemann.streams$fixed_time_window_fn$stream__3946.invoke(streams.clj:381)
    at riemann.config$eval96$stream__145$fn__150.invoke(riemann_v1.config:25)
    at riemann.config$eval96$stream__145.invoke(riemann_v1.config:25)
    at riemann.core$stream_BANG_$fn__5678.invoke(core.clj:19)
    at riemann.core$stream_BANG_.invoke(core.clj:18)
    at riemann.transport$handle.invoke(transport.clj:159)
    at riemann.transport.tcp$tcp_handler.invoke(tcp.clj:93)
    at riemann.transport.tcp$gen_tcp_handler$fn__5904.invoke(tcp.clj:65)
    at riemann.transport.tcp.proxy$io.netty.channel.ChannelInboundHandlerAdapter$ff19274a.channelRead(Unknown Source)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
    at io.netty.channel.AbstractChannelHandlerContext.access0(AbstractChannelHandlerContext.java:32)
    at io.netty.channel.AbstractChannelHandlerContext.run(AbstractChannelHandlerContext.java:324)
    at io.netty.util.concurrent.DefaultEventExecutor.run(DefaultEventExecutor.java:36)
    at io.netty.util.concurrent.SingleThreadEventExecutor.run(SingleThreadEventExecutor.java:116)
    at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)

我经常使用这样的模式来处理这些事情

(fixed-time-window 10
   (smap
     (fn [events]
         (let [count-of-failures 
               (count (filter #(re-find #"POST*" 
                                        (:Webservice %)) 
                       events))]
            (assoc (first events) 
                   :service "failure-counts"
                   :metric count-of-failures))))
      index
      slack
      prn
      divine-intervention))

对固定时间的顶级调用-window 一次接收一个事件,例如:

{:service "foo"} {:service "foo"} {:service "foo"}

并按时间分组:

[{:service "foo"} {:service "foo"}] [{:service "foo"}]

该捆绑器有一个子流,它获取每个组并对事物进行计数,然后将它们传递给它的子流单个事件,如下所示:

{:service "foo" :metric 2} ;; there where two in the first 10 second window
{:service "foo" :metris 1} ;; there was one in the second 10 second window.

从那里出来的流然后被传递给每个子流。在我的示例中,我将示例子流称为:

  • index ,一个内置函数,将东西放入破折号等的索引中
  • slack 是一个函数,这里没有给出将事件转发到 slack 通道的函数。它是特定于组织的(频道名称、tokesn 等),因此没有必要发布它。
  • prn: 打印到控制台进行调试
  • divine-intervention:另一个函数,谁的实现留作练习,它奇迹般地翻转了所有系统中的适当位以解决问题 ;-)