Para a utilização do Agente https://fluentbit.io/ recebendo dados da integração [LogClient] .


O fluxo abaixo exemplifica bem o processo:



Processo de Configuração



  1. Instalar o TD-Agent( FluentBit) na maquina Linux que irá se comunicar com o servidor FluentBit;
    1. Instalação do TD-Agent →
        1. # Importar a chave GPG do Fluent Bit
          sudo rpm --import https://packages.fluentbit.io/fluentbit.key
        2. # Criar o arquivo de repositório
          sudo tee /etc/yum.repos.d/fluentbit.repo <<EOF
          [fluentbit]
          name=Fluent Bit
          baseurl=https://packages.fluentbit.io/centos/8
          gpgcheck=1
          gpgkey=https://packages.fluentbit.io/fluentbit.key
          enabled=1
          EOF
        3. # Instalar o TD-Agent
          dnf install td-agent-bit

        4. #Editar o arquivo:

          /etc/td-agent-bit/td-agent-bit.conf

          E acrescentar essas regras:


          [SERVICE]
              flush        5
              daemon       Off
              log_level    info
              parsers_file parsers.conf
              plugins_file plugins.conf
              http_server  On
              http_listen  0.0.0.0
              http_port    2020
              storage.metrics on
              storage.path /tmp/storage
              storage.sync normal
              storage.checksum on
              storage.backlog.mem_limit 1G
          
          [INPUT]
              Name        tcp
              Listen      0.0.0.0
              Port        5140
              Tag         udp.logs
              Format      none
              Buffer_Size 256KB
          
          [FILTER]
              Name          lua
              Match         udp.logs
              script        /etc/td-agent-bit/processa_log.lua
              call          parse_logmsg
          
          [OUTPUT]
              name        http
              match       udp.logs
              host        <url>
              port        443
              uri         /ProtheusProduction.logs
              format      json
              tls         On
              tls.verify  On
              http_User   <user>
              http_Passwd <password>
              Retry_Limit 5
              net.connect_timeout 15s
              net.keepalive true
              net.keepalive_idle_timeout 60s
              workers     4
              compress    gzip
            
        5. #Criar um arquivo: /etc/td-agent-bit/processa_log.lua

          function parse_logmsg(tag, timestamp, record)
              if not record["log"] then
                  return 0, timestamp, record
              end
          
              local log = record["log"]
          
              -- Remove espaços duplos
              local final_log = ""
              local space_found = false
              for i = 1, #log do
                  local c = log:sub(i, i)
                  if c ~= " " then
                      final_log = final_log .. c
                      space_found = false
                  elseif not space_found then
                      final_log = final_log .. c
                      space_found = true
                  end
              end
          
              -- Remover aspas escapadas do final_log
              final_log = final_log:gsub('\\"', '"')
          
              -- Capturar a parte entre '|'
              local keyValuePart = final_log:match("|(.*)|")
              if keyValuePart then
                  local parts = split_string(keyValuePart, "|")
                  for _, part in ipairs(parts) do
                      local field, value = part:match("([^=]+)=([^=]+)")
                      if field and value then
                          -- Remover aspas escapadas dos valores
                          value = value:gsub('\\"', '"')
                          -- Tentar converter números para tipo numérico
                          local num_value = tonumber(value)
                          if num_value then
                              record[field:trim()] = num_value
                          else
                              record[field:trim()] = value:trim()
                          end
                      else
                          if part:trim() == "Tabela" and not value then
                              record["Tabela"] = "_"
                          end
                      end
                  end
          
                  if not record["Tabela"] or record["Tabela"] == '' or record["Tabela"] == null then
                      record["Tabela"] = "_"
                  end
          
                  local valueBeforePipe = final_log:match("^(.-)%s*|")
                  if valueBeforePipe then
                      local date, machineName, machineIp, year, routine, routineId = valueBeforePipe:match(
                          "^(%a+ %d+ %d+:%d+:%d+) (%w+)%(([%d%.]+)%)%((%d+)%) (%a+)%[(%d+)%]$")
          
                      record["MachineName"] = machineName
                      record["MachineIp"] = machineIp
                      record["Routine"] = routine
                      record["RoutineId"] = routineId
                  end
          
                  if record["Data"] and (not record["HoraAtualizacao"] or not record["HoraAlteracao"]) then
                      if not record["HoraAtualizacao"] then
                          record["HoraAtualizacao"] = record["Data"]
                      end
                      if not record["HoraAlteracao"] then
                          record["HoraAlteracao"] = record["Data"]
                      end
                  end
              else
                  record["error"] = "Formato de log inválido"
              end
          
              return 1, timestamp, record
          end
          
          -- Função para dividir strings
          function split_string(input, delimiter)
              local result = {}
              for match in (input .. delimiter):gmatch("(.-)" .. delimiter) do
                  table.insert(result, match)
              end
              return result
          end
          
          -- Função auxiliar para remover espaços em branco
          function string:trim()
              return self:match("^%s*(.-)%s*$")
          end
          
          


        6. Reiniciar Serviço:
          systemctl stop td-agent-bit
          systemctl start td-agent-bit