【问题标题】:What is the grok pattern for this jenkins log?这个詹金斯日志的 grok 模式是什么?
【发布时间】:2020-01-24 04:58:30
【问题描述】:

你能帮我了解一下这个 jenkins 示例数据或日志的 grok 模式吗?日志只有一行。

hudson.slaves.CommandLauncher launch\nSEVERE: Unable to launch the agent for dot-dewsttlas403-ci\njava.io.IOException: Failed to create a temporary file in /opt_shared/iit_slave/jenkins_slave/workspace\n\tat hudson.util.AtomicFileWriter.<init>(AtomicFileWriter.java:144)\n\tat hudson.util.AtomicFileWriter.<init>(AtomicFileWriter.java:109)\n\tat hudson.util.AtomicFileWriter.<init>(AtomicFileWriter.java:84)\n\tat hudson.util.AtomicFileWriter.<init>(AtomicFileWriter.java:74)\n\tat hudson.util.TextFile.write(TextFile.java:116)\n\tat jenkins.branch.WorkspaceLocatorImpl$WriteAtomic.invoke(WorkspaceLocatorImpl.java:264)\n\tat jenkins.branch.WorkspaceLocatorImpl$WriteAtomic.invoke(WorkspaceLocatorImpl.java:256)\n\tat hudson.FilePath$FileCallableWrapper.call(FilePath.java:3042)\n\tat hudson.remoting.UserRequest.perform(UserRequest.java:212)\n\tat hudson.remoting.UserRequest.perform(UserRequest.java:54)\n\tat hudson.remoting.Request$2.run(Request.java:369)\n\tat hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)\n\tat java.util.concurrent.FutureTask.run(FutureTask.java:266)\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)\n\tat java.lang.Thread.run(Thread.java:745)\n\tSuppressed: hudson.remoting.Channel$CallSiteStackTrace: Remote call to dot-dewsttlas403-ci\n\t\tat hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1743)\n\t\tat hudson.remoting.UserRequest$ExceptionResponse.retrieve(UserRequest.java:357)\n\t\tat hudson.remoting.Channel.call(Channel.java:957)\n\t\tat hudson.FilePath.act(FilePath.java:1069)\n\t\tat hudson.FilePath.act(FilePath.java:1058)\n\t\tat jenkins.branch.WorkspaceLocatorImpl.save(WorkspaceLocatorImpl.java:254)\n\t\tat jenkins.branch.WorkspaceLocatorImpl.access$500(WorkspaceLocatorImpl.java:80)\n\t\tat jenkins.branch.WorkspaceLocatorImpl$Collector.onOnline(WorkspaceLocatorImpl.java:561)\n\t\tat hudson.slaves.SlaveComputer.setChannel(SlaveComputer.java:697)\n\t\tat hudson.slaves.SlaveComputer.setChannel(SlaveComputer.java:432)\n\t\tat hudson.slaves.CommandLauncher.launch(CommandLauncher.java:154)\n\t\tat hudson.slaves.SlaveComputer$1.call(SlaveComputer.java:294)\n\t\tat jenkins.util.ContextResettingExecutorService$2.call(ContextResettingExecutorService.java:46)\n\t\tat jenkins.security.ImpersonatingExecutorService$2.call(ImpersonatingExecutorService.java:71)\n\t\tat java.util.concurrent.FutureTask.run(Unknown Source)\n\t\tat java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)\n\t\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)\n\t\tat java.lang.Thread.run(Unknown Source)\nCaused by: java.io.IOException: No space left on device\n\tat java.io.UnixFileSystem.createFileExclusively(Native Method)\n\tat java.io.File.createTempFile(File.java:2024)\n\tat hudson.util.AtomicFileWriter.<init>(AtomicFileWriter.java:142)\n\t... 15 more\n

我只对从上述日志中提取以下内容感兴趣。 代理状态代理名称

预期结果:

agent status: Unable
agent name: dot-dewsttlas403-ci

【问题讨论】:

  • 这不是一行。
  • 显然不是一行。但是在应用过滤器后,它是一个标签,比如@message。
  • agent for (?P&lt;agentname&gt;[^ ]+) and agent for (?P&lt;agentname&gt;[^ ]+) and SEVERE: +(?P&lt;status&gt;[^ ]+)
  • @WiktorStribiżew 它对我不起作用。你能说得更具体点吗,或者我可能遗漏了什么。

标签: regex logstash elastic-stack logstash-grok


【解决方案1】:

SEVERE: %{DATA:agent_status} to launch the agent for %{DATA:agent_name}\\n

这应该会给你你感兴趣的结果,但它只有在消息结构相同的情况下才有效。

使用的配置:

input {stdin{}}

filter{
    grok {
        match =>{
            "message" => "SEVERE: %{DATA:agent_status} to launch the agent for %{DATA:agent_name}\\n"
        }
    }
}

output {stdout{codec => json}}

结果:

{
  "host": "MY_COMPUTER",
  "agent_status": "Unable",
  "message": "hudson.slaves.CommandLauncher launch\\nSEVERE: Unable to launch the agent for dot-dewsttlas403-ci\\njava.io.IOException: Failed to create a temporary file in /opt_shared/iit_slave/jenkins_slave/workspace\\n\\tat \r",
  "agent_name": "dot-dewsttlas403-ci",
  "@timestamp": "2020-01-29T16:54:27.256Z",
  "@version": "1"
}

还可以在您下次使用 logstash-grok 时为您提供帮助:

模式的在线测试器: http://grokconstructor.appspot.com/do/match

基本的 grok 模式:https://github.com/logstash-plugins/logstash-patterns-core/blob/master/patterns/grok-patterns

【讨论】:

  • 感谢您的解决方案。我会尝试同样的。我正在使用 Herokuapp grokdebugger grokdebug.herokuapp.com 来测试我的模式。我遇到了文字 /n 和 /t 的问题。
  • 我已经尝试过您的解决方案。当我使用在线 grok 测试器时,它就像一个魅力,但是当我将相同的 grok 模式放入我的 Logstash confit 文件时,它失败了。你能建议我一个将 regex + Oniguruma 混合的解决方案吗?
  • 很奇怪,我刚刚在本地测试过,它工作正常。无论如何,转换我用正则表达式编写的模式:SEVERE: (?&lt;agent_status&gt;.*?) to launch the agent for (?&lt;agent_name&gt;.*?)\\n。我只需要用等效的正则表达式替换 grok 模式。
  • 另一种编写正则表达式的方法:SEVERE: (?&lt;agent_status&gt;.*?) to launch the agent for (?&lt;agent_name&gt;[0-9a-zA-Z-]*)。这次没有\\n,这可能会产生转义字符的问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-12-13
  • 1970-01-01
  • 2013-04-24
  • 2017-07-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多