
در بخش قبل کانفیگ forwarder بررسی گردید و در این بخش تنظیمات aggregator مورد بررسی قرار می گیرد.
یک نمونه از کانفیگ aggregator به صورت زیر می باشد:
# Ignore fluentd own events <match fluent.**> @type null </match> @include fluentd-inputs.conf @include fluentd-output.conf {{- if .Values.metrics.enabled }} @include metrics.conf {{- end }} fluentd-inputs.conf: | # TCP input to receive logs from <source> @type forward bind 0.0.0.0 port 24224 </source> # HTTP input for the liveness and readiness probes <source> @type http bind 0.0.0.0 port 9880 </source> fluentd-output.conf: | # Throw the healthcheck to the standard output <match fluentd.healthcheck> @type stdout </match> # Send the logs to the standard output <match **> @type elasticsearch include_tag_key true host eck-es-http.logs.svc port 9200 user elastic password password logstash_format false index_name fluentd-${tag} logstash_prefix fluentd target_index_affinity true include_timestamp true deflector_alias fluentd-${tag} rollover_index true application_name example template_name fluentd-${tag} template_file /voho/template customize_template {"<<TAG>>":"fluentd-${tag}"} template_overwrite true </match> metrics.conf: | # Prometheus Exporter Plugin # input plugin that exports metrics <source> @type prometheus port {{ .Values.metrics.service.port }} </source> # input plugin that collects metrics from MonitorAgent <source> @type prometheus_monitor <labels> host ${hostname} </labels> </source> # input plugin that collects metrics for output plugin <source> @type prometheus_output_monitor <labels> host ${hostname} </labels> </source
حال در زیر به جزئیات کانفیگ فوق می پردازیم:
<source> @type forward bind 0.0.0.0 port 24224 </source> # HTTP input for the liveness and readiness probes <source> @type http bind 0.0.0.0 port 9880 </source>
این بخش از تنظیمات منابع ورودی لاگ های را مشخص می کند که اولی از لاگ های forwarder ها که به پورت ۲۴۲۲۴ سرویس fluentd aggregator ارسال می کردند و دومی هم لاگ ها readiness و liveness استفاده می کنند.
<match **> @type elasticsearch include_tag_key true host eck-es-http.logs.svc port 9200 user username password password logstash_format false index_name fluentd-${tag} logstash_prefix fluentd target_index_affinity true include_timestamp true deflector_alias fluentd-${tag} rollover_index true application_name example template_name fluentd-${tag} template_file /voho/template customize_template {"<<TAG>>":"fluentd-${tag}"} template_overwrite true </match>
افزونه elasticsearch برای برای ارتباط برقرار کردن بین fluentd و elasticsearch می باشد که در مشخص می کند لاگ به چه index و با چه زمانی و ... به سمت elastic ارسال گردد.
معیین می کند که tag به عنوان یک فیلد در لاگ های ارسالی وجود داشته باشد یا خیر.
آدرس elasticsearch را مشخص می کند. (اگر الستیک داخل کلاستر می باشد می توان آدرس سرویس را داد و گر نه باید ادرس url الستیک داده شود.)
نحوه تعیین آدرس سرویس به صورت servicename>-<namespace>.svc> می باشد.
شماره port الستیک را مشخص می کند.
مقدار username الستیک را می گیرد.
مقدار password الستسک را می گیرد.
معین می کند که اسم index در الستیک فرمت logstash (indexname-date) را داشته باشند یا خیر.
اسم index ساخته شده در الستیک را معین می کند.
مقداری که به اول indexname اضافه می شود (در rollover کردن) را مشخص می کند.
4
معین می کند که در زمانی که index ها با تگ تاریخ ساخته می شوند اگر index روز های قبل به مقدار حجم حداکثر نرسیده باشد داده ها در همان index ذخیره شوند
مزیت این کار این می باشد که تعداد index ها کم می شود م سرعت جستوجو افزایش می یابد.
معین می کند که فیلد timestamp در لاگ ها وجود داشته باشند یا خیر.
با فعال کردن این بخش داده ها با فرمت اسم index به صورت <target_index-application_name-{index_date_pattern}-000001> ذخیره می شوند.
اگر یک index نیازمند rollover باشد باید یک alias برای آن تعریف گردد که این گزینه آن را برای index ها مشخص می کند.
این قسمت در rollover استفاده می شود.
برای این که برای هر لاگ با tag مشخص template به صورت خودکار ساخته شود می توان یک فایل template مشخص کرد که برای index آن لاگ ها template را اضافه کند.
محل فایل template را در pod fluentd مشخص می کند.
یک نمونه از فایل template در اخر کانفیگ آورده شده است.
برای این که در فایل template تعریف شده مقداری به صورت ثابت یا متغیر تعریف شوند از این بخش استفاده می شود.
به عنوان مثال در فایل template مقدار tag به صورت متغییر تعریف شده است که در این بخش مقدار tag از لاگ ها گرفته می شود.
معین می کند اگر در فایل template اگر تغییری داشتیم در template های ساخته شده اعمال شود یا خیر.
{ "order": 100, "index_patterns": [ "<<TAG>>-*" ], "settings": { "index": { "lifecycle": { "name": "ILM", "rollover_alias": "<<TAG>>" }, "refresh_interval": "15s", "number_of_shards": "1", "number_of_replicas": "1" } }, "aliases": { "all-<<TAG>>": {} } }
این فایل باید در image aggregator قرار گیرد که می توان یک dockerfile ایجاد کرده و آن را build کرد:
FROM docker.io/bitnami/fluentd:1.14.4-debian-10-r11 USER root RUN mkdir /example COPY template /example/template