Skip to content

Commit c3dfd43

Browse files
kurtadojordansissel
authored andcommitted
expand attributes in ListingBlocks, sync to logstash-docs version
Fixes elastic#2216
1 parent 31d1f01 commit c3dfd43

File tree

1 file changed

+32
-36
lines changed

1 file changed

+32
-36
lines changed

docs/asciidoc/static/getting-started-with-logstash.asciidoc

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Using Elasticsearch as a backend datastore, and kibana as a frontend reporting t
99
[float]
1010
==== Prerequisite: Java
1111
The only prerequisite required by Logstash is a Java runtime. You can check that you have it installed by running the command `java -version` in your shell. Here's something similar to what you might see:
12-
[source,js]
12+
[source,java]
1313
----------------------------------
1414
> java -version
1515
java version "1.7.0_45"
@@ -32,15 +32,15 @@ Once you have verified the existence of Java on your system, we can move on!
3232
[float]
3333
==== Logstash in two commands
3434
First, we're going to download the 'logstash' binary and run it with a very simple configuration.
35-
[source,js]
35+
["source","sh",subs="attributes,callouts"]
3636
----------------------------------
37-
curl -O https://download.elasticsearch.org/logstash/logstash/logstash-%VERSION%.tar.gz
37+
curl -O https://download.elasticsearch.org/logstash/logstash/logstash-{logstash_version}.tar.gz
3838
----------------------------------
39-
Now you should have the file named 'logstash-%VERSION%.tar.gz' on your local filesystem. Let's unpack it:
40-
[source,js]
39+
Now you should have the file named 'logstash-{logstash_version}.tar.gz' on your local filesystem. Let's unpack it:
40+
["source","sh",subs="attributes,callouts"]
4141
----------------------------------
42-
tar zxvf logstash-%VERSION%.tar.gz
43-
cd logstash-%VERSION%
42+
tar zxvf logstash-{logstash_version}.tar.gz
43+
cd logstash-{logstash_version}
4444
----------------------------------
4545
Now let's run it:
4646
[source,js]
@@ -55,16 +55,16 @@ hello world
5555
2013-11-21T01:22:14.405+0000 0.0.0.0 hello world
5656
----------------------------------
5757

58-
OK, that's interesting... We ran Logstash with an input called "stdin", and an output named "stdout", and Logstash basically echoed back whatever we typed in some sort of structured format. Note that specifying the *-e* command line flag allows Logstash to accept a configuration directly from the command line. This is especially useful for quickly testing configurations without having to edit a file between iterations.
58+
OK, that's interesting... We ran Logstash with an input called `stdin`, and an output named `stdout`, and Logstash basically echoed back whatever we typed in some sort of structured format. Note that specifying the `-e` command line flag allows Logstash to accept a configuration directly from the command line. This is especially useful for quickly testing configurations without having to edit a file between iterations.
5959

60-
Let's try a slightly fancier example. First, you should exit Logstash by issuing a 'CTRL-C' command in the shell in which it is running. Now run Logstash again with the following command:
61-
[source,js]
60+
Let's try a slightly fancier example. First, you should exit Logstash by issuing a `CTRL-C` command in the shell in which it is running. Now run Logstash again with the following command:
61+
[source,ruby]
6262
----------------------------------
6363
bin/logstash -e 'input { stdin { } } output { stdout { codec => rubydebug } }'
6464
----------------------------------
6565

6666
And then try another test input, typing the text "goodnight moon":
67-
[source,js]
67+
[source,ruby]
6868
----------------------------------
6969
goodnight moon
7070
{
@@ -75,21 +75,21 @@ goodnight moon
7575
}
7676
----------------------------------
7777

78-
So, by re-configuring the "stdout" output (adding a "codec"), we can change the output of Logstash. By adding inputs, outputs and filters to your configuration, it's possible to massage the log data in many ways, in order to maximize flexibility of the stored data when you are querying it.
78+
So, by re-configuring the `stdout` output (adding a "codec"), we can change the output of Logstash. By adding inputs, outputs and filters to your configuration, it's possible to massage the log data in many ways, in order to maximize flexibility of the stored data when you are querying it.
7979

8080
[float]
8181
=== Storing logs with Elasticsearch
8282
Now, you're probably saying, "that's all fine and dandy, but typing all my logs into Logstash isn't really an option, and merely seeing them spit to STDOUT isn't very useful." Good point. First, let's set up Elasticsearch to store the messages we send into Logstash. If you don't have Elasticearch already installed, you can http://www.elasticsearch.org/download/[download the RPM or DEB package], or install manually by downloading the current release tarball, by issuing the following four commands:
8383

84-
[source,js]
84+
["source","sh",subs="attributes,callouts"]
8585
----------------------------------
86-
curl -O https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-%ELASTICSEARCH_VERSION%.tar.gz
87-
tar zxvf elasticsearch-%ELASTICSEARCH_VERSION%.tar.gz
88-
cd elasticsearch-%ELASTICSEARCH_VERSION%/
86+
curl -O https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-{elasticsearch_version}.tar.gz
87+
tar zxvf elasticsearch-{elasticsearch_version}.tar.gz
88+
cd elasticsearch-{elasticsearch_version}/
8989
./bin/elasticsearch
9090
----------------------------------
9191

92-
NOTE: This tutorial is running Logstash %VERSION% with Elasticsearch %ELASTICSEARCH_VERSION%, although you can use it with a cluster running 1.0.0 or later. Each release of Logstash has a *recommended* version of Elasticsearch to pair with. Make sure they match based on the http://www.elasticsearch.org/overview/logstash[Logstash version] you're running!
92+
NOTE: This tutorial is running running Logstash {logstash_version} with Elasticsearch {elasticsearch_version}, although you can use it with a cluster running 1.0.0 or later. Each release of Logstash has a *recommended* version of Elasticsearch to pair with. Make sure they match based on the http://www.elasticsearch.org/overview/logstash[Logstash version] you're running!
9393

9494
More detailed information on installing and configuring Elasticsearch can be found on http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/index.html[The Elasticsearch reference pages]. However, for the purposes of Getting Started with Logstash, the default installation and configuration of Elasticsearch should be sufficient.
9595

@@ -163,7 +163,7 @@ Typing a phrase will now echo back to your terminal, as well as save in Elastics
163163

164164
[float]
165165
==== Default - Daily Indices
166-
You might notice that Logstash was smart enough to create a new index in Elasticsearch... The default index name is in the form of 'logstash-YYYY.MM.DD', which essentially creates one index per day. At midnight (UTC), Logstash will automagically rotate the index to a fresh new one, with the new current day's timestamp. This allows you to keep windows of data, based on how far retroactively you'd like to query your log data. Of course, you can always archive (or re-index) your data to an alternate location, where you are able to query further into the past. If you'd like to simply delete old indices after a certain time period, you can use the https://github.com/elasticsearch/curator[Elasticsearch Curator tool].
166+
You might notice that Logstash was smart enough to create a new index in Elasticsearch... The default index name is in the form of `logstash-YYYY.MM.DD`, which essentially creates one index per day. At midnight (UTC), Logstash will automagically rotate the index to a fresh new one, with the new current day's timestamp. This allows you to keep windows of data, based on how far retroactively you'd like to query your log data. Of course, you can always archive (or re-index) your data to an alternate location, where you are able to query further into the past. If you'd like to simply delete old indices after a certain time period, you can use the https://github.com/elasticsearch/curator[Elasticsearch Curator tool].
167167

168168
[float]
169169
=== Moving On
@@ -177,7 +177,7 @@ Inputs, Outputs, Codecs and Filters are at the heart of the Logstash configurati
177177
===== Inputs
178178
Inputs are the mechanism for passing log data to Logstash. Some of the more useful, commonly-used ones are:
179179

180-
* *file*: reads from a file on the filesystem, much like the UNIX command "tail -0a"
180+
* *file*: reads from a file on the filesystem, much like the UNIX command `tail -0a`
181181
* *syslog*: listens on the well-known port 514 for syslog messages and parses according to RFC3164 format
182182
* *redis*: reads from a redis server, using both redis channels and also redis lists. Redis is often used as a "broker" in a centralized Logstash installation, which queues Logstash events from remote Logstash "shippers".
183183
* *lumberjack*: processes events sent in the lumberjack protocol. Now called https://github.com/elasticsearch/logstash-forwarder[logstash-forwarder].
@@ -201,7 +201,7 @@ Outputs are the final phase of the Logstash pipeline. An event may pass through
201201
* *statsd*: a service which "listens for statistics, like counters and timers, sent over UDP and sends aggregates to one or more pluggable backend services". If you're already using statsd, this could be useful for you!
202202
[float]
203203
===== Codecs
204-
Codecs are basically stream filters which can operate as part of an input, or an output. Codecs allow you to easily separate the transport of your messages from the serialization process. Popular codecs include 'json', 'msgpack' and 'plain' (text).
204+
Codecs are basically stream filters which can operate as part of an input, or an output. Codecs allow you to easily separate the transport of your messages from the serialization process. Popular codecs include `json`, `msgpack` and `plain` (text).
205205

206206
* *json*: encode / decode data in JSON format
207207
* *multiline*: Takes multiple-line text events and merge them into a single event, e.g. java exception and stacktrace messages
@@ -216,7 +216,7 @@ For the complete list of (current) configurations, visit the Logstash <<plugin_c
216216

217217
Specifying configurations on the command line using '-e' is only so helpful, and more advanced setups will require more lengthy, long-lived configurations. First, let's create a simple configuration file, and invoke Logstash using it. Create a file named "logstash-simple.conf" and save it in the same directory as Logstash.
218218

219-
[source,js]
219+
[source,ruby]
220220
----------------------------------
221221
input { stdin { } }
222222
output {
@@ -227,7 +227,7 @@ output {
227227

228228
Then, run this command:
229229

230-
[source,js]
230+
[source,ruby]
231231
----------------------------------
232232
bin/logstash -f logstash-simple.conf
233233
----------------------------------
@@ -238,7 +238,7 @@ Et voilà! Logstash will read in the configuration file you just created and run
238238
==== Filters
239239
Filters are an in-line processing mechanism which provide the flexibility to slice and dice your data to fit your needs. Let's see one in action, namely the *grok filter*.
240240

241-
[source,js]
241+
[source,ruby]
242242
----------------------------------
243243
input { stdin { } }
244244
@@ -258,20 +258,20 @@ output {
258258
----------------------------------
259259
Run Logstash with this configuration:
260260

261-
[source,js]
261+
[source,ruby]
262262
----------------------------------
263263
bin/logstash -f logstash-filter.conf
264264
----------------------------------
265265

266266
Now paste this line into the terminal (so it will be processed by the stdin input):
267-
[source,js]
267+
[source,ruby]
268268
----------------------------------
269269
127.0.0.1 - - [11/Dec/2013:00:01:45 -0800] "GET /xampp/status.php HTTP/1.1" 200 3891 "http://cadenza/xampp/navi.php" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:25.0) Gecko/20100101 Firefox/25.0"
270270
----------------------------------
271271

272272
You should see something returned to STDOUT which looks like this:
273273

274-
[source,js]
274+
[source,ruby]
275275
----------------------------------
276276
{
277277
"message" => "127.0.0.1 - - [11/Dec/2013:00:01:45 -0800] \"GET /xampp/status.php HTTP/1.1\" 200 3891 \"http://cadenza/xampp/navi.php\" \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:25.0) Gecko/20100101 Firefox/25.0\"",
@@ -369,7 +369,7 @@ Also, you might have noticed that Logstash did not reprocess the events which we
369369
==== Conditionals
370370
Now we can build on the previous example, where we introduced the concept of a *conditional*. A conditional should be familiar to most Logstash users, in the general sense. You may use 'if', 'else if' and 'else' statements, as in many other programming languages. Let's label each event according to which file it appeared in (access_log, error_log and other random files which end with "log").
371371

372-
[source,js]
372+
[source,ruby]
373373
----------------------------------
374374
input {
375375
file {
@@ -407,7 +407,7 @@ OK, now we can move on to another incredibly useful example: *syslog*. Syslog is
407407

408408
First, let's make a simple configuration file for Logstash + syslog, called 'logstash-syslog.conf'.
409409

410-
[source,js]
410+
[source,ruby]
411411
----------------------------------
412412
input {
413413
tcp {
@@ -441,21 +441,21 @@ output {
441441
----------------------------------
442442
Run it as normal:
443443

444-
[source,js]
444+
[source,ruby]
445445
----------------------------------
446446
bin/logstash -f logstash-syslog.conf
447447
----------------------------------
448448

449449
Normally, a client machine would connect to the Logstash instance on port 5000 and send its message. In this simplified case, we're simply going to telnet to Logstash and enter a log line (similar to how we entered log lines into STDIN earlier). First, open another shell window to interact with the Logstash syslog input and type the following command:
450450

451-
[source,js]
451+
[source,ruby]
452452
----------------------------------
453453
telnet localhost 5000
454454
----------------------------------
455455

456456
You can copy and paste the following lines as samples (feel free to try some of your own, but keep in mind they might not parse if the grok filter is not correct for your data):
457457

458-
[source,js]
458+
[source,ruby]
459459
----------------------------------
460460
Dec 23 12:11:43 louis postfix/smtpd[31499]: connect from unknown[95.75.93.154]
461461
Dec 23 14:42:56 louis named[16000]: client 199.48.164.7#64817: query (cache) 'amsterdamboothuren.com/MX/IN' denied
@@ -465,7 +465,7 @@ Dec 22 18:28:06 louis rsyslogd: [origin software="rsyslogd" swVersion="4.2.0" x-
465465

466466
Now you should see the output of Logstash in your original shell as it processes and parses messages!
467467

468-
[source,js]
468+
[source,ruby]
469469
----------------------------------
470470
{
471471
"message" => "Dec 23 14:30:01 louis CRON[619]: (www-data) CMD (php /usr/share/cacti/site/poller.php >/dev/null 2>/var/log/cacti/poller-error.log)",
@@ -488,7 +488,3 @@ Now you should see the output of Logstash in your original shell as it processes
488488
----------------------------------
489489

490490
Congratulations! You're well on your way to being a real Logstash power user. You should be comfortable configuring, running and sending events to Logstash, but there's much more to explore.
491-
492-
|=======================================================================
493-
494-
include::static/configuration.asciidoc[]

0 commit comments

Comments
 (0)