本文主要介绍 Logstash 的一些常用输出插件;相关的环境及软件信息如下:CentOS7.9、Logstash 8.2.2。

1、Stdout 输出插件

Stdout 插件把结果数据输出到标准输出。

input {
  stdin {
  }
}
output {
  stdout {
  }
}

2、File 输出插件

File 插件把结果数据输出文件。

input {
  stdin {
  }
}
output {
  file {
    path => "/home/hadoop/a.txt"
    codec => line {
      format => "%{message}" #只把原始数据写入文件
    }
  }
}

3、Elasticsearch 输出插件

Elasticsearch插件把结果数据写入到 Elasticsearch 中。

input {
  stdin {
    codec => json
  }
}
output {
  stdout { } #同时把结果输出到控制台
  elasticsearch {
    hosts => ["localhost:9200"]
    index => "my-index"
    user => "elastic"
    password => "123456"
  }
}

4、Kafka 输出插件

Kafka 插件把结果数据写入到 Kafka 中。

input {
  stdin {
  }
}
output {
  stdout {}
  kafka {
    topic_id => "test"
    codec => "plain"
  }
}

5、Rabbitmq 输出插件

Rabbitmq 插件把结果数据写入到 Rabbitmq中。

input {
  stdin {
  }
}
output {
  stdout {} #同时把结果输出到控制台
  rabbitmq {
    host => "localhost"
    port => 5672
    user => "admin"
    password => "admin"
    exchange => "" #默认交换机
    exchange_type => "direct"
    key => "test" #exchance绑定queue的routeKey
    codec => "plain"
  }
}

6、Http 输出插件

Rabbitmq 插件使用结果数据调用配置的 HTTP 接口。

input {
  stdin {
  }
}
output {
  stdout {}
  http {
    url => "http://localhost:8080/test/hello2"
    http_method => "post"
    format => "json"
    codec => "json"
  }
}

7、Redis 输出插件

Redis 插件把结果数据写入到 Redis 中。

input {
  stdin {
  }
}
output {
  stdout {
  }
  redis {
    host => "localhost"
    port => 6379
    data_type => "list"
    key => "a"
    codec => plain {
      format => "%{message}" #只把原始数据写入文件
    }
  }
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。