Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 按唯一IP的日志存储计数_Apache_Logging_Ip_Logstash_Metrics - Fatal编程技术网

Apache 按唯一IP的日志存储计数

Apache 按唯一IP的日志存储计数,apache,logging,ip,logstash,metrics,Apache,Logging,Ip,Logstash,Metrics,我想用Logstash做一些日志分析 我需要从Apache访问日志中统计唯一的IP,然后我需要使用计数过滤器对它们进行匹配,以确定是否发送电子邮件 大概是这样的: 如果在5分钟的时间间隔内从一个唯一的IP找到10+访问权限,我需要向他们发送一封带有此IP的电子邮件 什么是最好的解决方案?要做到这一点非常困难——要做到这一点,您需要为每个IP地址创建一个电表。一旦每个IP地址有一个米,你就需要查看它的速率并确定它是否超过你的阈值(注意,速率是过去5分钟内每秒的速率)。一旦您决定需要发送警报,您可能

我想用Logstash做一些日志分析

我需要从Apache访问日志中统计唯一的IP,然后我需要使用计数过滤器对它们进行匹配,以确定是否发送电子邮件

大概是这样的: 如果在5分钟的时间间隔内从一个唯一的IP找到10+访问权限,我需要向他们发送一封带有此IP的电子邮件


什么是最好的解决方案?

要做到这一点非常困难——要做到这一点,您需要为每个IP地址创建一个电表。一旦每个IP地址有一个米,你就需要查看它的速率并确定它是否超过你的阈值(注意,速率是过去5分钟内每秒的速率)。一旦您决定需要发送警报,您可能希望在其中包含IP地址(因此我们需要使用ruby筛选器提取该地址)。。。总而言之,我不确定我是否会在生产中使用这样的东西,因为它可能会疯狂地消耗内存(因为每个ip地址的表)


您可能可以编写一个更智能的自定义筛选器,使用类似趋势算法的方法来查找计数趋势更高的IP地址。

这是一个非常棒/完整的回答!由于我需要这个用于生产应用程序,对于由同一IP的大量访问触发的报警系统,您有什么建议?它也可能是Logstash之外的其他工具。
filter {
  metrics {
    meter =>  "%{ip}"
    add_tag =>  ["metric"]
  }
  ruby { code => '
    ip = nil
    if event["tags"].include? "metric"
        event.to_hash.each do |key,value|
            if key.end_with?(".rate_5m") and value > 0.2
                ip = key[0..-9]
            end
        end
    end
    if ip
      event["ip"] = ip
      event["tags"] = ["alert"]
    end
    '
  }
}

output {
  if "alert" in [tags] {
    email { ... }
  }
}