如何用prometheus对网络流量跳跃异常进行报警?

问题描述 投票:0回答:2

我们想要检测 IaaS 基础设施中的虚拟机是否受到 DDOS 攻击。

我们有几个症状和指标,例如:

node_nf_conntrack_entries
node_network_receive_packets_total
以及
libvirt_domain_interface_stats_receive_packets_total

我们不想通过设置触发点来产生

false positive
。交通 > n 然后警报!

rate(libvirt_domain_interface_stats_receive_packets_total{host="x"}[5m])

rate(node_network_receive_packets_total{instance="y1"}[5m])

sum(node_nf_conntrack_entries_limit - node_nf_conntrack_entries) by (instance) < 1000

prometheus alert libvirt prometheus-node-exporter conntrack
2个回答
2
投票

您可以将最近5分钟的平均网络流量与5分钟前的平均5分钟网络流量进行比较。如果 5 分钟内增加超过 10 倍,则发出警报:

(
  rate(node_network_receive_packets_total[5m])
    /
  rate(node_network_receive_packets_total[5m] offset 5m)
) > 10

请参阅 文档了解偏移量修饰符

此查询可能会导致错误的警报。例如,如果网络流量接近于零,然后增加了 10 倍以上,但绝对值仍然太小。这可以通过在过低的网络流量上添加过滤器来解决。例如,以下查询仅当过去 5 分钟的平均每秒数据包速率大于 1000 时才会发出警报:

((
  rate(node_network_receive_packets_total[5m])
    /
  rate(node_network_receive_packets_total[5m] offset 5m)
) > 10)
  and
(
  rate(node_network_receive_packets_total[5m]) > 1000
)

当网络流量增长速度低于每 5 分钟 10 倍时,此查询可能会错过缓慢变化的 DOS 攻击。当查询应无条件发出警报时,可以通过使用

offset
值或添加绝对最大数据包速率来解决此问题。例如,以下查询将在最后一分钟的平均数据包速率超过 100K/秒时无条件发出警报:

(
  ((
    rate(node_network_receive_packets_total[5m])
      /
    rate(node_network_receive_packets_total[5m] offset 5m)
  ) > 10)
    and
  (
    rate(node_network_receive_packets_total[5m]) > 1000
  )
)
  or
(
  rate(node_network_receive_packets_total[1m]) > 100000
)

请参阅 这些文档,了解

and
or
运算符。


0
投票

要检测峰值,您可以使用

max_over_time
功能:

max_over_time(range-vector):指定区间内所有点的最大值。

这样当alertmanager进行查询时你就不会丢失峰值信息。

© www.soinside.com 2019 - 2024. All rights reserved.