1

我有包含已连接用户数的 UsersCount 事件流。当前,当用户数量在特定时间范围内下降一定百分比时会触发查询:

expression Disconnected { x => max(x.usersCount) - x.usersCount }
expression DisconnectedPercent { x => Disconnected(x) / max(x.usersCount) * 100 }
select usersCount, 
       max(usersCount) as maxUsersCount, 
       DisconnectedPercent(users) as disconnectedPercent, 
       Disconnected(users) as disconnectedCount
from UsersCount.win:time(2 min) as users
having DisconnectedPercent(users) >= 30 
   and Disconnected(users) >= 2
output first every 10 minutes

现在我需要改进查询以检查用户是否重新连接,即 DisconnectedPercent 达到某个负阈值,例如:

select ... 
from pattern [every UsersCount(DisconnectedPercent >= 30) -> 
   (timer:interval(10 sec) and not UserCount(DisconnectPercent < -10)].win:time(2 min)

现在我实现的解决方案需要两条语句和一个额外的流。声明一是:

expression Disconnected { x => max(x.usersCount) - x.usersCount } 
expression DisconnectedPercent { x => Disconnected(x) / max(x.usersCount) * 100 }
insert into UsersDisconnectTrigger 
    select usersCount, 
           max(usersCount) as maxUsersCount, 
           Disconnected(users) as disconnectedCount,
           DisconnectedPercent(users) as disconnectedPercent 
from UsersCount.win:time(5 minutes) as users 
having DisconnectedPercent(users) >= 30 and Disconnected(users) >= 10

注册监听器的第二个语句是:

select a.usersCount as usersCount, 
       a.maxUsersCount as maxUsersCount, 
       a.disconnectedCount as disconnectedCount, 
       a.disconnectedPercent as disconnectedPercent 
from pattern [every  a=UsersDisconnectTrigger -> 
           (timer:interval(5 minutes) 
     and not b=UsersCount((usersCount - a.usersCount) / a.usersCount >= 20 / 100)))].win:time(5 minutes)

有没有办法编写单个语句来检测这种模式?是否可以像上面那样选择有意义的值?

4

1 回答 1

0

您想考虑使用“插入”。让第一条语句填充聚合值流。让第二个语句消耗第一个语句的流,当阈值超过时发出警报。让第三个语句消耗第一个语句的流,当它的否定时发出警报。

于 2013-07-24T15:58:03.773 回答