|
| 1 | +# tail_with_throttle |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +The `in_tail_with_throttle` Input plugin allows Fluentd to read events from the tail of text files. Its behavior is similar to that of `in_tail` Input Plugin with the only difference being that this plugin rate limits the number of events read on the basis of groups. |
| 6 | + |
| 7 | +## Example Configuration |
| 8 | + |
| 9 | +```text |
| 10 | +<source> |
| 11 | + @type tail_with_throttle |
| 12 | + path /var/log/*.log |
| 13 | + pos_file /var/log/temp.log.pos |
| 14 | + tag applogs |
| 15 | + <parse> |
| 16 | + @type apache2 |
| 17 | + </parse> |
| 18 | + <group> |
| 19 | + pattern /(?<appname>[a-z0-9]([-a-z0-9]*[a-z0-9])?(\/[a-z0-9]([-a-z0-9]*[a-z0-9])?)*)_(?<namespace>[^_]+)_(?<container>.+)-(?<docker_id>[a-z0-9]{64})\.log$ |
| 20 | + rate_period 30s |
| 21 | + <rule> |
| 22 | + namespace logging |
| 23 | + appname frontend |
| 24 | + limit 500 |
| 25 | + </rule> |
| 26 | + <rule> |
| 27 | + namespace logging |
| 28 | + appname backend |
| 29 | + limit 1000 |
| 30 | + </rule> |
| 31 | + <rule> |
| 32 | + limit 20 |
| 33 | + </rule> |
| 34 | + </group> |
| 35 | +</source> |
| 36 | +``` |
| 37 | + |
| 38 | +Refer to the [Configuration File](../configuration/config-file.md) article for the basic structure and syntax of the configuration file. |
| 39 | + |
| 40 | +For `<parse>`, see [Parse Section](../configuration/parse-section.md). |
| 41 | + |
| 42 | +### How It Works |
| 43 | + |
| 44 | +When Fluentd is configured with `in_tail_with_throttle`, it will form groups based on the rules provided in the configuration file. Based on group formation, log files will be assigned to a group and reading will start from the **tail** of that log, not the beginning. Group limits are equally distributed among the log files in a group. If the group line limit of the log is reached within rate_period time interval, Fluentd will stop reading logs. Once, **rate_period** (time) is over, Fluentd will reset its group counters and restart the reading process. |
| 45 | + |
| 46 | + |
| 47 | +## Plugin Helpers |
| 48 | + |
| 49 | +* [`timer`](../plugin-helper-overview/api-plugin-helper-timer.md) |
| 50 | +* [`event_loop`](../plugin-helper-overview/api-plugin-helper-event_loop.md) |
| 51 | +* [`parser`](../plugin-helper-overview/api-plugin-helper-parser.md) |
| 52 | +* [`compat_parameters`](../plugin-helper-overview/api-plugin-helper-compat_parameters.md) |
| 53 | + |
| 54 | +See also: [Linux capability](../deployment/linux-capability.md) |
| 55 | + |
| 56 | +## Parameters |
| 57 | + |
| 58 | +See [Common Parameters](../configuration/plugin-common-parameters.md). |
| 59 | + |
| 60 | +`in_tail_with_throttle` Input Plugin utilizes `in_tail` plugin's configuration. Refer to `in_tail` plugin's parameters [in_tail Parameters](./tail.md) |
| 61 | + |
| 62 | +The additional parameter which `in_tail_with_throttle` uses is the `<group>` Directive. |
| 63 | + |
| 64 | +### `<group>` Directive \(required\) |
| 65 | + |
| 66 | +Grouping rules for the log. |
| 67 | + |
| 68 | +`in_tail_with_throttle` assigns each log file to a group based on the rules provided in **`<group>`** directive. The `limit` parameter controls the total number of lines collected for a group by `tail_with_throttle` Input Plugin. |
| 69 | + |
| 70 | +Example: |
| 71 | + |
| 72 | +```text |
| 73 | +# group rules |
| 74 | +<group> |
| 75 | + rate_period 5s |
| 76 | +
|
| 77 | + <rule> |
| 78 | + namespace shopping |
| 79 | + appname frontend |
| 80 | + limit 1000 |
| 81 | + </rule> |
| 82 | +
|
| 83 | + <rule> |
| 84 | + namespace payment |
| 85 | + appname backend |
| 86 | + limit 2000 |
| 87 | + </rule> |
| 88 | +</group> |
| 89 | +``` |
| 90 | + |
| 91 | +#### `pattern` |
| 92 | + |
| 93 | +| type | default | version | |
| 94 | +| :--- | :--- | :--- | |
| 95 | +| regexp | `/(?<appname>[a-z0-9]([-a-z0-9]*[a-z0-9])?(\/[a-z0-9]([-a-z0-9]*[a-z0-9])?)*)_(?<namespace>[^_]+)_(?<container>.+)-(?<docker_id>[a-z0-9]{64})\.log$`| 0.14.1 | |
| 96 | + |
| 97 | +Specifies the regular expression for extracting metadata (namespace, appname) from log file path. Default value of the pattern regexp follows CRIO path format which gives information about `namespace`, `pod` (appname), `docker_id`, `container` of the log. |
| 98 | + |
| 99 | +Please add `namespace` and `appname` regex-groups in your custom regex pattern to extract metadata from filenames. If the pattern specified in the configuration fails to identify `namespace` and `appname` information, it will assign the log to the default group. |
| 100 | + |
| 101 | + |
| 102 | +#### `rate_period` |
| 103 | + |
| 104 | +| type | default | version | |
| 105 | +| :--- | :--- | :--- | |
| 106 | +| time | 60 \(seconds\) | 0.14.1 | |
| 107 | + |
| 108 | +Time period in which the group line limit is applied. `in_tail_with_throttle` resets the line collected counter after every `rate_period` interval. |
| 109 | + |
| 110 | + |
| 111 | +### `<rule>` Directive \(required\) |
| 112 | + |
| 113 | +Specifies the rules and limits for a group. |
| 114 | + |
| 115 | + |
| 116 | +#### `namespace` |
| 117 | + |
| 118 | +| type | default | version | |
| 119 | +| :--- | :--- | :--- | |
| 120 | +| array | allow all files [\/.\/] | 0.14.1 | |
| 121 | + |
| 122 | +Namespace criteria to form rules. This parameter internally converts each string element in the array to a regexp so it can be used to generalize a list of namespaces. |
| 123 | + |
| 124 | +Examples: |
| 125 | +- This rule will apply to all files which have **monitoring** as a substring in their namespace. |
| 126 | + |
| 127 | +```text |
| 128 | +<rule> |
| 129 | + namespace monitoring |
| 130 | +</rule> |
| 131 | +``` |
| 132 | + |
| 133 | +- You can also specify multiple namespaces in your configuration file. |
| 134 | + |
| 135 | +```text |
| 136 | +<rule> |
| 137 | + namespace monitoring, logging |
| 138 | +</rule> |
| 139 | +``` |
| 140 | +#### `appname` |
| 141 | + |
| 142 | +| type | default | version | |
| 143 | +| :--- | :--- | :--- | |
| 144 | +| array | allow all files [\/.\/] | 0.14.1 | |
| 145 | + |
| 146 | +Appname criteria to form rules. This parameter, like `namespace`, internally converts each string element in the array to a regexp so it can be used to generalize a list of appnames. |
| 147 | + |
| 148 | +Examples: |
| 149 | +- This rule will apply to all files which have **heavy-stress** as a substring in their appname. |
| 150 | +```text |
| 151 | +<rule> |
| 152 | + appname heavy-stress |
| 153 | +</rule> |
| 154 | +``` |
| 155 | + |
| 156 | +- You can also specify multiple appnames in your configuration files. |
| 157 | + |
| 158 | +```text |
| 159 | +<rule> |
| 160 | + appname heavy-stress, backend-payment |
| 161 | +</rule> |
| 162 | +``` |
| 163 | + |
| 164 | + |
| 165 | +#### `limit` |
| 166 | + |
| 167 | +| type | default | version | |
| 168 | +| :--- | :--- | :--- | |
| 169 | +| integer | -1 | 0.14.1 | |
| 170 | + |
| 171 | +Maximum number of lines allowed from a group in `rate_period` time interval. The default value of `-1` doesn't throttle log files of that group. |
| 172 | + |
| 173 | + |
| 174 | +## Group Rules Example |
| 175 | + |
| 176 | +### Generic Rules |
| 177 | +This rule will assign files (that do not satisfy any rule) to a group limit of 100 lines. |
| 178 | + |
| 179 | +Example - |
| 180 | + |
| 181 | +```text |
| 182 | + <rule> |
| 183 | + limit 100 |
| 184 | + </rule> |
| 185 | +``` |
| 186 | + |
| 187 | +### Context-Specifc Rules |
| 188 | + |
| 189 | +#### Namespace based grouping |
| 190 | + |
| 191 | +This configuration will limit all files that have substring as **monitoring** present in their namespace, and will not check for appname in the filename. |
| 192 | + |
| 193 | +```text |
| 194 | +<rule> |
| 195 | + namespace monitoring |
| 196 | + limit 100 |
| 197 | +</rule> |
| 198 | +``` |
| 199 | + |
| 200 | +#### Appname based grouping |
| 201 | + |
| 202 | +Similarly, this configuration will limit all files containing 'frontend` substring present in their appname, and will not check for the namespace in the filename. |
| 203 | + |
| 204 | +```text |
| 205 | +<rule> |
| 206 | + appname frontend |
| 207 | + limit 200 |
| 208 | +</rule> |
| 209 | +``` |
| 210 | + |
| 211 | +#### Namespace and Appname based grouping |
| 212 | + |
| 213 | +Examples: |
| 214 | + |
| 215 | +- This rule will limit all files which have `monitoring` substring and `frontend` substring in namespace and appname fields, respectively. |
| 216 | + |
| 217 | +```text |
| 218 | + <rule> |
| 219 | + namespace monitoring |
| 220 | + appname frontend |
| 221 | + limit 50 |
| 222 | + </rule> |
| 223 | +``` |
| 224 | +- If we omit the `limit` parameter in a rule, then there will be no rate limiting applied to the files falling in that group. |
| 225 | + |
| 226 | +```text |
| 227 | + <rule> |
| 228 | + namespace monitoring |
| 229 | + appname frontend |
| 230 | + </rule> |
| 231 | +``` |
| 232 | + |
| 233 | +- When using multiple namespaces and appnames in a single rule, the group line limits are distributed uniformly. |
| 234 | + |
| 235 | + |
| 236 | +```text |
| 237 | +<rule> |
| 238 | + namespace monitoring, logging |
| 239 | + appname frontend, backend |
| 240 | + limit 4000 |
| 241 | +</rule> |
| 242 | +``` |
| 243 | + |
| 244 | +The list of groups formed from this rule are: |
| 245 | + |
| 246 | +| Namespace | Appname | Group Limit | |
| 247 | +|:------------: |:----------: |:-----------: | |
| 248 | +| /monitoring/ | /frontend/ | 1000 | |
| 249 | +| /monitoring/ | /backend/ | 1000 | |
| 250 | +| /logging/ | /frontend/ | 1000 | |
| 251 | +| /logging/ | /backend/ | 1000 | |
| 252 | + |
| 253 | +## FAQ |
| 254 | + |
| 255 | +### What happens when a file can be assigned to both, context-specific and generic rules? |
| 256 | + |
| 257 | +By default, context-specific rules always precede generic rule applied to default group. Hence the file will be assigned to context-specific rule. |
| 258 | + |
| 259 | +### What happens when we have the same rule repeated in the configuration file? |
| 260 | + |
| 261 | +Example, |
| 262 | + |
| 263 | +```text |
| 264 | + <rule> |
| 265 | + namespace monitoring |
| 266 | + appname logger |
| 267 | + limit 100 |
| 268 | + </rule> |
| 269 | +
|
| 270 | + <rule> |
| 271 | + namespace monitoring |
| 272 | + appname logger |
| 273 | + limit 2000 |
| 274 | + </rule> |
| 275 | +``` |
| 276 | + |
| 277 | +In this case, limits are overridden by `in_tail_with_throttle` Input Plugin. So, the final limit of the group for namespace `monitoring` and appname `logger` will be 2000. |
| 278 | + |
| 279 | +### Can we run `tail` and `tail_with_throttle` simultaneously ? |
| 280 | + |
| 281 | +Yes, we can run both input plugins simultaneously. |
0 commit comments