即使配置正常,在 Windows 上如何调试 Logstash?

Ray*_*Ray 5 windows elasticsearch logstash elastic-stack

我的 Logstash 具有以下配置来导入一些 CSV 文件:

\n\n
input {\n  file {\n    path => [\n        "C:\\Data\\Archive_ATS_L1\\2016-10-08-00-00_to_2016-10-09-00-00\\S2KHistorian\\Historian\\S2KEventMsg_Table.csv",\n        "C:\\Data\\Archive_ATS_L1\\2016-10-09-00-00_to_2016-10-10-00-00\\S2KHistorian\\Historian\\S2KEventMsg_Table.csv",\n        "C:\\Data\\Archive_ATS_L1\\2016-10-10-00-00_to_2016-10-11-00-00\\S2KHistorian\\Historian\\S2KEventMsg_Table.csv",\n        "C:\\Data\\Archive_ATS_L1\\2016-10-11-00-00_to_2016-10-12-00-00\\S2KHistorian\\Historian\\S2KEventMsg_Table.csv",\n        "C:\\Data\\Archive_ATS_L1\\2016-10-12-00-00_to_2016-10-13-00-00\\S2KHistorian\\Historian\\S2KEventMsg_Table.csv",\n        "C:\\Data\\Archive_ATS_L1\\2016-10-13-00-00_to_2016-10-14-00-00\\S2KHistorian\\Historian\\S2KEventMsg_Table.csv",\n        "C:\\Data\\Archive_ATS_L1\\2016-10-14-00-00_to_2016-10-15-00-00\\S2KHistorian\\Historian\\S2KEventMsg_Table.csv"\n    ]\n    start_position => "beginning"    \n  }\n}\nfilter {\n  csv {\n      separator => ","\n      columns => ["MessageCode","SourceGuid","DateTimeGenerated","Code1","Code2","Code3","Code4","LanguageCode", "AlarmSeverity", "Message", "Guid1", "Guid2", "Guid3", "Guid4", "MessageOrigin", "RequestId", "Bool1", "Bool2", "Bool3", "Bool4", "Bool5", "Bool6", "Bool7", "Bool8", "Code5", "Code6", "Bool9", "Bool10", "Bool11", "Code7"]\n  }\n}\noutput {  \n    elasticsearch {\n        action => "index"\n        hosts => "localhost"\n        index => "S2K"\n        workers => 1\n    }\n    stdout {}\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

我使用以下命令行启动logstash:

\n\n
logstash.bat \xe2\x80\x93f ..\\conf\\logstash.conf --verbose\n
Run Code Online (Sandbox Code Playgroud)\n\n

通常我会在控制台中看到正在导入 Elasticsearch 的数据。但这次我得到的只是一行“管道主线已启动”,并且一直如此。

\n\n

如何从logstash检查数据是否已导入?我尝试通过运行以下命令来使用 Elasticsearch:curl http://localhost:9200/_aliases

\n\n

这通常给出索引列表。但我在此配置中拥有的索引(称为 S2K)未列出。

\n\n

我是 ELK 新手,那么如何检查 Logstash 是否正在执行其工作?请注意,我使用的是 Windows 7。

\n

Ant*_*ton 7

要调试logstash,您需要做两件事:在配置中添加stdout,并以正确的方式运行logstash。

第一步:将此配置添加到您的logstashconf文件中(例如:/etc/logstash/conf.d/config.conf)

output {
  stdout {
    codec => rubydebug {
      metadata => true # Here, we will print metadata in console
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

第2步:运行logstash以使用命令查看输出

sudo /usr/share/logstash/bin/logstash  -f /etc/logstash/conf.d/config.conf
Run Code Online (Sandbox Code Playgroud)

你会得到这样的东西:

{
            "log" => {
        "file" => {
            "path" => "***\\spring.log"
        }
    },
        "appName" => "my-service",
      "@metadata" => {
        "ip_address" => "***",
              "type" => "_doc",
              "beat" => "filebeat",
           "version" => "7.12.0"
    },
      "log_level" => "INFO",
     "serverName" => "***",
            "pid" => "6236",
         "thread" => "main",
        "message" => "***",
    "serviceName" => "***",
           "tags" => [
        [0] "beats_input_codec_plain_applied"
    ],
          "input" => {
        "type" => "log"
    },
     "@timestamp" => 2021-01-03T10:22:07.644Z,
       "@version" => "1",
          "class" => "***"
}
Run Code Online (Sandbox Code Playgroud)

最后,调试后你可以像这样运行它sudo systemctl start logstash

希望对您有帮助,这种方法帮助我节省了时间


小智 1

Stdout Ruby Debug 是您的朋友。

这会将所有内容输出到屏幕,因此您需要将屏幕输出推送到文件(底部的示例代码)

https://www.elastic.co/guide/en/logstash/current/plugins-outputs-stdout.html

.conf 文件中输出部分的内容

output { stdout { codec => rubydebug } }
Run Code Online (Sandbox Code Playgroud)

这是如何运行conf并将屏幕输出推送到另一个文件以进行调试的示例。

logstash -r -f yourconfig.conf > debugfile.out
Run Code Online (Sandbox Code Playgroud)

只需将您的 config.conf 和 debugfile.out 更改为您想要的任何名称,并请记住在完成调试后从您的conf文件中删除rubydebug编解码器!

希望这可以帮助