diff --git a/docs/logs.md b/docs/logs.md index f11945c733b618781fd4f8c00bf051bae601cbdc..b791898c64983b351e4c3cbf27a2288ce0bd8b49 100644 --- a/docs/logs.md +++ b/docs/logs.md @@ -101,6 +101,21 @@ outputs: | http_passwd {{ .Values.tenant.password }} ``` +### Fluentbit Custom Lua Scripts +In Fluent Bit we can use Lua scripts to create processors that transform the records. These scripts are available in the Fluent Bit container under the path `/fluent-bit/etc/scripts`. In order to create new Lua scripts just add them in the values `logs.fluentbit.luaScripts` key. + +For example, the following configuration will create two files in `/fluent-bit/etc/scripts`. One named `my_lua_script.lua` and another one named `my_lua_script2.lua`. +```yaml +luaScripts: + my_lua_script.lua: | + function my_function(tag, timestamp, record) + // Do something... + return 2, timestamp, record + end + my_other_lua_script.lua: | + ... +``` + ## 3. Customizing Fluentbit for Additional Log Sources You can extend the logging configuration by extending previous configurations with custom Fluentbit **inputs**, **filters**, or **outputs**. This is especially useful if you want to gather logs from additional sources or apply different processing to specific logs. diff --git a/docs/metrics.md b/docs/metrics.md index 938a83303268c95e104a18ea2a4812c4dce46cf9..38c55c0854c1d18830fb6448de814ca31f1d4596 100644 --- a/docs/metrics.md +++ b/docs/metrics.md @@ -121,8 +121,30 @@ metrics: regex: ".*_unwanted_metric" ``` +## 4. Pushing Metrics to Central Monitoring Infrastructure +By default the Helm chart uses a dedicated Fluent Bit to upload the metrics to the Central Monitoring Infrastructure via OpenTelemetry protocol. -## 4 . Further Customizations +This Fluent Bit already has a default configuration for the inputs, filters and outputs. Please, check the `values.yaml` to see the default configuration. + +Besides these basic configuration options, others are also offered. + +### Fluentbit Custom Lua Scripts +In Fluent Bit we can use Lua scripts to create processors that transform the records. These scripts are available in the Fluent Bit container under the path `/fluent-bit/etc/scripts`. In order to create new Lua scripts just add them in the values `logs.fluentbit.luaScripts` key. + +For example, the following configuration will create two files in `/fluent-bit/etc/scripts`. One named `my_lua_script.lua` and another one named `my_lua_script2.lua`. +```yaml +luaScripts: + my_lua_script.lua: | + function my_function(tag, timestamp, record) + // Do something... + return 2, timestamp, record + end + my_other_lua_script.lua: | + ... +``` + + +## 5. Further Customizations You can further customize metrics collection with the following settings: diff --git a/templates/fluentbit-logs/scripts.yaml b/templates/fluentbit-logs/configmap-luascripts.yaml similarity index 74% rename from templates/fluentbit-logs/scripts.yaml rename to templates/fluentbit-logs/configmap-luascripts.yaml index 954535c174fe45ce5668666b39e6504e8305e845..916c74d7b184c3f80573666f781bf0eba707d3af 100644 --- a/templates/fluentbit-logs/scripts.yaml +++ b/templates/fluentbit-logs/configmap-luascripts.yaml @@ -12,4 +12,9 @@ data: record['timestamp'] = exp_sec * 1000 return 2, timestamp, record end -{{- end -}} + {{- if .Values.logs.fluentbit.luaScripts -}} + {{ range $key, $value := .Values.logs.fluentbit.luaScripts }} + {{ $key }}: {{ $value | quote }} + {{ end }} + {{ end }} +{{- end -}} \ No newline at end of file diff --git a/templates/fluentbit-metrics/configmap-luascripts.yaml b/templates/fluentbit-metrics/configmap-luascripts.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ea6f6a894a8bf28b17a9118efa70b00d56d49913 --- /dev/null +++ b/templates/fluentbit-metrics/configmap-luascripts.yaml @@ -0,0 +1,12 @@ +{{- if and .Values.metrics.enabled .Values.metrics.fluentbit.enabled .Values.metrics.fluentbit.luaScripts -}} +apiVersion: v1 +kind: ConfigMap +metadata: + name: it-monit-metrics-collector-fluentbit-scripts +data: + {{- if .Values.metrics.fluentbit.luaScripts -}} + {{ range $key, $value := .Values.metrics.fluentbit.luaScripts }} + {{ $key }}: {{ $value | quote }} + {{ end }} + {{ end }} +{{- end -}} \ No newline at end of file diff --git a/templates/fluentbit-metrics/statefulset.yaml b/templates/fluentbit-metrics/statefulset.yaml index 32eff7768621b8aa3820ba87033168870b4bb4ae..1a757ee3c7bfaf0c3d8895469a315fcbf7593cb4 100644 --- a/templates/fluentbit-metrics/statefulset.yaml +++ b/templates/fluentbit-metrics/statefulset.yaml @@ -33,6 +33,10 @@ spec: volumeMounts: - name: config mountPath: /fluent-bit/etc/conf + {{- if .Values.metrics.fluentbit.luaScripts -}} + - name: scripts + mountPath: /fluent-bit/etc/scripts + {{- end }} - name: fluentbit mountPath: /flb-storage/ {{- if .Values.metrics.fluentbit.extraVolumeMounts }} @@ -46,6 +50,11 @@ spec: - name: config configMap: name: it-monit-metrics-collector-fluentbit + {{- if .Values.metrics.fluentbit.luaScripts -}} + - name: scripts + configMap: + name: it-monit-metrics-collector-fluentbit-scripts + {{- end }} - name: fluentbit emptyDir: sizeLimit: {{ .Values.metrics.fluentbit.diskMaxCache }} diff --git a/values.yaml b/values.yaml index 15c15805f75dec08e348e5229079305802c45c81..960930d1fc021516f920f8e2884465539b5edb98 100644 --- a/values.yaml +++ b/values.yaml @@ -158,6 +158,17 @@ metrics: uri: /api/prom/push threaded: false + # These scripts are available in the fluentbit /fluent-bit/etc/scripts path. + # Include your lua scripts in the following format: + # luaScripts: + # my_lua_script.lua: | + # function my_function(tag, timestamp, record) + # // Do something... + # return 2, timestamp, record + # end + # my_other_lua_script.lua: ... + luaScripts: {} + # -- max size for in-disk storage for fluent-bit diskMaxCache: "5G" @@ -412,3 +423,14 @@ logs: extraVolumes: [] ## -- extra volumes to mount in the fluentbits, can be used to scrape metrics from pvcs extraVolumeMounts: [] + + # These scripts are available in the fluentbit /fluent-bit/etc/scripts path. + # Include your lua scripts in the following format: + # luaScripts: + # my_lua_script.lua: | + # function my_function(tag, timestamp, record) + # // Do something... + # return 2, timestamp, record + # end + # my_other_lua_script.lua: ... + luaScripts: {}