Logstash » История » Версия 6
Константин Пильник, 2022-11-29 18:35
1 | 1 | Константин Пильник | h1. Logstash |
---|---|---|---|
2 | |||
3 | h2. разбираем лог syslog |
||
4 | |||
5 | 5 | Константин Пильник | h4. rsyslog |
6 | |||
7 | <pre><code class="bash"> |
||
8 | ~# cat /etc/rsyslog.d/remote.conf |
||
9 | # udp |
||
10 | *.* @127.0.0.1:500 |
||
11 | 6 | Константин Пильник | # tcp |
12 | #*.* @@127.0.0.1:500 |
||
13 | 5 | Константин Пильник | </code></pre> |
14 | |||
15 | 1 | Константин Пильник | {{collapse(logstash.conf) |
16 | 4 | Константин Пильник | <pre><code class="php"> |
17 | 1 | Константин Пильник | input { |
18 | file { |
||
19 | type => "message" |
||
20 | path => [ "/var/log/messages" ] |
||
21 | start_position => "end" |
||
22 | stat_interval => 1 |
||
23 | discover_interval => 3 |
||
24 | } |
||
25 | 5 | Константин Пильник | # production |
26 | # udp { |
||
27 | # port => 500 |
||
28 | # type => syslog |
||
29 | # } |
||
30 | 1 | Константин Пильник | } |
31 | |||
32 | filter { |
||
33 | if [type] == "message" { |
||
34 | grok { |
||
35 | match => { "message" => "%{SYSLOGTIMESTAMP:syslog_timestamp} %{SYSLOGHOST:syslog_hostname} %{DATA:syslog_program}(?:\[%{POSINT:syslog_pid}\])?:\s+%{GREEDYDATA:syslog_message}" } |
||
36 | } |
||
37 | date { |
||
38 | match => [ "syslog_timestamp", "MMM d HH:mm:ss", "MMM dd HH:mm:ss" ] |
||
39 | } |
||
40 | } |
||
41 | } |
||
42 | |||
43 | output { |
||
44 | stdout {} |
||
45 | 5 | Константин Пильник | # production |
46 | # elasticsearch { |
||
47 | # hosts => ["elasticsearch:9200"] |
||
48 | # index => "%{[type]}-%{+YYYY.MM.dd}" |
||
49 | # user => "${ELASTIC_USERNAME}" |
||
50 | # password => "${ELASTIC_PASSWORD}" |
||
51 | # } |
||
52 | 1 | Константин Пильник | } |
53 | 3 | Константин Пильник | </code></pre> |
54 | 1 | Константин Пильник | }} |
55 | |||
56 | h2. разбираем лог nginx из файловой системы |
||
57 | |||
58 | {{collapse(nginx.conf) |
||
59 | <pre> |
||
60 | log_format json_combined escape=json |
||
61 | '{' |
||
62 | '"time_local":"$time_local",' |
||
63 | '"remote_addr":"$remote_addr",' |
||
64 | '"remote_user":"$remote_user",' |
||
65 | '"request":"$request",' |
||
66 | '"status": "$status",' |
||
67 | '"body_bytes_sent":"$body_bytes_sent",' |
||
68 | '"request_time":"$request_time",' |
||
69 | '"http_referrer":"$http_referer",' |
||
70 | '"http_user_agent":"$http_user_agent"' |
||
71 | '}'; |
||
72 | access_log /var/log/nginx/access.log json_combined; |
||
73 | </pre> |
||
74 | }} |
||
75 | {{collapse(logstash.conf) |
||
76 | 4 | Константин Пильник | <pre><code class="php"> |
77 | 1 | Константин Пильник | input { |
78 | file { |
||
79 | type => "nginx" |
||
80 | path => [ "/var/log/nginx/access.log" ] |
||
81 | start_position => "end" |
||
82 | } |
||
83 | } |
||
84 | |||
85 | filter { |
||
86 | if [type] == "nginx" { |
||
87 | json { |
||
88 | source => "message" |
||
89 | } |
||
90 | } |
||
91 | } |
||
92 | |||
93 | output { |
||
94 | stdout {} |
||
95 | } |
||
96 | </code></pre> |
||
97 | }} |
||
98 | |||
99 | h2. разбираем лог nginx из syslog |
||
100 | |||
101 | {{collapse(nginx.conf) |
||
102 | <pre> |
||
103 | log_format json_combined escape=json |
||
104 | '{' |
||
105 | '"time_local":"$time_local",' |
||
106 | '"remote_addr":"$remote_addr",' |
||
107 | '"remote_user":"$remote_user",' |
||
108 | '"request":"$request",' |
||
109 | '"status": "$status",' |
||
110 | '"body_bytes_sent":"$body_bytes_sent",' |
||
111 | '"request_time":"$request_time",' |
||
112 | '"http_referrer":"$http_referer",' |
||
113 | '"http_user_agent":"$http_user_agent"' |
||
114 | '}'; |
||
115 | access_log syslog:server=unix:/dev/log,tag=nginx,severity=error,nohostname json_combined; |
||
116 | </pre> |
||
117 | }} |
||
118 | {{collapse(logstash.conf) |
||
119 | 4 | Константин Пильник | <pre><code class="php"> |
120 | 1 | Константин Пильник | input { |
121 | file { |
||
122 | type => "syslog" |
||
123 | path => [ "/var/log/syslog" ] |
||
124 | start_position => "end" |
||
125 | } |
||
126 | } |
||
127 | |||
128 | filter { |
||
129 | if [type] == "syslog" { |
||
130 | grok { |
||
131 | match => { "message" => "%{SYSLOGTIMESTAMP:syslog_timestamp} %{SYSLOGHOST:syslog_hostname} %{DATA:syslog_program}(?:\[%{POSINT:syslog_pid}\])?:\s+%{GREEDYDATA:syslog_message}" } |
||
132 | } |
||
133 | json { |
||
134 | source => "[syslog_message]" |
||
135 | target => "[nginx_message]" |
||
136 | } |
||
137 | } |
||
138 | } |
||
139 | |||
140 | output { |
||
141 | stdout {} |
||
142 | } |
||
143 | 3 | Константин Пильник | </code></pre> |
144 | 1 | Константин Пильник | }} |
145 | |||
146 | |||
147 | 2 | Константин Пильник | h3. ссылки |
148 | |||
149 | 1 | Константин Пильник | https://www.elastic.co/guide/en/logstash/current/input-plugins.html |
150 | https://www.elastic.co/guide/en/logstash/current/filter-plugins.html |
||
151 | https://www.elastic.co/guide/en/logstash/current/output-plugins.html |