# TCP & TLS

The **tcp** output plugin allows to send records to a remote TCP server. The payload can be formatted in different ways as required.

## Configuration Parameters

| Key                | Description                                                                                                               | default   |
| ------------------ | ------------------------------------------------------------------------------------------------------------------------- | --------- |
| Host               | Target host where Fluent-Bit or Fluentd are listening for Forward messages.                                               | 127.0.0.1 |
| Port               | TCP Port of the target service.                                                                                           | 5170      |
| Format             | Specify the data format to be printed. Supported formats are *msgpack* *json*, *json\_lines* and *json\_stream*.          | msgpack   |
| json\_date\_key    | Specify the name of the time key in the output record. To disable the time key just set the value to `false`.             | date      |
| json\_date\_format | Specify the format of the date. Supported formats are *double*, *epoch* and *iso8601* (eg: *2018-05-30T09:39:52.000681Z*) | double    |

## TLS Configuration Parameters

The following parameters are available to configure a secure channel connection through TLS:

| Key             | Description                                                                                                                               | Default |
| --------------- | ----------------------------------------------------------------------------------------------------------------------------------------- | ------- |
| tls             | Enable or disable TLS support                                                                                                             | Off     |
| tls.verify      | Force certificate validation                                                                                                              | On      |
| tls.debug       | Set TLS debug verbosity level. It accept the following values: 0 (No debug), 1 (Error), 2 (State change), 3 (Informational) and 4 Verbose | 1       |
| tls.ca\_file    | Absolute path to CA certificate file                                                                                                      |         |
| tls.crt\_file   | Absolute path to Certificate file.                                                                                                        |         |
| tls.key\_file   | Absolute path to private Key file.                                                                                                        |         |
| tls.key\_passwd | Optional password for tls.key\_file file.                                                                                                 |         |

### Command Line

```bash
$ bin/fluent-bit -i cpu -o tcp://127.0.0.1:5170 -p format=json_lines -v
```

We have specified to gather [CPU](https://github.com/fluent/fluent-bit-docs/tree/16f30161dc4c79d407cd9c586a0c6839d0969d97/pipeline/input/cpu.md) usage metrics and send them in JSON lines mode to a remote end-point using netcat service, e.g:

#### Start the TCP listener

Run the following in a separate terminal, netcat will start listening for messages on TCP port 5170

```
$ nc -l 5170
```

Start Fluent Bit

```bash
$ bin/fluent-bit -i cpu -o stdout -p format=msgpack -v
Fluent Bit v1.x.x
* Copyright (C) 2019-2020 The Fluent Bit Authors
* Copyright (C) 2015-2018 Treasure Data
* Fluent Bit is a CNCF sub-project under the umbrella of Fluentd
* https://fluentbit.io

[2016/10/07 21:52:01] [ info] [engine] started
[0] cpu.0: [1475898721, {"cpu_p"=>0.500000, "user_p"=>0.250000, "system_p"=>0.250000, "cpu0.p_cpu"=>0.000000, "cpu0.p_user"=>0.000000, "cpu0.p_system"=>0.000000, "cpu1.p_cpu"=>0.000000, "cpu1.p_user"=>0.000000, "cpu1.p_system"=>0.000000, "cpu2.p_cpu"=>0.000000, "cpu2.p_user"=>0.000000, "cpu2.p_system"=>0.000000, "cpu3.p_cpu"=>1.000000, "cpu3.p_user"=>0.000000, "cpu3.p_system"=>1.000000}]
[1] cpu.0: [1475898722, {"cpu_p"=>0.250000, "user_p"=>0.250000, "system_p"=>0.000000, "cpu0.p_cpu"=>0.000000, "cpu0.p_user"=>0.000000, "cpu0.p_system"=>0.000000, "cpu1.p_cpu"=>1.000000, "cpu1.p_user"=>1.000000, "cpu1.p_system"=>0.000000, "cpu2.p_cpu"=>0.000000, "cpu2.p_user"=>0.000000, "cpu2.p_system"=>0.000000, "cpu3.p_cpu"=>0.000000, "cpu3.p_user"=>0.000000, "cpu3.p_system"=>0.000000}]
[2] cpu.0: [1475898723, {"cpu_p"=>0.750000, "user_p"=>0.250000, "system_p"=>0.500000, "cpu0.p_cpu"=>2.000000, "cpu0.p_user"=>1.000000, "cpu0.p_system"=>1.000000, "cpu1.p_cpu"=>0.000000, "cpu1.p_user"=>0.000000, "cpu1.p_system"=>0.000000, "cpu2.p_cpu"=>1.000000, "cpu2.p_user"=>0.000000, "cpu2.p_system"=>1.000000, "cpu3.p_cpu"=>0.000000, "cpu3.p_user"=>0.000000, "cpu3.p_system"=>0.000000}]
[3] cpu.0: [1475898724, {"cpu_p"=>1.000000, "user_p"=>0.750000, "system_p"=>0.250000, "cpu0.p_cpu"=>1.000000, "cpu0.p_user"=>1.000000, "cpu0.p_system"=>0.000000, "cpu1.p_cpu"=>2.000000, "cpu1.p_user"=>1.000000, "cpu1.p_system"=>1.000000, "cpu2.p_cpu"=>1.000000, "cpu2.p_user"=>1.000000, "cpu2.p_system"=>0.000000, "cpu3.p_cpu"=>1.000000, "cpu3.p_user"=>1.000000, "cpu3.p_system"=>0.000000}]
```

No more, no less, it just works.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.fluentbit.io/manual/1.6/pipeline/outputs/tcp-and-tls.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
