Logstash日志已读取但未推送到elasticsearch

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

我具有以下logstash配置:

input {
  file {
    codec => "json_lines"
    path => ["/etc/logstash/input.log"]
    sincedb_path => "/etc/logstash/dbfile"
    start_position => "beginning"
    ignore_older => "0"
  }
}
output {
   elasticsearch {
      hosts => ["192.168.169.46:9200"]
   }
   stdout {
      codec => rubydebug
   }
}

/etc/logstash/input.log文件由运行中的Java应用程序中的日志填充。日志采用以下json格式(它们以\n字符内联写入):

{
"exception": {
    "exception_class": "java.lang.RuntimeException",
    "exception_message": "Test runtime exception stack: 0",
    "stacktrace": "java.lang.RuntimeException: Test runtime exception stack: 0"
},
"@version": 1,
"source_host": "WS-169-046",
"message": "Test runtime exception stack: 0",
"thread_name": "parallel-1",
"@timestamp": "2019-12-02T16:30:14.084+02:00",
"level": "ERROR",
"logger_name": "nl.hnf.logs.aggregator.demo.LoggingTest",
"aplication-name": "demo-log-aggregation"
}

我还使用elasticsearch API(将请求正文放置在http://192.168.169.46:9200/_template/logstash?pretty处更新了logstash默认模板:]

{
"index_patterns": "logstash-*",
"version": 60002,
"settings": {
    "index.refresh_interval": "5s",
    "number_of_shards": 1
},
"mappings": {
    "dynamic_templates": [
        {
            "message_field": {
                "path_match": "message",
                "match_mapping_type": "string",
                "mapping": {
                    "type": "text",
                    "norms": false
                }
            }
        },
        {
            "string_fields": {
                "match": "*",
                "match_mapping_type": "string",
                "mapping": {
                    "type": "text",
                    "norms": false,
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                }
            }
        }
    ],
    "properties": {
        "@timestamp": {
            "type": "date"
        },
        "@version": {
            "type": "keyword"
        },
        "source_host": {
            "type": "keyword"
        },
        "message": {
            "type": "text"
        },
        "thread_name": {
            "type": "text"
        },
        "level": {
            "type": "keyword"
        },
        "logger_name": {
            "type": "keyword"
        },
        "aplication_name": {
            "type": "keyword"
        },
        "exception": {
            "dynamic": true,
            "properties": {
                "exception_class": {
                    "type": "text"
                },
                "exception_message": {
                    "type": "text"
                },
                "stacktrace": {
                    "type": "text"
                }
            }
        }
    }
}

Elasticsearch回复为"acknowledged": true,我可以看到正在通过API更新模板。现在以debug日志级别启动logstash,我看到输入日志正在读取但没有发送到elasticsearch,尽管索引已创建但始终为空(0个文档):

[2019-12-03T09:30:51,655][DEBUG][logstash.inputs.file     ][custom] Received line {:path=>"/etc/logstash/input.log", :text=>"{\"@version\":1,\"source_host\":\"ubuntu\",\"message\":\"Generating some logs: 65778 - 2019-12-03T09:30:50.775\",\"thread_name\":\"parallel-1\",\"@timestamp\":\"2019-12-03T09:30:50.775+00:00\",\"level\":\"INFO\",\"logger_name\":\"nl.hnf.logs.aggregator.demo.LoggingTest\",\"aplication-name\":\"demo-log-aggregation\"}"}
[2019-12-03T09:30:51,656][DEBUG][filewatch.sincedbcollection][custom] writing sincedb (delta since last write = 1575365451)

此外,elasticsearch日志也处于debug级别,但是我看不到那里的任何错误或任何可以提示我有关问题根源的信息。

你们对为什么不将日志推送到elasticsearch有任何想法或建议吗?

elasticsearch logstash
2个回答
0
投票

在filebeat中,将ignore_older设置为零表示“不检查文件的年代”。对于logstash文件输入,它的意思是“忽略大于零秒的文件”,实际上是“忽略所有内容”。删除它。如果这样做没有帮助,请增加要跟踪的日志级别,并查看filewatch模块对正在监视的文件的说明。


0
投票

[通过使用json编解码器而不是json_lines并删除了start_positionignore_oldersincedb_path解决了该问题>

input {
  file {
    codec => "json"
    path => ["/etc/logstash/input.log"]
  }
}
output {
   elasticsearch {
      hosts => ["192.168.169.46:9200"]
   }
   stdout {
      codec => rubydebug
   }
}

而且json_lines编解码器似乎与文件输入不兼容(\n分隔符,它无法按预期工作)

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