Logstash » История » Версия 7
Константин Пильник, 2022-11-29 18:36
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 | 7 | Константин Пильник | https://www.elastic.co/guide/en/logstash/current/plugins-inputs-syslog.html |
56 | 1 | Константин Пильник | |
57 | h2. разбираем лог nginx из файловой системы |
||
58 | |||
59 | {{collapse(nginx.conf) |
||
60 | <pre> |
||
61 | log_format json_combined escape=json |
||
62 | '{' |
||
63 | '"time_local":"$time_local",' |
||
64 | '"remote_addr":"$remote_addr",' |
||
65 | '"remote_user":"$remote_user",' |
||
66 | '"request":"$request",' |
||
67 | '"status": "$status",' |
||
68 | '"body_bytes_sent":"$body_bytes_sent",' |
||
69 | '"request_time":"$request_time",' |
||
70 | '"http_referrer":"$http_referer",' |
||
71 | '"http_user_agent":"$http_user_agent"' |
||
72 | '}'; |
||
73 | access_log /var/log/nginx/access.log json_combined; |
||
74 | </pre> |
||
75 | }} |
||
76 | {{collapse(logstash.conf) |
||
77 | 4 | Константин Пильник | <pre><code class="php"> |
78 | 1 | Константин Пильник | input { |
79 | file { |
||
80 | type => "nginx" |
||
81 | path => [ "/var/log/nginx/access.log" ] |
||
82 | start_position => "end" |
||
83 | } |
||
84 | } |
||
85 | |||
86 | filter { |
||
87 | if [type] == "nginx" { |
||
88 | json { |
||
89 | source => "message" |
||
90 | } |
||
91 | } |
||
92 | } |
||
93 | |||
94 | output { |
||
95 | stdout {} |
||
96 | } |
||
97 | </code></pre> |
||
98 | }} |
||
99 | |||
100 | h2. разбираем лог nginx из syslog |
||
101 | |||
102 | {{collapse(nginx.conf) |
||
103 | <pre> |
||
104 | log_format json_combined escape=json |
||
105 | '{' |
||
106 | '"time_local":"$time_local",' |
||
107 | '"remote_addr":"$remote_addr",' |
||
108 | '"remote_user":"$remote_user",' |
||
109 | '"request":"$request",' |
||
110 | '"status": "$status",' |
||
111 | '"body_bytes_sent":"$body_bytes_sent",' |
||
112 | '"request_time":"$request_time",' |
||
113 | '"http_referrer":"$http_referer",' |
||
114 | '"http_user_agent":"$http_user_agent"' |
||
115 | '}'; |
||
116 | access_log syslog:server=unix:/dev/log,tag=nginx,severity=error,nohostname json_combined; |
||
117 | </pre> |
||
118 | }} |
||
119 | {{collapse(logstash.conf) |
||
120 | 4 | Константин Пильник | <pre><code class="php"> |
121 | 1 | Константин Пильник | input { |
122 | file { |
||
123 | type => "syslog" |
||
124 | path => [ "/var/log/syslog" ] |
||
125 | start_position => "end" |
||
126 | } |
||
127 | } |
||
128 | |||
129 | filter { |
||
130 | if [type] == "syslog" { |
||
131 | grok { |
||
132 | match => { "message" => "%{SYSLOGTIMESTAMP:syslog_timestamp} %{SYSLOGHOST:syslog_hostname} %{DATA:syslog_program}(?:\[%{POSINT:syslog_pid}\])?:\s+%{GREEDYDATA:syslog_message}" } |
||
133 | } |
||
134 | json { |
||
135 | source => "[syslog_message]" |
||
136 | target => "[nginx_message]" |
||
137 | } |
||
138 | } |
||
139 | } |
||
140 | |||
141 | output { |
||
142 | stdout {} |
||
143 | } |
||
144 | 3 | Константин Пильник | </code></pre> |
145 | 1 | Константин Пильник | }} |
146 | |||
147 | |||
148 | 2 | Константин Пильник | h3. ссылки |
149 | |||
150 | 1 | Константин Пильник | https://www.elastic.co/guide/en/logstash/current/input-plugins.html |
151 | https://www.elastic.co/guide/en/logstash/current/filter-plugins.html |
||
152 | https://www.elastic.co/guide/en/logstash/current/output-plugins.html |