DEV Community

Beatriz Oliveira for Sysadminas

Posted on

1

Como coletar logs do PostgreSQL com o Filebeat

O que é o PostgreSQL?

O PostgreSQL é um Sistema Gerenciador de Bancos de Dados (SGBD) open source.

Para conhecer mais sobre ele, recomendo a leitura do post Introdução ao PostgreSQL do DevMedia nesse link.

Aqui no nosso blog, a Renata Azevedo mostra como configurar um cluster de PostgreSQL e você pode ver esse tutorial nesse link.

Utilizando o Filebeat para coletar os logs do PostgreSQL

Ao utilizar o módulo PostgreSQL do Filebeat você consegue coletar e analisar os logs do PostgreSQL.

Para saber mais sobre esse módulo, acesse a documentação aqui nesse link

Instalação e configuração do Filebeat

  • Instale o Filebeat:

Windows: PowerShell.exe -ExecutionPolicy UnRestricted -File .\install-service-filebeat.ps1
Linux: sudo rpm -vi filebeat-7.10.1-x86_64.rpm

  • Acesse o arquivo de configuração do Filebeat:

Windows: C:\Program Files\Filebeat\filebeat.yml
Linux: /etc/filebeat/filebeat.yml

Insira nele as informações de conexão com o Elasticsearch e com o Kibana:

output.elasticsearch:
  hosts: ["url_do_elasticsearch:9200"]
setup.kibana:
  host: ["url_do_kibana:5601"]
Enter fullscreen mode Exit fullscreen mode
  • Habilite e configure o módulo :
    Windows: .\filebeat.exe modules enable postgresql
    Linux: sudo filebeat modules enable postgresql

  • Para modificar as configurações do módulo, altere o arquivo postgresql.yml:

Windows: modules.d/postgresql.yml
Linux: /etc/filebeat/modules.d/postgresql.yml

Por padrão, o arquivo vem com as seguintes informações e é aqui que você especifica o caminho para o seu diretório de logs:

# Module: postgresql
# Docs: https://www.elastic.co/guide/en/beats/filebeat/7.7/filebeat-module-postgresql.html
- module: postgresql
  # All logs
  log:
    enabled: true
# Set custom paths for the log files. If left empty,
    # Filebeat will choose the paths depending on your OS.
    #var.paths: ["/diretório/do/log/postgresql/*.log*"]
Enter fullscreen mode Exit fullscreen mode
  • Carregue o índice e os dashboards do módulo:

Windows: .\filebeat.exe setup
Linux: sudo filebeat setup

  • Inicie o serviço do Filebeat:

Windows: Start-Service filebeat
Linux: sudo service filebeat start

Depois disso, você conseguirá ver os logs do seu ambiente no discover, além de ter dashboards com informações e métricas do seu PostgreSQL.

Alt Text

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay