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

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

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

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay