Forem

Cover image for Como monitorar o Prometheus com Metricbeat
Beatriz Oliveira for Sysadminas

Posted on

3 3

Como monitorar o Prometheus com Metricbeat

O que é o Prometheus?

O Prometheus é uma ferramenta de monitoramento de métricas e indicadores de aplicações e serviços. 

Segundo a descrição no Github do Prometheus:

"Ele coleta as métricas dos pontos configurados em intervalos dados, avalia expressões das regras, exibe os resultados e também pode acionar alertas quando as condições especificadas são observadas como verdadeiras."

Para saber mais sobre o projeto, acesse o site oficial do Prometheus.

Como monitorar o Prometheus utilizando o Metricbeat?

Para começar esse lab, você precisará ter um ambiente com o Prometheus e outro ambiente com o Elasticsearch e com o Kibana configurados.

Assim que você tiver esses pré requisitos, poderá começar a seguir os passos abaixo para configurar o Metricbeat para coletar os dados do Prometheus.

Para instalar o Metricbeat no host do Prometheus, siga os passos descritos abaixo.

  • Faça o download do Metricbeat nesse link.

  • Instale o Metricbeat:
    Windows: PowerShell.exe -ExecutionPolicy UnRestricted -File .\install-service-metricbeat.ps1
    Linux: sudo rpm -vi metricbeat-7.10.1-x86_64.rpm

  • Acesse o arquivo de configuração do Metricbeat:
    Windows: C:\Program Files\Metricbeat\metricbeat.yml
    Linux: /etc/metricbeat/metricbeat.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
  • Se você estiver usando o Metricbeat OSS insira as seguintes configurações no fim do arquivo metricbeat.yml.
setup.ilm.enabled: false
setup.pack.security.enabled: false
setup.xpack.graph.enabled: false
setup.xpack.watcher.enabled: false
setup.xpack.monitoring.enabled: false
setup.xpack.reporting.enabled: false
Enter fullscreen mode Exit fullscreen mode
  • Habilite e configure o módulo do Prometheus:
    Windows: .\metricbeat.exe modules enable prometheus
    Linux: sudo metricbeat modules enable prometheus

  • Para modificar as configurações do módulo, altere o arquivo prometheus.yml:
    Windows: modules.d/prometheus.yml
    Linux: /etc/metricbeat/modules.d/prometheus.yml

Por padrão, o arquivo vem assim:

# Module: prometheus
# Docs: https://www.elastic.co/guide/en/beats/metricbeat/7.8/metricbeat-module-prometheus.html
# Metrics collected from a Prometheus endpoint
- module: prometheus
  period: 10s
  metricsets: ["collector"]
  hosts: ["localhost:9090"]
  metrics_path: /metrics
  #metrics_filters:
  #  include: []
  #  exclude: []
  #username: "user"
  #password: "secret"
# This can be used for service account based authorization:
  #bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
  #ssl.certificate_authorities:
  #  - /var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt
# Metrics sent by a Prometheus server using remote_write option
#- module: prometheus
#  metricsets: ["remote_write"]
#  host: "localhost"
#  port: "9201"
# Secure settings for the server using TLS/SSL:
  #ssl.certificate: "/etc/pki/server/cert.pem"
  #ssl.key: "/etc/pki/server/cert.key"
# Metrics that will be collected using a PromQL
#- module: prometheus
#  metricsets: ["query"]
#  hosts: ["localhost:9090"]
#  period: 10s
#  queries:
#  - name: "instant_vector"
#    path: "/api/v1/query"
#    params:
#      query: "sum(rate(prometheus_http_requests_total[1m]))"
#  - name: "range_vector"
#    path: "/api/v1/query_range"
#    params:
#      query: "up"
#      start: "2019-12-20T00:00:00.000Z"
#      end:  "2019-12-21T00:00:00.000Z"
#      step: 1h
#  - name: "scalar"
#    path: "/api/v1/query"
#    params:
#      query: "100"
#  - name: "string"
#    path: "/api/v1/query"
#    params:
#      query: "some_value"
Enter fullscreen mode Exit fullscreen mode
  • Carregue os dashboards do módulo:
    Windows: .\metricbeat.exe setup
    Linux: sudo metricbeat setup

  • Inicie o serviço do Metricbeat:
    Windows: Start-Service metricbeat
    Linux: sudo service metricbeat 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 estado do seu Prometheus.

Métricas
Alt Text

Logs
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)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay