Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用google fluend解析从nginx日志到stackdriver的错误消息_Nginx_Google Cloud Platform_Fluentd_Stackdriver - Fatal编程技术网

使用google fluend解析从nginx日志到stackdriver的错误消息

使用google fluend解析从nginx日志到stackdriver的错误消息,nginx,google-cloud-platform,fluentd,stackdriver,Nginx,Google Cloud Platform,Fluentd,Stackdriver,我们试图通过解析nginx error来设置警报,我们只需要具有[error]级别的消息。([error]27720#27720:*29765923规则禁止访问,客户端:blalbablab)。主要目标是不发送我们不需要的gcp stackdriver日志(减少日志存储空间)。所以我创建了带有日志流的GoogleFluend,但我一直在解析错误消息。这是我的配置 <source> @type tail tag nginx-error path /var/log/nginx

我们试图通过解析nginx error来设置警报,我们只需要具有[error]级别的消息。(
[error]27720#27720:*29765923规则禁止访问,客户端:blalbablab
)。主要目标是不发送我们不需要的gcp stackdriver日志(减少日志存储空间)。所以我创建了带有日志流的GoogleFluend,但我一直在解析错误消息。这是我的配置

<source>
  @type tail
  tag nginx-error
  path /var/log/nginx/error.log
  format multiline
  format_firstline /^\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2} \[\w+\] (?<pid>\d+).(?<tid>\d+): /
  format1 /^(?<time>\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}) \[(?<log_level>\w+)\] (?<pid>\d+).(?<tid>\d+): (?<message>$      multiline_flush_interval 3s
  #<parse>
    #@type regexp
    #expression (\s\[error+\])
    #time_key name
    #types id:integer
  #</parse>
</source>

@型尾
标记nginx错误
路径/var/log/nginx/error.log
格式化多行
格式{u firstline/^\d{4}/\d{2}/\d{2}:\d{2}:\d{2}\[\w+\](?\d+)(?\d+):/
format1/^(?\d{4}/\d{2}/\d{2}:\d{2}:\d{2})\[(?\w+)\](?\d+)(?\d+):(?$multiline\u flush\u interval 3s
#
#@类型regexp
#表达式(\s\[错误+\])
#时间键名称
#类型id:整数
#

在这种情况下,使用带regexp规则的parse正确吗?请帮我解决这个问题。

经过一些测试,我得到了一个可用的版本

 <source>
  @type tail
  format /^(?<message>.*\[error\].*)$/
  path /var/log/nginx/error.log
  pos_file /var/lib/google-fluentd/pos/nginx-error.pos
  read_from_head true
  tag nginx-error
</source>

@型尾
格式/^(?.*\[错误\].*)$/
路径/var/log/nginx/error.log
pos_文件/var/lib/google fluentd/pos/nginx-error.pos
从你的头上读出来是真的
标记nginx错误

您的完整用例是什么?您是在进一步处理日志还是只是将它们转发到某个输出目标?如果目的只是转发
[错误]
日志,那么您可以简单地使用过滤器进行此操作。但是,正如您提到的解析,这听起来好像还有更多。另外,请添加两个完整的示例日志。