2016-09-01 18 views
-1

"스왑 메모리 부족"이라는 단어가 들어있는 줄을 가져야하는 몇 가지 사용자 정의 파일 로깅을 위해 Logstash를 구현하려고합니다.grok 패턴이 Logstash의 로그 파일에서 특정 단어가있는 행을 가져옵니다.

filter { 
    if [type] == "syslog" { 
    grok { 
     match => { "message" => "%{SYSLOGTIMESTAMP:syslog_timestamp} %{SYSLOGHOST:syslog_hostname} %{DATA:syslog_program}(?:\[%{POSINT:syslog_pid}\])?: %{GREEDYDATA:syslog_message}" } 
     add_field => [ "received_at", "%{@timestamp}" ] 
     add_field => [ "received_from", "%{host}" ] 
    } 
    syslog_pri { } 
    date { 
     match => [ "syslog_timestamp", "MMM d HH:mm:ss", "MMM dd HH:mm:ss" ] 
    } 
    } 
    if [type] == "custom_error" { 
    grok { 
     match => { "message" => "Exception java.lang.OutOfMemoryError: requested %{NUMBER:int} bytes for promotion. Out of swap space?" } 
     add_field => [ "received_at", "%{@timestamp}" ] 
     add_field => [ "received_from", "%{host}" ] 
    } 
    date { 
    match => [ "syslog_timestamp", "MMM d HH:mm:ss", "MMM dd HH:mm:ss" ] 
    } 
} 
} 
: 내가 원하는 라인을 얻을 수있는 내가 로그인하는 데 필요한 사용자 정의 로그 파일에 대한 형 필터 custom_error 만든에서 /etc/logstash/conf.d/10-syslog.conf 파일의 내용은 다음과

하지만 여전히 원하는 결과를 얻지 못하고 필요한 줄과 함께 많은 다른 메시지가 표시되어 로그 메시지를 너무 길게 만듭니다. 로그 파일에서 필요한 줄을 어떻게 만듭니 까?

답변

0

질문이 있으시면 logstash 구성에서 조건부를 사용할 수 있습니다.
설명은 here입니다. 특별히 단어 out of swap memory를 포함하는 라인을 필터링 할 경우

그래서, 당신은 사용할 수 있습니다

if ([message] =~/out of swap memory/) { 
    ... 
    only the lines containing "out of swap memory" will go through this part. 
}