Configuring Logstash

To configure Logstash, you create a config file that specifies which plugins you want to use and settings for each plugin.

You can reference event fields in a configuration and use conditionals to process events when they meet certain criteria.

When you run logstash, you use the -f to specify your config file.

Let’s step through creating a simple config file and using it to run Logstash. Create a file named "logstash-simple.conf" and save it in the same directory as Logstash.

input { stdin { } }
output {
elasticsearch { hosts => ["localhost:9200"] }
stdout { codec => rubydebug }
}

Then, run logstash and specify the configuration file with the -f flag.

bin/logstash -f logstash-simple.conf

Et voilà! Logstash reads the specified configuration file and outputs to both Elasticsearch and stdout.

Before we move on to some more complex examples, let’s take a closer look at what’s in a config file.

Structure of a Config File

A Logstash config file has a separate section for each type of plugin you want to add to the event processing pipeline.

For example:

# This is a comment. You should use comments to describe
# parts of your configuration.
input {
...
} filter {
...
} output {
...
}

Each section contains the configuration options for one or more plugins.

If you specify multiple filters, they are applied in the order of their appearance in the configuration file.

Plugin Configuration

The configuration of a plugin consists of the plugin name followed by a block of settings for that plugin.

For example, this input section configures two file inputs:

input {
file {
path => "/var/log/messages"
type => "syslog"
} file {
path => "/var/log/apache/access.log"
type => "apache"
}
}

In this example, two settings are configured for each of the file inputs: path and type.

The settings you can configure vary according to the plugin type.

For information about each plugin, see Input Plugins, Output Plugins, Filter Plugins, and Codec Plugins.

Value Types

A plugin can require that the value for a setting be a certain type, such as boolean, list, or hash.

The following value types are supported.

Array

This type is now mostly deprecated弃用 in favor of using a standard type like string with the plugin defining the :list => true property for better type checking.

It is still needed to handle lists of hashes or mixed types where type checking is not desired.

Example:

  users => [ {id => 1, name => bob}, {id => 2, name => jane} ]

Lists

Not a type in and of itself, but a property types can have.

This makes it possible to type check multiple values.

Plugin authors can enable list checking by specifying :list => true when declaring an argument.

Example:

path => [ "/var/log/messages", "/var/log/*.log" ]
uris => [ "http://elastic.co", "http://example.net" ]

This example configures path, which is a string to be a list that contains an element for each of the three strings.

It also will configure the uris parameter to be a list of URIs, failing if any of the URIs provided are not valid.

Boolean

A boolean must be either true or false.

Note that the true and false keywords are not enclosed in quotes.

Example:

ssl_enable => true

Bytes

A bytes field is a string field that represents a valid unit of bytes.

It is a convenient way to declare specific sizes in your plugin options.

Both SI (k M G T P E Z Y) and Binary (Ki Mi Gi Ti Pi Ei Zi Yi) units are supported.

Binary units are in base-1024 and SI units are in base-1000.

This field is case-insensitive and accepts space between the value and the unit.

If no unit is specified, the integer string represents the number of bytes.

Examples:

  my_bytes => "1113"   # 1113 bytes
my_bytes => "10MiB" # 10485760 bytes
my_bytes => "100kib" # 102400 bytes
my_bytes => "180 mb" # 180000000 bytes

Codec

A codec is the name of Logstash codec used to represent the data. Codecs can be used in both inputs and outputs.

Input codecs provide a convenient way to decode your data before it enters the input.

Output codecs provide a convenient way to encode your data before it leaves the output.

Using an input or output codec eliminates the need for a separate filter in your Logstash pipeline.

A list of available codecs can be found at the Codec Plugins page.

Example:

  codec => "json"

Hash

A hash is a collection of key value pairs specified in the format "field1" => "value1".

Note that multiple key value entries are separated by spaces rather than commas.

Example:

match => {
"field1" => "value1"
"field2" => "value2"
...
}

Number

Numbers must be valid numeric values (floating point or integer).

Example:

port => 33

Password

A password is a string with a single value that is not logged or printed.

Example:

my_password => "password"

URI

A URI can be anything from a full URL like http://elastic.co/ to a simple identifier like foobar.

If the URI contains a password such as http://user:pass@example.net the password portion of the URI will not be logged or printed.

Example:

my_uri => "http://foo:bar@example.net"

Path

A path is a string that represents a valid operating system path.

Example:

String

A string must be a single character sequence. Note that string values are enclosed in quotes, either double or single.

Escape Sequences

By default, escape sequences are not enabled.

If you wish to use escape sequences in quoted strings, you will need to set config.support_escapes: true in your logstash.yml.

When true, quoted strings (double and single) will have this transformation:

name => "Hello world"
name => 'It\'s a beautiful day'

Comments

Comments are the same as in perl, ruby, and python. A comment starts with a # character, and does not need to be at the beginning of a line. For example:

# this is a comment

input { # comments can appear at the end of a line, too
# ...
}

Configuring Logstash的更多相关文章

  1. 【原创】大数据基础之Logstash(4)高可用

    logstash高可用体现为不丢数据(前提为服务器短时间内不可用后可恢复比如重启服务器或重启进程),具体有两个方面: 进程重启(服务器重启) 事件消息处理失败 在logstash中对应的解决方案为: ...

  2. 2-4、配置Filebeat使用logstash

    配置filebeat使用logstash 重要:要将事件发送到Logstash,还需要创建一个Logstash配置管道,该管道监听传入的Beats连接并将收到的事件编入索引到Elasticsearch ...

  3. Kubernetes部署ELK并使用Filebeat收集容器日志

    本文的试验环境为CentOS 7.3,Kubernetes集群为1.11.2,安装步骤参见kubeadm安装kubernetes V1.11.1 集群 1. 环境准备 Elasticsearch运行时 ...

  4. Windows上怎么安装ELK

    In this guide I will show that it is also possible to run Logstash on a Windows Server 2012 machine ...

  5. 【笔记】草履虫也能看懂的ELK搭建流程

    环境需要 Elasticsearch需要JAVA环境,至少是JDK1.8 elasticsearch 不允许root用户使用,需要新增个elk用户 如果觉得官网下载太慢,可以使用这个 https:// ...

  6. 测试右移:线上质量监控 ELK 实战

    目录 [测试右移]介绍 ELK Stack 介绍 ELK 监控体系搭建 ES & Kibana 搭建 Nginx 日志自动采集 Nginx Agent 安装 Nginx 服务器 数据分析 Lo ...

  7. Manage Spring Boot Logs with Elasticsearch, Logstash and Kibana

    下载地址:https://www.elastic.co/downloads When time comes to deploy a new project, one often overlooked ...

  8. ElasticSearch+Logstash+Filebeat+Kibana集群日志管理分析平台搭建

    一.ELK搜索引擎原理介绍 在使用搜索引擎是你可能会觉得很简单方便,只需要在搜索栏输入想要的关键字就能显示出想要的结果.但在这简单的操作背后是搜索引擎复杂的逻辑和许多组件协同工作的结果. 搜索引擎的组 ...

  9. elasticsearch+logstash+redis+kibana 实时分析nginx日志

    1. 部署环境 2. 架构拓扑 3. nginx安装 安装在192.168.176.128服务器上 这里安装就简单粗暴了直接yum安装nginx [root@manager ~]# yum -y in ...

随机推荐

  1. 福布斯最佳雇主榜:谷歌母公司Alphabet再登榜首 微软次之

    http://www.sohu.com/a/259018538_114774 站长之家(ChinaZ.com) 10月12日 消息:在福布斯发布的最新全球最佳雇主榜单中,谷歌母公司Alphabet以满 ...

  2. callback源码分析——callbacks

    uvm的callback必须是提供者有预见性的留一些方法在function前后,这样在使用的时候,进行遍历调度即可 设计者,需要从uvm_callback定义一个基类,只定义function原型,定义 ...

  3. WEB应用程序:AJAX全套

    概述 对于WEB应用程序:用户浏览器发送请求,服务器接收并处理请求,然后返回结果,往往返回就是字符串(HTML),浏览器将字符串(HTML)渲染并显示浏览器上. 1.传统的Web应用 一个简单操作需要 ...

  4. python中常见的错误类型

    Python异常类 Python是面向对象语言,所以程序抛出的异常也是类.常见的Python异常有以下几个 ,大家只要大致扫一眼,有个映像,等到编程的时候,相信大家肯定会不只一次跟他们照面(除非你不用 ...

  5. DNN模型训练词向量原理

    转自:https://blog.csdn.net/fendouaini/article/details/79821852 1 词向量 在NLP里,最细的粒度是词语,由词语再组成句子,段落,文章.所以处 ...

  6. c# 静态方法和数据

    c#所有方法都必须在类的内部声明,但如果把方法或者字段声明为static就可以使用,类名代用方法或者访问字段. 在方法中声明一个静态变量a 和一个静态的aFun方法.下面是在主函数中调用. 从上图可以 ...

  7. 20165215 2017-2018-2 《Java程序设计》第2周学习总结

    20165215 2017-2018-2 <Java程序设计>第2周学习总结 教材学习内容总结 chapter2 逻辑类型boolea只能赋值true或false Java没有无符号整数类 ...

  8. AtCoder Beginner Contest 044 A - 高橋君とホテルイージー / Tak and Hotels (ABC Edit)

    Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement There is a hotel with ...

  9. Cookie,Session,正则表达式

    一.Cookie和Session基础知识 Cookie:客户端本地存储的键值对 Http访问是不记录状态的,所以要借助session和cookie来保存访问状态  当你在浏览网站的时候,WEB 服务器 ...

  10. 深入理解softmax函数

    Softmax回归模型,该模型是logistic回归模型在多分类问题上的推广,在多分类问题中,类标签  可以取两个以上的值.Softmax模型可以用来给不同的对象分配概率.即使在之后,我们训练更加精细 ...