DEV Community

Cover image for Monitorando sua máquina com o Prometheus
Gabriel Tetzner Menegueti
Gabriel Tetzner Menegueti

Posted on • Edited on

5 4

Monitorando sua máquina com o Prometheus

Sobre

Tutorial desenvolvido para o monitoramento de recursos de uma máquina, utilizando um exportador do prometheus (node exporter).

Dependências e tecnologias

Badge

Badge

Badge

Configurações

Atualize os repositórios

$ sudo apt update
Enter fullscreen mode Exit fullscreen mode

Instale Docker e Docker-compose

$ sudo apt install docker.io
$ sudo apt install docker-compose
Enter fullscreen mode Exit fullscreen mode

Crie um diretório do arquivo docker-compose

$ sudo mkdir docker
Enter fullscreen mode Exit fullscreen mode

Crie o arquivo do docker-compose

$ cd docker
$ touch docker-compose.yml
Enter fullscreen mode Exit fullscreen mode

Abre o arquivo e cole a seguinte configuração

version: '3'
services:
  prometheus:
    image: prom/prometheus:latest
    container_name: prometheus
    ports:
    - 9090:9090
    command:
    - --config.file=/etc/prometheus/prometheus.yml
    volumes:
    - /etc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
    restart: always

  grafana:
    image: grafana/grafana:latest
    container_name: grafana-server
    user: "1000"
    environment:
    - GF_SECURITY_ADMIN_PASSWORD=tutorial2022
    depends_on:
    - prometheus
    ports:
    - 3000:3000
    restart: always

  node-exporter:
    image: prom/node-exporter
    container_name: node-exporter
    restart: always
    ports: 
    - 9100:9100
Enter fullscreen mode Exit fullscreen mode

Crie o diretório do arquivo de configuração Prometheus

$ sudo mkdir /etc/prometheus
Enter fullscreen mode Exit fullscreen mode

Depois crie o arquivo de configuração do Prometheus

$ sudo touch /etc/prometheus/prometheus.yml
Enter fullscreen mode Exit fullscreen mode

Abre o arquivo e cole a seguinte configuração

global:
    scrape_interval: 5s
    evaluation_interval: 5s
scrape_configs:
  - job_name: 'prometheus'
    scrape_interval: 5s
    static_configs:
         - targets: ['yourip:9090']
    metrics_path: "/metrics"

  - job_name: node-exporter
    scrape_interval: 5s
    static_configs:
         - targets: ['yourip:9100']
    metrics_path: "/metrics"
Enter fullscreen mode Exit fullscreen mode

Cheque seu IP

$ ifconfig
Enter fullscreen mode Exit fullscreen mode

Com seu editor de texto preferido mude o IP na configuração do prometheus

$ sudo nano /etc/prometheus/prometheus.yml
Enter fullscreen mode Exit fullscreen mode

Levante os container's no diretório docker

$ sudo docker-compose up -d
Enter fullscreen mode Exit fullscreen mode

Cheque se Server Prometheus foi levantado

Cheque se o Grafana Server foi levantado

Verificação

Verificação Prometheus

  • Coloque as configurações de seu endereço de servidor Prometheus.
  • Endereço do servidor: http://seuip:9090
  • Salve as configurações.

Verificação Grafana

Acesse o dashboard do node exporter e faça o download

Billboard image

The fastest way to detect downtimes

Join Vercel, CrowdStrike, and thousands of other teams that trust Checkly to streamline monitoring.

Get started now

Top comments (1)

Collapse
 
edgardcunha profile image
Edgard da Cunha Pontes

Parabéns Gabriel! Excelente tutorial!

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay