logstash读取日志文件到odps(maxcompute)

1.首先,了解logstash的配置文件构成。

原文链接:https://blog.csdn.net/sxf_123456/article/details/77773953

logstash 条件判断语句
使用条件来决定filter和output处理特定的事件。logstash条件类似于编程语言。条件支持if、else if、else语句,可以嵌套。 
比较操作有: 
相等: ==, !=, <, >, <=, >= 
正则: =~(匹配正则), !~(不匹配正则) 
包含: in(包含), not in(不包含) 
布尔操作: 
and(与), or(或), nand(非与), xor(非或) 
一元运算符: 
!(取反) 
()(复合表达式), !()(对复合表达式结果取反) 

2.下载有logstash-output-maxcompute插件的Logstash实例。解压安装到/usr/local/logstash-7.8.0

https://odps-repo.oss-cn-hangzhou.aliyuncs.com/streaming-tunnel/logstash-7.8.0-with-mc-output.tar.gz?spm=a2c4g.11186623.2.13.329b63c1xEwGnN&file=logstash-7.8.0-with-mc-output.tar.gz

3./usr/local/logstash-7.8.0/config/logstash-odps.conf

input {
    file {
        path => "/opt/cloudflare-cn/logs/*.log"
        type => "cloudflare-cn-log"
        start_position => "beginning"
        codec => json   #转换成json
        }
}
filter {
      if [ClientRequestHost] !~ "xxxx\..*\.xxxxxxx.cn" {   #正则匹配,不匹配的丢弃这条数据,(其中\.匹配.)
        drop {}
      }
    }

output {
        maxctunnel{
                aliyun_access_id => "xxxxxxxx"
                aliyun_access_key => "xxxxxxxxxxxxxxxx"
                aliyun_mc_endpoint => "http://service.cn-hangzhou.maxcompute.aliyun.com/api"
                project => "xxxxxx"
                table => "xxxxxxxx"
                partition => "pt=$<@timestamp.strftime('%F')>"   #@timestamp为logstash自动生成的时间戳,当成分区
                #下面这些字段与转成json里的字段名对应相同,odps的表里必须存在所有字段,顺序就是下面的顺序
                value_fields => ["CacheCacheStatus", "CacheResponseBytes", "CacheResponseStatus", "CacheTieredFill", "ClientASN", "ClientCountry", "ClientDeviceType", "ClientIP", "ClientIPClass", "ClientRequestBytes", "ClientRequestHost", "ClientRequestMethod", "ClientRequestPath", "ClientRequestProtocol", "ClientRequestURI", "ClientRequestUserAgent", "ClientSSLCipher", "ClientSSLProtocol", "ClientSrcPort", "EdgeColoCode", "EdgeColoID", "EdgeEndTimestamp", "EdgePathingOp", "EdgePathingSrc", "EdgePathingStatus", "EdgeRateLimitID", "EdgeRequestHost", "EdgeResponseBytes", "EdgeResponseCompressionRatio", "EdgeResponseContentType", "EdgeResponseStatus", "EdgeServerIP", "EdgeStartTimestamp", "FirewallMatchesActions", "FirewallMatchesRuleIDs", "FirewallMatchesSources", "OriginIP", "OriginResponseBytes", "OriginResponseStatus", "OriginResponseTime", "OriginSSLProtocol", "ParentRayID", "RayID", "SecurityLevel", "WAFAction", "WAFFlags", "WAFProfile", "WorkerCPUTime", "WorkerStatus", "WorkerSubrequest", "WorkerSubrequestCount", "ZoneID"]
}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值