# Fluent's usage and Commands ###### tags: `By_Ivan` Some note of things i've read. **fluent-cat** The fluent-cat command sends an event to fluentd's in_forward/in_unix plugin. This is particularly useful for debuging. This can be used for testing between two terminals. ```shell= $ fluent-cat --none test HELLOworld ``` ```shell= $ fluentd -c empty.conf 2020-09-11 14:31:53 +0800 [info]: parsing config file is succeeded path="empty.conf" 2020-09-11 14:31:53 +0800 [info]: gem 'fluent-plugin-elasticsearch' version '2.12.5' 2020-09-11 14:31:53 +0800 [info]: gem 'fluent-plugin-formatter_pretty_json' version '1.0.0' 2020-09-11 14:31:53 +0800 [info]: gem 'fluent-plugin-mongo' version '1.4.1' 2020-09-11 14:31:53 +0800 [info]: gem 'fluent-plugin-s3' version '1.4.0' 2020-09-11 14:31:53 +0800 [info]: gem 'fluent-plugin-sql' version '2.0.0' 2020-09-11 14:31:53 +0800 [info]: gem 'fluent-plugin-td' version '1.1.0' 2020-09-11 14:31:53 +0800 [info]: gem 'fluentd' version '1.11.2' 2020-09-11 14:31:53 +0800 [info]: using configuration file: <ROOT> <source> @type forward </source> <match *> @type stdout </match> </ROOT> 2020-09-11 14:31:53 +0800 [info]: starting fluentd-1.11.2 pid=6111 ruby="2.5.5" 2020-09-11 14:31:53 +0800 [info]: spawn command to main: cmdline=["/usr/bin/ruby", "-Eascii-8bit:ascii-8bit", "/home/ivan/bin/fluentd", "-c", "empty.conf", "--under-supervisor"] 2020-09-11 14:31:53 +0800 [info]: adding match pattern="*" type="stdout" 2020-09-11 14:31:54 +0800 [info]: adding source type="forward" 2020-09-11 14:31:54 +0800 [info]: #0 starting fluentd worker pid=6120 ppid=6111 worker=0 2020-09-11 14:31:54 +0800 [info]: #0 listening port port=24224 bind="0.0.0.0" 2020-09-11 14:31:54 +0800 [info]: #0 fluentd worker is now running worker=0 2020-09-11 14:32:09.417269980 +0800 test: {"message":"HELLOworld"} ``` **none-parser** Can be used to split multiline input to seperated events EX: spliting sar result into seperated lines ```r= <source> @type exec command sar | tail -10 tag script <parse> @type none </parse> </source> <match script> @type stdout </match> ``` ### Endpoints and logging **Endpoints** Fluentd supports curl endpoint for receiving signal and monitoring plugin instance. 1. instance monitoring ```r= # add this source plugin to enable this function <source> @type monitor_agent @id in_curl bind "127.0.0.1" port 24220 </source> ``` ```shell! $ curl http://127.0.0.1:24220/api/plugins.json {"plugins":[{"plugin_id":"in_curl","plugin_category":"input","type":"monitor_agent","config":{"@type":"monitor_agent","@id":"in_curl","bind":"127.0.0.1","port":"24220"},"output_plugin":false,"retry_count":null},{"plugin_id":"in_exec","plugin_category":"input","type":"exec","config":{"@type":"exec","@id":"in_exec","command":"echo \"Hello World\"","run_interval":"30s","tag":"test_run"},"output_plugin":false,"retry_count":null},{"plugin_id":"out_std","plugin_category":"output","type":"stdout","config":{"@type":"stdout","@id":"out_std"},"output_plugin":true,"retry_count":0,"emit_records":9,"emit_count":9,"write_count":0,"rollback_count":0,"slow_flush_count":0,"flush_time_count":0,"retry":{}}]} ``` There are several query parameters that can be used. For example, adding "debug" would expose additional internal metrics. ```shell $ curl http://127.0.0.1:24220/api/plugins.json?debug=1 { "plugins": [ { "plugin_id": "in_curl", "plugin_category": "input", "type": "monitor_agent", "config": { "@type": "monitor_agent", "@id": "in_curl", "bind": "127.0.0.1", "port": "24220" }, "output_plugin": false, "retry_count": null, "instance_variables": { "log": "#<Fluent::PluginLogger:0x000055f4a86ec5d8>", "bind": "127.0.0.1", "port": 24220, "tag": null, "emit_interval": 60, "include_config": true, "include_retry": true, "transport_config": "<Fluent::Config::Secti ... ... ``` ::: info When using monitor agent, it is sugested to add @id for each distinct plugin. This benefits labeling in the query result. ::: [doc](https://docs.fluentd.org/input/monitor_agent) 2. signal receiving Originally Fluentd can be controlled by internal signals. For remote server model, RPC can be used to send these signals. ```r= # add this inside config to enable this function <system> rpc_endpoint 127.0.0.1:24444 </system> ``` ```shell $ curl http://127.0.0.1:24444/api/${ENDPOINT} ``` | ENDPOINT | Function | | -------- | -------- | |/api/processes.interruptWorkers | Stops the daemon. | |/api/processes.killWorkers | Stops the daemon. | |/api/processes.flushBuffersAndKillWorkers |Flushes buffer and stops the daemon. | |/api/plugins.flushBuffers | Flushes the buffered messages. | |/api/config.gracefulReload | Reloads configuration. | |/api/config.reload | Reloads configuration. | [doc](https://docs.fluentd.org/deployment/rpc) **Logging** 1. flowcounter ### Multi Process Workers [doc](https://docs.fluentd.org/deployment/multi-process-workers) ___