首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ELK中的datetime解析

ELK中的datetime解析
EN

Stack Overflow用户
提问于 2016-03-17 12:20:26
回答 1查看 628关注 0票数 0

我正在尝试使用ELK堆栈解析日志。下面是我的样本日志

代码语言:javascript
复制
2015-12-11 12:05:24+0530 [process] INFO: process 0.24.5 started 

我正在使用下面的grok

代码语言:javascript
复制
grok{
    match => {"message" => "(?m)%{TIMESTAMP_ISO8601:processdate}\s+\[%{WORD:name}\]\s+%{LOGLEVEL:loglevel}"}
    }

我的弹性搜索映射是

代码语言:javascript
复制
{
    "properties": {
        "processdate":{
            "type":   "date",
            "format" : "yyyy-MM-dd HH:mm:ss+SSSS"
        },
        "name":{"type" : "string"},
        "loglevel":{"type" : "string"},
    }
}

但是当我加载到弹性搜索中时,

代码语言:javascript
复制
 "error"=>{"type"=>"mapper_parsing_exception", "reason"=>"failed to parse [processdate]", "caused_by"=>{"type"=>"illegal_argument_exception", "reason"=>"Invalid format: \"2015-12-11 12:05:39+0530\" is malformed at \" 12:05:39+0530\""}}}}, :level=>:warn}

如何将其修改为适当的数据格式?我在弹性搜索中添加了正确的日期格式。

更新:本地主机:9200/log

代码语言:javascript
复制
{"log":{"aliases":{},"mappings":{"filelog":{"properties":{"processdate":{"type":"date","format":"yyyy-MM-dd' 'HH:mm:ssZ"},"loglevel":{"type":"string"},"name":{"type":"string"}}}},"settings":{"index":{"creation_date":"1458218007417","number_of_shards":"5","number_of_replicas":"1","uuid":"_7ffuioZS7eGBbFCDMk7cw","version":{"created":"2020099"}}},"warmers":{}}}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-03-17 14:08:07

所得到的错误意味着您的日期格式是错误的。像这样修正您的日期格式,即在结束时使用Z (时区)而不是+SSSS (秒的分数):

代码语言:javascript
复制
{
    "properties": {
        "processdate":{
            "type":   "date",
            "format" : "yyyy-MM-dd HH:mm:ssZ"
        },
        "name":{"type" : "string"},
        "loglevel":{"type" : "string"}
    }
}

此外,根据我们之前的交换,您的elasticsearch输出插件缺少document_type设置,应该像这样配置,以便使用自定义filelog映射类型(否则将使用默认的logs类型,而您的自定义映射类型不会启动):

代码语言:javascript
复制
output {
    elasticsearch {
        hosts => ["172.16.2.204:9200"] 
        index => "log" 
        document_type => "filelog" 
    } 
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36060412

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档