Fluentd
1.0
1.0
  • Introduction
  • Overview
    • Life of a Fluentd event
    • Support
    • FAQ
    • Logo
    • fluent-package v5 vs td-agent v4
  • Installation
    • Before Installation
    • Install fluent-package
      • RPM Package (Red Hat Linux)
      • DEB Package (Debian/Ubuntu)
      • .dmg Package (macOS)
      • .msi Installer (Windows)
    • Install calyptia-fluentd
      • RPM Package (Red Hat Linux)
      • DEB Package (Debian/Ubuntu)
      • .dmg Package (macOS)
      • .msi Installer (Windows)
    • Install by Ruby Gem
    • Install from Source
    • Post Installation Guide
    • Obsolete Installation
      • Treasure Agent v4 (EOL) Installation
        • Install by RPM Package v4 (Red Hat Linux)
        • Install by DEB Package v4 (Debian/Ubuntu)
        • Install by .dmg Package v4 (macOS)
        • Install by .msi Installer v4 (Windows)
      • Treasure Agent v3 (EOL) Installation
        • Install by RPM Package v3 (Red Hat Linux)
        • Install by DEB Package v3 (Debian/Ubuntu)
        • Install by .dmg Package v3 (macOS)
        • Install by .msi Installer v3 (Windows)
  • Configuration
    • Config File Syntax
    • Config File Syntax (YAML)
    • Routing Examples
    • Config: Common Parameters
    • Config: Parse Section
    • Config: Buffer Section
    • Config: Format Section
    • Config: Extract Section
    • Config: Inject Section
    • Config: Transport Section
    • Config: Storage Section
    • Config: Service Discovery Section
  • Deployment
    • System Configuration
    • Logging
    • Signals
    • RPC
    • High Availability Config
    • Performance Tuning
    • Multi Process Workers
    • Failure Scenarios
    • Plugin Management
    • Trouble Shooting
    • Fluentd UI
    • Linux Capability
    • Command Line Option
    • Source Only Mode
    • Zero-downtime restart
  • Container Deployment
    • Docker Image
    • Docker Logging Driver
    • Docker Compose
    • Kubernetes
  • Monitoring Fluentd
    • Overview
    • Monitoring by Prometheus
    • Monitoring by REST API
  • Input Plugins
    • tail
    • forward
    • udp
    • tcp
    • unix
    • http
    • syslog
    • exec
    • sample
    • monitor_agent
    • windows_eventlog
  • Output Plugins
    • file
    • forward
    • http
    • exec
    • exec_filter
    • secondary_file
    • copy
    • relabel
    • roundrobin
    • stdout
    • null
    • s3
    • kafka
    • elasticsearch
    • opensearch
    • mongo
    • mongo_replset
    • rewrite_tag_filter
    • webhdfs
    • buffer
  • Filter Plugins
    • record_transformer
    • grep
    • parser
    • geoip
    • stdout
  • Parser Plugins
    • regexp
    • apache2
    • apache_error
    • nginx
    • syslog
    • ltsv
    • csv
    • tsv
    • json
    • msgpack
    • multiline
    • none
  • Formatter Plugins
    • out_file
    • json
    • ltsv
    • csv
    • msgpack
    • hash
    • single_value
    • stdout
    • tsv
  • Buffer Plugins
    • memory
    • file
    • file_single
  • Storage Plugins
    • local
  • Service Discovery Plugins
    • static
    • file
    • srv
  • Metrics Plugins
    • local
  • How-to Guides
    • Stream Analytics with Materialize
    • Send Apache Logs to S3
    • Send Apache Logs to Minio
    • Send Apache Logs to Mongodb
    • Send Syslog Data to Graylog
    • Send Syslog Data to InfluxDB
    • Send Syslog Data to Sematext
    • Data Analytics with Treasure Data
    • Data Collection with Hadoop (HDFS)
    • Simple Stream Processing with Fluentd
    • Stream Processing with Norikra
    • Stream Processing with Kinesis
    • Free Alternative To Splunk
    • Email Alerting like Splunk
    • How to Parse Syslog Messages
    • Cloud Data Logging with Raspberry Pi
  • Language Bindings
    • Java
    • Ruby
    • Python
    • Perl
    • PHP
    • Nodejs
    • Scala
  • Plugin Development
    • How to Write Input Plugin
    • How to Write Base Plugin
    • How to Write Buffer Plugin
    • How to Write Filter Plugin
    • How to Write Formatter Plugin
    • How to Write Output Plugin
    • How to Write Parser Plugin
    • How to Write Storage Plugin
    • How to Write Service Discovery Plugin
    • How to Write Tests for Plugin
    • Configuration Parameter Types
    • Upgrade Plugin from v0.12
  • Plugin Helper API
    • Plugin Helper: Child Process
    • Plugin Helper: Compat Parameters
    • Plugin Helper: Event Emitter
    • Plugin Helper: Event Loop
    • Plugin Helper: Extract
    • Plugin Helper: Formatter
    • Plugin Helper: Inject
    • Plugin Helper: Parser
    • Plugin Helper: Record Accessor
    • Plugin Helper: Server
    • Plugin Helper: Socket
    • Plugin Helper: Storage
    • Plugin Helper: Thread
    • Plugin Helper: Timer
    • Plugin Helper: Http Server
    • Plugin Helper: Service Discovery
  • Troubleshooting Guide
  • Appendix
    • Update from v0.12 to v1
    • td-agent v2 vs v3 vs v4
Powered by GitBook
On this page
  • Methods
  • server_create_connection(title, port, proto: nil, bind: '0.0.0.0', shared: true, backlog: nil, tls_options: nil, **socket_options, &block)
  • server_create(title, port, proto: nil, bind: '0.0.0.0', shared: true, socket: nil, backlog: nil, tls_options: nil, max_bytes: nil, flags: 0, **socket_options, &callback)
  • Configuration example
  • General configuration
  • TLS configuration: Basic examples
  • TLS configuration: cert_verifier example
  • Plugins using server

Was this helpful?

  1. Plugin Helper API

Plugin Helper: Server

The server plugin helper manages various types of servers.

Here is an example:

require 'fluent/plugin/input'

module Fluent::Plugin
  class ExampleInput < Input
    Fluent::Plugin.register_input('example', self)

    # 1. Load server helper
    helpers :server

    # Omit `configure`, `shutdown` and other plugin APIs

    def start
      # 2. Create server
      server_create(:title, @port) do |data|
        #3. Process data
      end
    end
  end
end

The launched server is managed by the plugin helper. No need of server shutdown code in plugin's shutdown method. The plugin shutdowns the launched servers automatically.

Methods

server_create_connection(title, port, proto: nil, bind: '0.0.0.0', shared: true, backlog: nil, tls_options: nil, **socket_options, &block)

This method creates a server instance for various protocols.

The &block is invoked with the new connection as a parameter.

  • title: unique symbol

  • port: the port to listen to

  • proto: protocol type. { :tcp, :tls }

  • bind: the bind address to listen to

  • shared: if true, share socket via server engine for multiple workers

  • backlog: the maximum length of the queue for pending connections

  • tls_options: options for TLS

    • version: set TLS version :TLSv1_1 or :TLSv1_2.

      Default: :TLSv1_2

    • ciphers: set the list of available cipher suites. (default:

      "ALL:!aNULL:!eNULL:!SSLv2")

    • insecure: if true, set TLS verify mode NONE

    • verify_fqdn: if true, validate the server certificate for the hostname

    • fqdn: set FQDN

    • enable_system_cert_store: if true, enable system default cert store

    • allow_self_signed_cert: if true, allow self-signed certificate

    • cert_paths: files contain PEM-encoded certificates

  • socket_options: options for socket

    • resolve_name: if true, resolve the hostname

    • connect: if true, connect to host

    • nonblock: if true, use non-blocking I/O

    • linger_timeout: the timeout (seconds) to set SO_LINGER

    • recv_timeout: the timeout (seconds) to set SO_RECVTIMEO

    • send_timeout: the timeout (seconds) to set SO_SNDTIMEO

Example:

# TCP
server_create_connection(:title, @port) do |conn|
  # on connection
  # conn is Fluent::PluginHelper::Server::TCPCallbackSocket
  source_addr = conn.remote_host
  source_port = conn.remote_port
  conn.data do |data|
    conn.write(something)
  end
end

server_create(title, port, proto: nil, bind: '0.0.0.0', shared: true, socket: nil, backlog: nil, tls_options: nil, max_bytes: nil, flags: 0, **socket_options, &callback)

This method creates a server instance for various protocols.

The &block is invoked with parameter(s) on data.

  • title: unique symbol

  • port: the port to listen to

  • proto: protocol type. { :tcp, :udp, :tls }

  • bind: the bind address to listen to

  • shared: if true, share socket via server engine for multiple workers

  • socket: socket instance for UDP (only for UDP)

  • backlog: the maximum length of the queue for pending connections

  • tls_options: options for TLS

    • version: set TLS version :TLSv1_1 or :TLSv1_2. (default: :TLSv1_2)

    • ciphers: set the list of available cipher suites. (default:

      "ALL:!aNULL:!eNULL:!SSLv2")

    • insecure: if true, set TLS verify mode NONE

    • verify_fqdn: if true, validate the server certificate for the hostname

    • fqdn: set FQDN

    • enable_system_cert_store: if true, enable system default cert store

    • allow_self_signed_cert: if true, allow self signed certificate

    • cert_paths: files contain PEM-encoded certificates

  • max_bytes: the maximum number of bytes to receive (required for UDP)

  • flags: zero or more of the MSG_ options (UDP-only)

  • socket_options: options for socket

    • resolve_name: if true, resolve the hostname

    • connect: if true, connect to host

    • nonblock: if true, use non-blocking I/O

    • linger_timeout: the timeout (seconds) to set SO_LINGER

    • recv_timeout: the timeout (seconds) to set SO_RECVTIMEO

    • send_timeout: the timeout (seconds) to set SO_SNDTIMEO

Code example:

# UDP (w/o socket)
server_create(:title, @port, proto: :udp, max_bytes: 2048) do |data|
  # data is received data
end

# UDP (w/ socket)
server_create(:title, @port, proto: :udp, max_bytes: 2048) do |data, sock|
  # data is received data
  # sock is UDPSocket
end

# TCP (w/o connection)
server_create(:title, @port) do |data|
  # data is received data
end

# TCP (w/ connection)
server_create(:title, @port) do |data, conn|
  # data is received data
  # conn is Fluent::PluginHelper::Server::TCPCallbackSocket
end

# TLS (w/o connection)
server_create(:title, @port, proto: :tls) do |data|
  # data is received data
end

# TLS (w/ connection)
server_create(:title, @port, proto: :tls) do |data, conn|
  # data is received data
  # conn is Fluent::PluginHelper::Server::TLSCallbackSocket
end

Configuration example

General configuration

linger_timeout

type
default
available transport type
version

integer

0

tcp, tls

1.14.6

The timeout (seconds) to set SO_LINGER.

The default value 0 is to send RST rather than FIN to avoid lots of connections sitting in TIME_WAIT on closing on non-Windows.

You can set positive value to send FIN on closing on non-Windows.

On Windows, Fluentd sends FIN without depending on this setting.

<source>
  @type tcp
  # other plugin parameters
  <transport tcp>
    linger_timeout 1
  </transport>
</source>

TLS configuration: Basic examples

  1. Use existing certs (signed by public CA or self signed CA)

  2. Use certs automatically generated by Fluentd

Case 1. Use existing certs (signed by public CA or self signed CA)

If cert_path and private_key_path are specified, certs generation is disabled. The existing certs are loaded.

<source>
  @type forward
  # other plugin parameters
  <transport tls>
    version TLSv1_2
    ciphers ALL:!aNULL:!eNULL:!SSLv2
    insecure false

    # For Cert signed by public CA
    ca_path /path/to/ca_file
    cert_path /path/to/cert_path
    private_key_path /path/to/priv_key
    private_key_passphrase "passphrase"
    client_cert_auth false

    # For Cert signed by self signed CA
    ca_path /path/to/ca_path
    cert_path /path/to/cert_path
    private_key_path /path/to/priv_key
    private_key_passphrase "passphrase"
    client_cert_auth false

  </transport>
</source>

Case 2. Use certs automatically generated by Fluentd

<source>
  @type forward
  # other plugin parameters
  <transport tls>
    version TLSv1_2
    ciphers ALL:!aNULL:!eNULL:!SSLv2
    insecure false

    # For Cert generated
    ca_cert_path /path/to/ca_cert
    ca_private_key_path /path/to/ca_priv_key
    ca_private_key_passphrase "ca_passphrase"

  </transport>
</source>

TLS configuration: cert_verifier example

cert_verifier is supported since v1.10.0.

Configuration example:

<source>
  @type forward
  <transport tls>
    # other parameters
    client_cert_auth true
    cert_verifier /path/to/my_verifier.rb
  </transport>
</source>
  • my_verifier.rb example

Proc or lambda Object for the Simple Scenario

Proc.new { |ok, ctx|
  # check code

  if cond
    true
  else
    false
  end
}

Use class for the Complicated Scenario

This is CN check example:

module Fluent
  module Plugin
    class InForwardCNChecker
      def initialize
        # Modify for actual common names
        @allow_list = ['fluentd', 'fluentd-client', 'other-org']
      end

      def call(ok, ctx)
        subject = ctx.chain.first.subject.to_a.find { |entry| entry.first == 'CN' }
        if subject
          @allow_list.include?(subject[1])
        else
          false
        end
      end
    end
  end
end

Fluent::Plugin::InForwardCNChecker.new

Plugins using server

PreviousPlugin Helper: Record AccessorNextPlugin Helper: Socket

Last updated 8 months ago

Was this helpful?

For more details, see .

cert_verifier: if specified, pass evaluated object to OpenSSL's . See also "cert_verifier example" section.

send_keepalive_packet: if true, enable TCP keep-alive via SO_KEEPALIVE. See also .

cert_verifier: if specified, pass evaluated object to OpenSSL's . See also "cert_verifier example" section.

send_keepalive_packet: if true, enable TCP keep-alive via SO_KEEPALIVE. See also .

If ca_cert_path and ca_private_key_path are specified, certs generation is enabled. You can customize cert generation behavior via generation_... parameters. See about parameter details.

The code must return a callable object that has a call method with two arguments. This object is used as OpenSSL's .

If this article is incorrect or outdated, or omits critical information, please . is an open-source project under . All components are available under the Apache 2 License.

Transport Section
verify_callback
verify_callback
verify_callback
in_forward
in_syslog
in_tcp
in_udp
out_forward
let us know
Fluentd
Cloud Native Computing Foundation (CNCF)
Generated and Signed by Private CA Certs or Self-signed Parameters
socket article
socket article