Prometheus with Docker Container

Lยท2022๋…„ 10์›” 24์ผ
0
post-thumbnail
post-custom-banner

๋…์ž ๋Œ€์ƒ๐Ÿ“ฃ

๐Ÿ‘‰ Prometheus๋กœ ์‹œ์Šคํ…œ ๋ฉ”ํŠธ๋ฆญ์„ ๋ชจ๋‹ˆํ„ฐ๋ง ํ•˜์‹œ๋ ค๋Š” ๋ถ„
๐Ÿ‘‰ node_exporter๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋งคํŠธ๋ฆญ์„ ์ถ”์ถœํ•˜์‹œ๋ ค๋Š” ๋ถ„
๐Ÿ‘‰ Ubuntu ํ™˜๊ฒฝ์—์„œ ๊ตฌ์ถ•ํ•˜์‹œ๋Š” ๋ถ„


์ถœ๊ฐ„ ์ด์œ โ“

Docker(swarm) Container ๊ธฐ๋ฐ˜ Prometheus ๊ตฌ์ถ• ์‹œ, ์„œ๋น„์Šค ๋“ฑ๋ก ๋ถˆ๊ฐ€ ํ˜„์ƒ ํ™•์ธ


๋ฌธ์ œ ํŒŒ์•…๐Ÿ”

# systemctl ์ปค๋งจ๋”ฉ ์˜ค๋ฅ˜
$ sytemctl daemon-reload
System has not been booted with systemd as init system (PID 1). Can't operate.
Q: Prometheus๋ฅผ Docker Container ๊ธฐ๋ฐ˜์œผ๋กœ ๊ตฌ์ถ•ํ•˜๋ ค๋Š”๋ฐ
   Systemctl ์ปค๋งจ๋”ฉ์ด ์ •์ƒ ์ž‘๋™ํ•˜์ง€ ์•Š์•„์„œ
   Prometheus ์„œ๋น„์Šค ๋“ฑ๋ก์ด ๋ถˆ๊ฐ€ํ•ฉ๋‹ˆ๋‹ค..๐Ÿ˜ฅ

๋ฌธ์ œ ํ•ด๊ฒฐ๐ŸŽŠ

A: Docker Container๋Š” Unprivileged ๋ชจ๋“œ๊ฐ€ default๊ฐ’์ž…๋‹ˆ๋‹ค.
   ์ด ๋ชจ๋“œ๋Š” ์‹œ์Šคํ…œ์˜ ๋ฉ”์ธ ๋ฆฌ์†Œ์Šค์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋Š” ๊ถŒํ•œ์ด
   ๋ถ€์กฑํ•˜์—ฌ, ์‹œ์Šคํ…œ ์ž์› ์ ‘๊ทผ์ด ๋ถˆ๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.
   
   ๋”ฐ๋ผ์„œ ์šฐ๋ฆฌ๋Š” Docker Container๋ฅผ Privileged ๋ชจ๋“œ๋กœ
   ์‹คํ–‰ํ•ด์•ผํ•  ํ•„์š”๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

   ํ•˜์ง€๋งŒ, ๋งŒ์•ฝ ์ด๋ ‡๊ฒŒ ์‰ฝ๊ฒŒ ํ•ด๊ฒฐ๋œ๋‹ค๋ฉด 
   ์ด ๊ธ€์„ ์ถœ๊ฐ„ํ•˜์ง€ ์•Š์•˜์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค๐Ÿ˜‚
   
   ๊ฐ„ํ˜น, privileged ์˜ต์…˜์ด๋‚˜ /init ์˜ต์…˜์„ ์ ์šฉํ•ด๋„
   ์œ„ ๋ฌธ์ œ๊ฐ€ ํ•ด๊ฒฐ๋˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹คโ—โ—

   ํ•˜๋‹จ์˜ ๋‚ด์šฉ์„ ์ฐธ๊ณ ํ•˜์—ฌ ์ด Disgustingํ•œ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜์‹ญ์‹œ์˜คโ—โ—
   
   (์ด ๊ธ€์€ Prometheus ์„ค์ • ํŒŒ์ผ์ด ์ด๋ฏธ ๋ณผ๋ฅจ ๋ฐ”์ธ๋”ฉ๋˜์—ˆ๋‹ค๋Š”
   ๊ฒƒ์„ ์ „์ œ๋กœ ์ž‘์„ฑ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.)
  1. node_exporter ์ตœ์‹  ๋ฒ„์ „ ํ™•์ธ
    # node exporter์˜ ์ตœ์‹ ๋ฒ„์ „ ํ™•์ธ ํ›„, ๋‹ค์šด๋กœ๋“œ ๋งํฌ ํ™•๋ณด
    # ํ˜„ ์‹œ์ , 1.4.0์ด ์ตœ์‹  ๋ฒ„์ „
    https://github.com/prometheus/node_exporter/releases/download/v1.4.0/node_exporter-1.4.0.linux-amd64.tar.gz
  2. node_exporter ๊ตฌ๋™ ์‰˜ ํŒŒ์ผ ์ž‘์„ฑ
    # ๋กœ์ปฌ ์ž‘์„ฑ ๋ฒ„์ „
    $ vi prom_node_exporter.sh
    #!/usr/bin/env bash
    container_name=`docker ps -q | xargs -n 1 docker inspect --format '{{ .Name }} {{range .NetworkSettings.Networks}} {{.IPAddress}}{{end}}' | sed 's#^/##' | grep [ํ”„๋กœ์ ํŠธ๋ช…] | cut -d " " -f1`
    docker exec -i $container_name wget -P /opt https://github.com/prometheus/node_exporter/releases/download/v1.4.0/node_exporter-1.4.0.linux-amd64.tar.gz
    docker exec -i $container_name tar xvzf /opt/node_exporter-1.4.0.linux-amd64.tar.gz -C /opt/
    docker exec -i $container_name rm -rf /opt/node_exporter-1.4.0.linux-amd64.tar.gz
    docker exec -i $container_name /opt/node_exporter-1.4.0.linux-amd64/node_exporter --web.listen-address=:3010 &
    
    # ์ปจํ…Œ์ด๋„ˆ ๋‚ด๋ถ€ ์ž‘์„ฑ ๋ฒ„์ „
    $ vi prom_mode_exporter.sh
    #!/bin/bash
    wget -P /opt https://github.com/prometheus/node_exporter/releases/download/v1.4.0/node_exporter-1.4.0.linux-amd64.tar.gz
    tar xvzf /opt/node_exporter-1.4.0.linux-amd64.tar.gz -C /opt/
    rm -rf /opt/node_exporter-1.4.0.linux-amd64.tar.gz
    /opt/node_exporter-1.4.0.linux-amd64/node_exporter --web.listen-address=:3010 &
    ๊ฐ ์‰˜ ํŒŒ์ผ์˜ ๋งˆ์ง€๋ง‰ ์ปค๋งจ๋“œ์—์„œ 3010์€ prometheus์—์„œ ์„ค์ •ํ•œ job task์˜ ํฌํŠธ๋ฅผ ์ฐธ๊ณ ํ•˜์—ฌ ์ˆ˜์ •ํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.๐Ÿ˜
profile
๋ฐ์ดํ„ฐ ์š”๋ฆฌ์‚ฌ
post-custom-banner

0๊ฐœ์˜ ๋Œ“๊ธ€