Text 기반 event 를 감지하기 위한, TextEvent 모니터링 등록 방법에 대한 안내 문서입니다. 수집 대상인 Client 에 수집기인 fleuntd를 설치하고 설정하는 방법과 ZMC 에서 해당 이벤트 알림을 등록하는 방법을 안내합니다.
Instructions
다음의 절차로 진행합니다.
Support Portal 을 통한 TextEvent 모니터링 사용 신청
Client 에 수집기 fluentd 설치
TextEvent 수집을 위한 fleuntd 설정 파일 생성
서비스 시작
ZMC 에 alert 등록
1. Support Portal 을 통한 TextEvent 모니터링 사용 신청
TextEvent 모니터링의 경우 별도로 provisioning 을 해야 합니다. 그렇기에 https://support.skdt.co.kr 을 통해 TextEvent 의 사용을 희망하시는 org 이름을 기재하여 요청해 주셔야 합니다.
2. Client 에 수집기 fluentd 설치
각 os 의 환경에 맞도록 fluentd 를 설치합니다. Private network 에서는 internet 이 연결된 서버에서 설치 파일을 다운로드한 후, 해당 파일을 업로드하여 설치합니다.
- Linux
# fluentd 설치 (default path : /opt/td-agent) $ curl -L https://toolbelt.treasuredata.com/sh/install-redhat-td-agent3.sh | sh # 필수 plugin 설치 $ /opt/td-agent/embedded/bin/fluent-gem install fluent-plugin-grafana-loki -v 1.2.12
- Windows
# fluentd 설치 파일 다운로드 (defautl path : C:\opt\td-agent) http://packages.treasuredata.com.s3.amazonaws.com/3/windows/td-agent-3.7.1-0-x64.msi해당 파일을 다운로드 후 설치 # 필수 plugin 설치 PS> C:\opt\td-agent\embedded\bin\fluent-gem install fluent-plugin-grafana-loki -v 1.2.12 # [옵션] windows eventlog 용 plugin 설치 PS> C:\opt\td-agent\embedded\bin\fluent-gem install fluent-plugin-windows-eventlog -v 0.6.0
Private Network 에서 설치를 위한 다운로드
public network 에서 설치 파일을 다운로드한 후,
private network 의 설치 대상 서버에 파일을 업로드하여 설치합니다
- Linux
### 설치 파일 다운로드 ## RHEL 8 $ curl http://packages.treasuredata.com.s3.amazonaws.com/3/redhat/8/x86_64/td-agent-3.7.1-0.el8.x86_64.rpm -o td-agent-3.7.1.0.el8.x86_64.rpm ## RHEL 7 $ curl http://packages.treasuredata.com.s3.amazonaws.com/3/redhat/7/x86_64/td-agent-3.7.1-0.el7.x86_64.rpm -o td-agent-3.7.1-0.el7.x86_64.rpm ## RHEL 6 $ curl http://packages.treasuredata.com.s3.amazonaws.com/3/redhat/6/x86_64/td-agent-3.7.1-0.el6.x86_64.rpm -o td-agent-3.7.1-0.el6.x86_64.rpm ### 다운로드한 파일을 private network 의 설치 대상 서버에 업로드한 후 진행 ### 설치 ## RHEL 8 $ sudo yum makecache fast $ sudo yum install -y td-agent-3.7.1-0.el8.x86_64.rpm --nogpgcheck ## RHEL 7 $ sudo yum makecache fast $ sudo yum install -y td-agent-3.7.1-0.el7.x86_64.rpm --nogpgcheck ## RHEL 6 $ sudo yum makecache fast $ sudo yum install -y td-agent-3.7.1-0.el6.x86_64.rpm --nogpgcheck
- Windows
### 설치 파일 다운로드 PS> curl http://packages.treasuredata.com.s3.amazonaws.com/3/windows/td-agent-3.7.1-0-x64.msi -o td-agent-3.7.1-0-x64.msi ## [opt] windows event 감시 용 파일 $ curl https://rubygems.org/downloads/fluent-plugin-windows-eventlog-0.6.0.gem -o fluent-plugin-windows-eventlog-0.6.0.gem ### 다운로드한 파일을 private network 의 설치 대상 서버에 업로드한 후 진행 ### msi 설치 ### [opt] windows event 감시 용 plugin 설치 PS> C:\opt\td-agent\embedded\bin\fluent-gem install fluent-plugin-windows-eventlog-0.6.0.gem
3. TextEvent 수집을 위한 fluentd 설정 파일 생성
다음은 주로 사용하는 샘플을 설정해 둔 것으로, 각 사용자의 환경에 맞도록 변경하실 때 참고하시기를 바랍니다.
기본적인 설정파일의 구조
Input -> filter 1 -> ... -> filter N -> Output
Input
은<source>
지시어(directive)에서 설정한대로 유입된 data stream 이, pipeline 으로Output
인<match>
지시어까지 동작합니다.
tag
tag
라는 내부 제어 pattern 을 통해 해당 pipeline 에서 data stream 의 방향을 제어할 수 있습니다.tag
는.
으로 구분한 문자열입니다.
e.g. myapp.access.type1tag
는<source>
지시어 내부에서 선언하고,<filter>
,<match>
등 각각의 지시어에서 분기로써 선언해주면 됩니다.
e.g.tag
이름을myapp.access.type1
이라고 가정하면,<filter myapp.access.type1>
,<match myapp.**>
등으로 선언하여 분기할 수 있습니다.
Wildcards and Expansions
*
는tag
의 한 부분을 의미함.
e.g.a.*
는a.b
라는tag
는 포함하지만,a
나a.b.c
는 포함하지 않음.**
는tag
에서 0… 의 regular expression 표현의 의미임.
e.g.a.**
는a
,a.b
,a.b.c
모두를 포함함.기타 자세한 원리는 [링크] 참고
ZMON 에서의 형식
<match>
로 제공되는 필수 data record
구조는 다음과 같습니다.
hostname # OS 의 hosts 파일 내 저장된 hostname pattern # "line append" 나 특정 문자열의 pattern target # 감시 대상 파일의 절대경로 count # 해당 event 가 발생된 수 log # 발생된 text label_tag # ZMON 에서 데이터 구분 단위로, 각 target 마다 unique 한 값 설정
Sample 구조 설정
아래 sample 을 복사해서 사용하실 때에는 다음을 유념해 주세요.
영문 os 의 경우 # 로 시작되는 주석 라인은 삭제를 하셔야 합니다.
~~ 로 둘러쌓인 부분은 각 환경에 맞게 수정이 필요한 부분입니다. 실제로 ~~ 의 기호가 쓰이는 설정은 없으므로, ~~ 는 삭제를 하셔야 합니다.
##### Guide 1) 특정 파일에 대한 line append 로 수집하는 설정 <source> @type tail ##### 로그 감시 대상 파일 절대 경로 path ~~C:/opt/td-agent/lineappend.txt~~ path_key trailed_path ##### pos_file : 로그 감시 대상 파일의 offset 저장 ##### pos_file 파일이 지워지고 새 파일이 생성되면 처음부터 읽게 됨. ##### 단, 각 <source> 마다 pos_file 은 달라야 함. pos_file ~~C:/opt/td-agent/offset.pos~~ tag ~~sample.lineappend.1~~ <parse> ##### @type none 으로 설정할 경우, 모든 log 가 key : message 의 value 로 들어가게 됨. @type none </parse> </source> ##### lineappend filter <filter ~~sample.lineappend.**~~> @type record_transformer <record> hostname "#{Socket.gethostname}" pattern "line append" target ${record["trailed_path"]} count 1 log ${record["message"]} label_tag "${tag}" </record> renew_record true keep_keys label_tag, hostname, pattern, target, count, log </filter> <match ~~sample.**~~> @type loki url ~~https://aaa-loki.zmon.cloud~~ line_format json <label> label_tag </label> <buffer> flush_interval 10s flush_at_shutdown true </buffer> </match>
##### Guide 2) 특정 파일에서 parsing 해서 원하는 형태로 수집하는 설정 <source> @type tail ##### 로그 감시 대상 파일 절대 경로 path ~~C:/opt/td-agent/test.txt~~ path_key trailed_path ##### pos_file : 로그 감시 대상 파일의 offset 저장 ##### pos_file 파일이 지워지고 새 파일이 생성되면 처음부터 읽게 됨. ##### 단, 각 <source> 마다 pos_file 은 달라야 함. pos_file ~~C:/opt/td-agent/offset.pos~~ tag ~~sample.parse.1~~ <parse> @type regexp expression /~~\[(?<pattern>[^\]]*)\]:\[(?<svc_name>[^\]]*)\]:\[(?<bbb>[^\]]*)\]:\[(?<ccc>[^\]]*)\]~~/ </parse> </source> ##### parse log filter <filter ~~sample.parse.**~~> @type record_transformer <record> hostname "#{Socket.gethostname}" pattern ~~${record["pattern"]}~~ target ${record["trailed_path"]} count 1 log ~~${record["aaa"]} ${record["bbb"]} ${record["ccc"]}~~ label_tag "${tag}" </record> renew_record true keep_keys label_tag, hostname, pattern, target, count, log </filter> <match ~~sample.**~~> @type loki url ~~https://aaa-loki.zmon.cloud~~ line_format json <label> label_tag </label> <buffer> flush_interval 10s flush_at_shutdown true </buffer> </match>
##### Guide 3) 특정 파일에서 특정 pattern 을 수집하는 설정 <source> @type tail ##### 로그 감시 대상 파일 절대 경로 path ~~C:/opt/td-agent/test.txt~~ path_key trailed_path ##### pos_file : 로그 감시 대상 파일의 offset 저장 ##### pos_file 파일이 지워지고 새 파일이 생성되면 처음부터 읽게 됨. ##### 단, 각 <source> 마다 pos_file 은 달라야 함. pos_file ~~C:/opt/td-agent/offset.pos~~ tag ~~sample.parse.1~~ <parse> @type regexp expression /~~\[(?<pattern>[^\]]*)\]:\[(?<svc_name>[^\]]*)\]:\[(?<bbb>[^\]]*)\]:\[(?<ccc>[^\]]*)\]~~/ </parse> </source> ##### <source> 에서 parsing 한 <pattern> 과 <svc_name> 을 가지고 filter 사용 ##### <pattern> 의 값이 "reg_exp" 이고 ##### <svc_name> 이 "not_this_type" 아닌 것만 다음으로 넘어감. <filter ~~sample.parse.**~~> @type grep <regexp> key ~~pattern~~ pattern /~~reg_exp~~/ </regexp> <exclude> key ~~svc_name~~ pattern /~~not_this_type~~/ </exclude> </filter> ##### parse log filter <filter ~~sample.parse.**~~> @type record_transformer <record> hostname "#{Socket.gethostname}" pattern ~~${record["pattern"]}~~ target ${record["trailed_path"]} count 1 log ~~${record["aaa"]} ${record["bbb"]} ${record["ccc"]}~~ label_tag "${tag}" </record> renew_record true keep_keys label_tag, hostname, pattern, target, count, log </filter> <match ~~sample.**~~> @type loki url ~~https://aaa-loki.zmon.cloud~~ line_format json <label> label_tag </label> <buffer> flush_interval 10s flush_at_shutdown true </buffer> </match>
##### Guide 4) windows eventlog 를 수집하는 설정 <source> @type windows_eventlog @id windows_eventlog ##### 필요한 채널을 선택합니다. ##### application, system, security 들을 선택할 수 있으나, system 은 권한에 따라 수집이 안될 수 있습니다. channels ~~application,system,security~~ tag ~~sample.winevt.1~~ <storage> @type local persistent path ~~C:/opt/td-agent/winevt.pos~~ </storage> </source> <filter ~~sample.winevt.**~~> @type record_transformer <record> hostname "#{Socket.gethostname}" pattern ~~${record["channel"]}~~ target ~~"windows eventlog"~~ count 1 ##### 가능한 key ##### channel, record_number, event_id, event_type, event_category, ##### source_name, description log ~~${record["event_type"]}:${record["event_id"]}}:${record["source_name"]}~~ label_tag "${tag}" </record> renew_record true keep_keys label_tag, hostname, pattern, target, count, log </filter> <match ~~sample.**~~> @type loki url ~~https://aaa-loki.zmon.cloud~~ line_format json <label> label_tag </label> <buffer> flush_interval 10s flush_at_shutdown true </buffer> </match>
##### Guide 5-1) Private network 의 수집 대상 서버 설정 방법 <source> @type tail ##### 로그 감시 대상 파일 절대 경로 path ~~C:/opt/td-agent/test.txt~~ path_key trailed_path ##### pos_file : 로그 감시 대상 파일의 offset 저장 ##### pos_file 파일이 지워지고 새 파일이 생성되면 처음부터 읽게 됨. ##### 단, 각 <source> 마다 pos_file 은 달라야 함. pos_file ~~C:/opt/td-agent/offset.pos~~ tag ~~sample.parse.1~~ <parse> @type regexp expression /~~\[(?<pattern>[^\]]*)\]:\[(?<svc_name>[^\]]*)\]:\[(?<bbb>[^\]]*)\]:\[(?<ccc>[^\]]*)\]~~/ </parse> </source> ##### parse log filter <filter ~~sample.parse.**~~> @type record_transformer <record> hostname "#{Socket.gethostname}" pattern ~~${record["pattern"]}~~ target ${record["trailed_path"]} count 1 log ~~${record["aaa"]} ${record["bbb"]} ${record["ccc"]}~~ label_tag "${tag}" </record> renew_record true keep_keys label_tag, hostname, pattern, target, count, log </filter> <match ~~sample.**~~> @type forward @id forward_output send_timeout 10s recover_wait 10s hard_timeout 10s <buffer> flush_interval 10s flush_at_shutdown true </buffer> <server> name ~~GATEWAY 식별을 위한 NAME~~ host ~~GATEWAY IP~~ port ~~GATEWAY PORT~~ </server> </match>
##### Guide 5-2) Private network 의 GATEWAY 서버 설정 방법 <source> @type forward @id forward_input @label @jump port ~~GATEWAY PORT~~ bind 0.0.0.0 </source> <label @jump> <match **> @type loki url ~~http://aaa-loki.zmon.cloud~~ line_format json username ~~인증을 위한 ZMON USERNAME - telegraf 설치와 동일~~ password ~~인증을 위한 ZMON PASSWORD - telegraf 설치와 동일~~ <label> label_tag </label> <buffer> flush_mode interval flush_interval 10s flush_at_shutdown true chunk_limit_size 2M queue_limit_length 8n </buffer> <secondary> @type file ## 전송 실패 를 작성하기 위한 로그 파일 path ~~ C:/opt/td-agent/forward-failed_jump.log~~ </secondary> </match> </label>
Sample 설정
다음은 실제로 사용을 하고 있는 예시 파일입니다. (단, url 의 경우 dummy url 입니다.)
##### example 1) /var/log/messages 의 WARN 문구가 있는 경우만 수집 <source> @type tail path /var/log/messages path_key trailed_path pos_file /opt/td-agent/syslog.pos tag sample.messages.test <parse> @type none </parse> </source> <filter sample.messages.**> @type grep <regexp> key message pattern /WARN/ </regexp> </filter> <filter sample.messages.**> @type record_transformer <record> hostname "#{Socket.gethostname}" pattern "syslog" target ${record["trailed_path"]} count 1 log ${record["message"]} label_tag "${tag}" </record> renew_record true keep_keys label_tag, hostname, pattern, target, count, log </filter> <match sample.messages.**> @type loki url ~~https://aaa-loki.zmon.cloud~~ line_format json <label> label_tag </label> <buffer> flush_interval 10s flush_at_shutdown true </buffer> </match>
##### example 2) windows eventlog 의 application 이벤트 중 event_id 가 999 인 것만 수집 <source> @type windows_eventlog @id windows_eventlog channels application tag sample.winevt.test <storage> @type local persistent path C:/opt/td-agent/winevt.pos </storage> </source> <filter sample.winevt.**> @type grep <regexp> key event_id pattern /999/ </regexp> </filter> <filter sample.winevt.**> @type record_transformer <record> hostname "#{Socket.gethostname}" pattern ${record["channel"]} target "windows eventlog" count 1 log ${record["event_type"]}:${record["event_id"]}}:${record["source_name"]} label_tag "${tag}" </record> renew_record true keep_keys label_tag, hostname, pattern, target, count, log </filter> <match sample.**> @type loki url ~~https://aaa-loki.zmon.cloud~~ line_format json <label> label_tag </label> <buffer> flush_interval 10s flush_at_shutdown true </buffer> </match>
4. 서비스 시작
linux
linux 의 경우 설치 시 td-agent.service 로 기본 등록이 됩니다 (systemd 의 경우). 이 때 configuration 파일의 위치는 /etc/td-agent/td-agent.conf
를 기본 경로로 갖게 되며, log 파일의 위치는 /var/log/td-agent/td-agent.log
가 기본 경로로 됩니다.
# systemd (/etc/systemd/system/td-agent.service) $ sudo systemctl start/stop/status/restart td-agent.service # init.d (/etc/init.d/td-agent) $ sudo /etc/init.d/td-agent start/stop/status/restart
windows
windows의 경우 직접 서비스 및 config 파일의 위치 및 log 파일의 위치를 서비스로 등록할 수 있습니다. 다음의 예시에서는 configuration 파일의 위치는 C:/opt/td-agent/windows-svc.conf
로, log 파일의 위치는 C:/opt/td-agent/td-agent.log
로 설정하였습니다.
PS> fluentd --reg-winsvc i ## fluentd --reg-winsvc-fluentdopt '-c {config 파일 절대 경로} -o {log 파일 절대 경로}' ps> fluentd --reg-winsvc-fluentdopt '-c C:/opt/td-agent/windows-svc.conf -o C:/opt/td-agent/td-agent.log'
5. ZMC 에 alert 등록
기본적으로 ZMC 의 rule 을 등록하는 방법은 별도로 제공되는 다음 [link] 를 참고해주시기 바랍니다.
linux rule 등록 : SERVER-Linux-Text Event
windows rule 등록 : SERVER-Windows-Text Event
[공통] 세부 등록
Metric : rule 을 구분할 수 있는 이름으로 수정이 가능합니다.
Target : config 파일 내의
path
에 해당하는 값을 정확하게 입력해주시면 됩니다. (대소문자 및\
,/
구분 등)Status Condition : 현재는 Count 값이 1 이상일 때에만 발생되도록 설정이 가능합니다.
Level :
경고 (P1)
,주의 (P5)
의 값으로 ZCARE 의 전파 단계를 구분합니다.
Opsgenie 전파 단계
P1 - Critical -경고
P2 - High
P3 - Moderate
P4 - Low
P5 - Informational - 주의
Message : 빈 값일 경우 config 파일의
Log
에 해당하는 데이터가 전송이 되며, 특정 값을 입력하실 경우 입력한 값이 전송됩니다.
Related articles
text 의 수집은 잘못 설정하실 경우 많은 network traffic 및 저장공간을 차지하게 됩니다. 그러므로 필요에 맞게 정확한 fluentd 의 설정을 위해 다음의 정보를 통해 정확히 원하시는 text만 수집할 수 있도록 설정하시기를 권고합니다.
fluentd official document URL (영문) [LINK]
ZMC 사용 방법 guide URL [https://support.skdt.co.kr/support/solutions/articles/42000075361 ]