regex 구문 분석기를 사용하면 수집된 데이터에 대해 몇 가지 정규식을 사용할 수 있습니다.

vRealize Log Insight 에이전트는 Perl 구문에 해당하는 C++ Boost 라이브러리 정규식을 사용합니다. regex 구문 분석기는 명명된 캡처 그룹이 포함된 정규식을 지정하는 방법으로 정의할 수 있습니다. 예: (?<field_1>\d{4})[-](?<field_2>\d{4})[-](?<field_3>\d{4})[-](?<field_4>\d{4})

그룹에 지정된 이름(예: field_1, field_2, field_3field_4)은 해당하는 추출된 필드의 이름으로 사용됩니다. 이름에 대한 요구 사항은 다음과 같습니다.
  • 정규식 패턴에 지정하는 이름은 vRealize Log Insight의 올바른 필드 이름이어야 합니다.
  • 이름에는 영숫자와 밑줄("_") 문자만 포함할 수 있습니다.
  • 이름은 숫자로 시작할 수 없습니다.

유효하지 않은 이름이 제공된 경우 구성에 실패합니다.

정규식 구문 분석기 옵션

regex 구문 분석기의 유일한 필수 옵션은 format 옵션입니다.

debug 옵션은 추가적인 디버깅 정보가 필요할 때 사용할 수 있습니다.

구성

regex 구문 분석기를 생성하려면 regexbase_parser로 사용하고 형식 옵션을 제공합니다.

정규식 구성 예

다음 예는 1234-5678-9123-4567을 분석하는 데 사용할 수 있습니다.

[parser|regex_parser]
base_parser=regex
format=(?<tag1>\d{4})[-](?<tag2>\d{4})[-](?<tag3>\d{4})[-](?<tag4>\d{4})
[filelog|some_info]
directory=D:\Logs
include=*.txt
parser=regex_parser

결과는 다음과 같이 표시됩니다.

tag1=1234
tag2=5678
tag3=9123
tag4=4567

regex 구문 분석기를 사용하여 Apache 로그를 구문 분석하려면 Apache 로그에 사용할 특정 regex 형식을 제공해야 합니다.

[parser|regex_parser]
base_parser=regex
format=(?<remote_host>.*) (?<remote_log_name>.*) (?<remote_auth_user>.*) \[(?<log_timestamp>.*)\] "(?<request>.*)" (?<status_code>.*) (?<response_size>.*)

결과는 다음과 같이 표시됩니다.

127.0.0.1 - admin [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326
remote_host=127.0.0.1
remote_log_name=-
remote_auth_user=admin
log_timestamp=10/Oct/2000:13:55:36 -0700
request=GET /apache_pb.gif HTTP/1.0
status_code=200
response_size=2326
다음 코드는 Apache 로그를 구문 분석하는 다른 예를 보여 줍니다.
[parser|regex_parser]
base_parser=regex
format=(?<remote_host>.* (?<remote_log_name>.*)) (?<remote_auth_user>.*) \[(?<log_timestamp>.*)\] "(?<request>.* (?<resource>.*) (?<protocol>.*))" (?<status_code>.*) (?<response_size>.*)
127.0.0.1 unknown - [17/Nov/2015:15:17:54 +0400] \"GET /index.php HTTP/1.1\" 200 4868
remote_host=127.0.0.1 unknown
remote_log_name=unknown
remote_auth_user=-
log_timestamp=17/Nov/2015:15:17:54 +0400
request=GET /index.php HTTP/1.1
resource=/index.php
protocol=HTTP/1.1
status_code=200
response_size=4868

성능 고려 사항

regex 구문 분석기는 CLF 구문 분석기 같은 다른 구문 분석기에 비해 리소스를 더 많이 사용합니다. 다른 구문 분석기를 사용하여 로그를 구문 분석할 수 있는 경우에는 해당 구문 분석기를 regex 구문 분석기 대신 사용하여 성능을 개선하는 방법을 고려해 보십시오.

사용할 수 있는 다른 구문 분석기가 없어 regex 구문 분석기를 사용해야 하는 경우에는 형식을 최대한 명확하게 정의하십시오. 다음 예에서는 더 나은 성능을 제공하는 구성을 보여 줍니다. 이 예에서는 숫자 값이 있는 필드를 지정합니다.
(?<remote_host>\d+.\d+.\d+.\d+) (?<remote_log_name>.*) (?<remote_auth_user>.*) \[(?<log_timestamp>.*)\] "(?<request>.*)" (?<status_code>\d+) (?<response_size>\d+)