node-exporter

node-exporter 구성

image

  graph LR
  subgraph gvp6nx1a
  A1[host] --> E2
  E2[node-exporter] -- http --> A3[prometheus]
  end
  A2[host] --> E3
  E3[node-exporter] -- https --> A3

container 구성

docker-compose.yml

수집 데이터에 접근하기 위해 host 모드로 구성

vi /opt/node-exporter/docker-compose.yml
services:
  node-exporter:
    image: prom/node-exporter:latest
    container_name: node-exporter
    network_mode: host
    pid: host
    user: 1000:1000
    volumes:
      - /:/rootfs:ro
      - /proc:/rootfs/proc:ro
      - /sys:/rootfs/sys:ro
      - /run/udev/data:/run/udev/data:ro
      - /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket:ro
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
      - /opt/node-exporter/config/web.yml:/etc/web.yml:rw
    command:
      - --web.config.file=/etc/web.yml
      - --path.rootfs=/rootfs
      - --path.procfs=/rootfs/proc
      - --path.sysfs=/rootfs/sys
      - --collector.filesystem.mount-points-exclude=^/(rootfs/)?(dev|etc|proc|run|sys)($$|/)
      - --collector.processes
      - --collector.systemd
      - --collector.interrupts
    restart: unless-stopped

web.yml

http basic auth 구성

pip install bcrypt && \
tee ~/gen-password.py <<EOF
import getpass
import bcrypt

password = getpass.getpass("password: ")
hashed_password = bcrypt.hashpw(password.encode("utf-8"), bcrypt.gensalt())
print(hashed_password.decode())
EOF
python3 ~/gen-password.py
password:
$***********************************************************
pip uninstall -y bcrypt && rm ~/gen-password.py && \
tee /opt/node-exporter/config/web.yml <<EOF
basic_auth_users:
  dev: $***********************************************************
EOF

host 구성

proxy 구성

특정 ip만 허용하도록 구성

vi /opt/nginx/config/sites-available/node-exporter.conf
...
  location / {
    include                /etc/nginx/conf.d/include/proxy.conf;
    proxy_pass             http://host.docker.internal:9100;
    proxy_intercept_errors on;
    allow                  192.168.0.0/16;
    allow                  2**.**.**.*;   #sj9n7air
    allow                  1**.***.**.**; #gvp6nx1a
    deny                   all;
  }
...

Troubleshooting