Ver3.0 ๐ฅ Prometheus๋ก ๋ฉํธ๋ฆญ ์์ง ๊ตฌ์กฐ ์๋ฒฝ ์ ๋ณตํ๊ธฐ

๐ฅ Prometheus๋ก ๋ฉํธ๋ฆญ ์์ง ๊ตฌ์กฐ ์๋ฒฝ ์ ๋ณตํ๊ธฐ
๋ชจ๋ํฐ๋ง์ ์ ์ธ๊ณ, ํ๋ก๋ฉํ ์ฐ์ค์ ํจ๊ป ์์ํ๋ ๋ฉํธ๋ฆญ ์์ง ์ฌ์ ๐
์๋
! ์ค๋์ DevOps ์์ง๋์ด๋ผ๋ฉด ๋ฐ๋์ ์์์ผ ํ Prometheus ๋ฉํธ๋ฆญ ์์ง ๊ตฌ์กฐ์ ๋ํด ๊น์ด ์๊ฒ ํํค์ณ๋ณผ ๊ฑฐ์ผ. ๐
ํด๋ผ์ฐ๋ ํ๊ฒฝ์ด ๋ณต์กํด์ง๊ณ ๋ง์ดํฌ๋ก์๋น์ค ์ํคํ
์ฒ๊ฐ ๋์ธ๊ฐ ๋๋ฉด์, ์์คํ
์ ์ ๋๋ก ๋ชจ๋ํฐ๋งํ๋ ๊ฑด ์ ํ์ด ์๋๋ผ ํ์๊ฐ ๋์ด. Prometheus๋ ์ด๋ฐ ํ๋์ ์ธ ์ธํ๋ผ ํ๊ฒฝ์์ ๊ฐ์ฅ ๋ง์ด ์ฌ์ฉ๋๋ ์คํ์์ค ๋ชจ๋ํฐ๋ง ์๋ฃจ์
์ด์ง!
์ด ๊ธ์์๋ Prometheus์ ๊ธฐ๋ณธ ๊ฐ๋
๋ถํฐ ์ค์ ๊ตฌ์ฑ๊น์ง, ์น๊ตฌ์๊ฒ ์ค๋ช
ํ๋ฏ ์ฝ๊ณ ์ฌ๋ฏธ์๊ฒ ์๋ ค์ค๊ฒ. ์ค๋น๋์ด? ๊ทธ๋ผ ์์ํด๋ณด์! ๐ฏ
๐ฏ Prometheus๊ฐ ๋ญ๊ธธ๋ ์ด๋ ๊ฒ ๋๋ฆฌ์ผ?
๋จผ์ Prometheus๊ฐ ์ ํํ ๋ญ์ง๋ถํฐ ์์๋ณด์. Prometheus๋ 2012๋
SoundCloud์์ ๊ฐ๋ฐํ ์คํ์์ค ์์คํ
๋ชจ๋ํฐ๋ง ๋ฐ ์๋ฆผ ํดํท์ด์ผ. 2016๋
์๋ Kubernetes์ ์ด์ด ๋ ๋ฒ์งธ๋ก Cloud Native Computing Foundation(CNCF)์ ์กธ์
ํ๋ก์ ํธ๊ฐ ๋ ๋งํผ ๊ฒ์ฆ๋ ์๋ฃจ์
์ด์ง! ๐
๊ทธ๋ผ ์ ์ด๋ ๊ฒ ์ธ๊ธฐ๊ฐ ๋ง์๊น? ๋ช ๊ฐ์ง ํต์ฌ ์ด์ ๊ฐ ์์ด:
๐ Prometheus์ ํต์ฌ ๊ฐ์
1. Pull ๊ธฐ๋ฐ ๋ฉํธ๋ฆญ ์์ง ๋ชจ๋ธ ๐ฅ
๋๋ถ๋ถ์ ์ ํต์ ์ธ ๋ชจ๋ํฐ๋ง ์์คํ
์ Push ๋ฐฉ์์ ์ฌ์ฉํด. ์ฆ, ๊ฐ ์ ํ๋ฆฌ์ผ์ด์
์ด๋ ์๋ฒ๊ฐ ๋ฉํธ๋ฆญ์ ์ค์ ์๋ฒ๋ก ๋ณด๋ด๋ ๊ฑฐ์ง. ํ์ง๋ง Prometheus๋ ๋ฐ๋์ผ! Prometheus ์๋ฒ๊ฐ ์ง์ ํ๊ฒ๋ค์ ์ฐพ์๊ฐ์ ๋ฉํธ๋ฆญ์ ๊ฐ์ ธ์(Pull). ์ด๊ฒ ์ ์ข๋๊ณ ?
- ๋คํธ์ํฌ ๋ฐฉํ๋ฒฝ ์ค์ ์ด ๋ ๊ฐ๋จํด์ ธ
- ํ๊ฒ์ ์ํ๋ฅผ Prometheus๊ฐ ์ง์ ํ์ธํ ์ ์์ด
- ์๋น์ค ๋์ค์ปค๋ฒ๋ฆฌ์ ์์ฐ์ค๋ฝ๊ฒ ํตํฉ๋ผ
2. ๊ฐ๋ ฅํ ์ฟผ๋ฆฌ ์ธ์ด PromQL ๐
Prometheus Query Language(PromQL)๋ ์ ๋ง ๊ฐ๋ ฅํด. ๋ณต์กํ ๋ฉํธ๋ฆญ ๊ณ์ฐ๊ณผ ์ง๊ณ๋ฅผ ๊ฐ๋จํ ์ฟผ๋ฆฌ๋ก ํํํ ์ ์๊ฑฐ๋ . ์๋ฅผ ๋ค์ด, ์ง๋ 5๋ถ๊ฐ์ ํ๊ท CPU ์ฌ์ฉ๋ฅ ์ ๊ตฌํ๊ฑฐ๋, ํน์ ๋ ์ด๋ธ์ ๊ฐ์ง ์ธ์คํด์ค๋ค์ ๋ฉํธ๋ฆญ์ ํฉ์ฐํ๋ ๊ฒ ์ ๋ง ์ฌ์.
3. ๋ค์ฐจ์ ๋ฐ์ดํฐ ๋ชจ๋ธ ๐
Prometheus๋ ์๊ณ์ด ๋ฐ์ดํฐ๋ฅผ ๋ฉํธ๋ฆญ ์ด๋ฆ๊ณผ ํค-๊ฐ ์(๋ ์ด๋ธ)์ผ๋ก ์๋ณํด. ์ด๊ฒ ๋ฌด์จ ๋ง์ด๋๋ฉด, ๊ฐ์ ๋ฉํธ๋ฆญ์ด๋ผ๋ ๋ค์ํ ์ฐจ์์ผ๋ก ๋ถ๋ฅํ๊ณ ํํฐ๋งํ ์ ์๋ค๋ ๊ฑฐ์ผ. ์๋ฅผ ๋ค์ด `http_requests_total`์ด๋ผ๋ ๋ฉํธ๋ฆญ์ `method="GET"`, `status="200"`, `endpoint="/api/users"` ๊ฐ์ ๋ ์ด๋ธ๋ก ์ธ๋ถํํ ์ ์์ง!
4. ์๋น์ค ๋์ค์ปค๋ฒ๋ฆฌ ์ง์ ๐ฏ
Kubernetes, Consul, EC2 ๋ฑ ๋ค์ํ ํ๋ซํผ์ ์๋น์ค ๋์ค์ปค๋ฒ๋ฆฌ๋ฅผ ๊ธฐ๋ณธ ์ง์ํด. ๋์ ์ผ๋ก ์์ฑ๋๊ณ ์ฌ๋ผ์ง๋ ์ปจํ
์ด๋ ํ๊ฒฝ์์ ํนํ ์ ์ฉํ์ง!
5. ๋จ์ํ๊ณ ์ ๋ขฐ์ฑ ์๋ ์ํคํ
์ฒ ๐๏ธ
๊ฐ Prometheus ์๋ฒ๋ ๋
๋ฆฝ์ ์ผ๋ก ๋์ํด. ์ธ๋ถ ์์กด์ฑ์ด ๊ฑฐ์ ์์ด์ ์ค์น์ ์ด์์ด ๊ฐ๋จํ๊ณ , ์ฅ์ ๋ฐ์ ์ ์ํฅ ๋ฒ์๊ฐ ์ ํ์ ์ด์ผ.
๐๏ธ Prometheus ์ํคํ ์ฒ ์์ ๋ถํด
์ด์ Prometheus์ ๋ด๋ถ ๊ตฌ์กฐ๋ฅผ ํํค์ณ๋ณด์. ์ ์ฒด ์ํคํ ์ฒ๋ฅผ ์ดํดํ๋ฉด ๋ฉํธ๋ฆญ ์์ง ๊ตฌ์กฐ๋ฅผ ์ค๊ณํ๋ ๊ฒ ํจ์ฌ ์ฌ์์ง ๊ฑฐ์ผ! ๐ง
๐จ Prometheus ์ํ๊ณ์ ์ฃผ์ ์ปดํฌ๋ํธ
Prometheus์ ์ฌ์ฅ์ด๋ผ๊ณ ํ ์ ์์ด. ์ธ ๊ฐ์ง ์ฃผ์ ์ญํ ์ ๋ด๋นํ์ง:
โข Retrieval (์์ง)
์ค์ ๋ ํ๊ฒ๋ค๋ก๋ถํฐ ๋ฉํธ๋ฆญ์ ์ฃผ๊ธฐ์ ์ผ๋ก ์คํฌ๋ฉ(scrape)ํด. ๊ธฐ๋ณธ์ ์ผ๋ก 15์ด๋ง๋ค ํ ๋ฒ์ฉ ์์งํ๋๋ฐ, ์ด ๊ฐ๊ฒฉ์ ์ค์ ์ผ๋ก ์กฐ์ ํ ์ ์์ด.
โข TSDB (Time Series Database)
์์งํ ๋ฉํธ๋ฆญ์ ์๊ณ์ด ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์ ์ฅํด. Prometheus๋ ์์ฒด ๊ฐ๋ฐํ ๊ณ ์ฑ๋ฅ TSDB๋ฅผ ์ฌ์ฉํ๋๋ฐ, ๋ก์ปฌ ๋์คํฌ์ ํจ์จ์ ์ผ๋ก ๋ฐ์ดํฐ๋ฅผ ์ ์ฅํ๊ณ ์์ถํด. ๊ธฐ๋ณธ ๋ณด๊ด ๊ธฐ๊ฐ์ 15์ผ์ด์ง๋ง ์ด๊ฒ๋ ์ค์ ๊ฐ๋ฅํด!
โข HTTP Server
PromQL ์ฟผ๋ฆฌ๋ฅผ ๋ฐ์์ ์ฒ๋ฆฌํ๊ณ ๊ฒฐ๊ณผ๋ฅผ ๋ฐํํด. Grafana ๊ฐ์ ์๊ฐํ ๋๊ตฌ๋ API ํด๋ผ์ด์ธํธ๊ฐ ์ด ์๋ฒ๋ฅผ ํตํด ๋ฐ์ดํฐ๋ฅผ ์กฐํํ์ง.
Prometheus ํ์์ผ๋ก ๋ฉํธ๋ฆญ์ ์ง์ ๋ ธ์ถํ์ง ์๋ ์์คํ ๋ค์ ์ํ ์ด๋ํฐ์ผ. ๋ค์ํ ๊ณต์/๋น๊ณต์ Exporter๋ค์ด ์์ด:
โข Node Exporter - ๋ฆฌ๋ ์ค/์ ๋์ค ์์คํ ์ ํ๋์จ์ด ๋ฐ OS ๋ฉํธ๋ฆญ (CPU, ๋ฉ๋ชจ๋ฆฌ, ๋์คํฌ, ๋คํธ์ํฌ ๋ฑ)
โข MySQL Exporter - MySQL ๋ฐ์ดํฐ๋ฒ ์ด์ค ๋ฉํธ๋ฆญ
โข Blackbox Exporter - HTTP, HTTPS, DNS, TCP, ICMP ์๋ํฌ์ธํธ ํ๋ก๋น
โข JMX Exporter - Java ์ ํ๋ฆฌ์ผ์ด์ ์ JMX ๋ฉํธ๋ฆญ
โข Redis Exporter - Redis ์๋ฒ ๋ฉํธ๋ฆญ
Exporter๋ ํ๊ฒ ์์คํ ์์ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์์ Prometheus๊ฐ ์ดํดํ ์ ์๋ ํ์์ผ๋ก ๋ณํํ ํ, HTTP ์๋ํฌ์ธํธ๋ก ๋ ธ์ถํด. Prometheus ์๋ฒ๋ ์ด ์๋ํฌ์ธํธ๋ฅผ ์คํฌ๋ฉํ๋ ๊ฑฐ์ง!
์์ ๋งํ๋ฏ์ด Prometheus๋ ๊ธฐ๋ณธ์ ์ผ๋ก Pull ๋ฐฉ์์ด์ผ. ๊ทธ๋ฐ๋ฐ ๋ฐฐ์น ์ก์ด๋ ์งง์ ์๋ช ์ ์์ ์ฒ๋ผ Prometheus๊ฐ ์คํฌ๋ฉํ๊ธฐ ์ ์ ์ข ๋ฃ๋๋ ๊ฒฝ์ฐ๊ฐ ์์ด. ์ด๋ด ๋ Pushgateway๋ฅผ ์ฌ์ฉํด!
์งง์ ์์ ๋ค์ด ๋ฉํธ๋ฆญ์ Pushgateway๋ก Pushํ๋ฉด, Prometheus๋ Pushgateway๋ฅผ ์คํฌ๋ฉํด์ ๊ทธ ๋ฉํธ๋ฆญ๋ค์ ์์งํ ์ ์์ด. ํ์ง๋ง ๋จ์ฉํ๋ฉด ์ ๋ผ! Pull ๋ชจ๋ธ์ ์ฅ์ ์ ์๊ฒ ๋๊ฑฐ๋ . ์ ๋ง ํ์ํ ๊ฒฝ์ฐ์๋ง ์ฌ์ฉํ์. ๐จ
Prometheus ์๋ฒ๊ฐ ์๋ฆผ ๊ท์น์ ํ๊ฐํด์ ์๋ฆผ์ ๋ฐ์์ํค๋ฉด, Alertmanager๊ฐ ๊ทธ๊ฑธ ๋ฐ์์ ์ฒ๋ฆฌํด. Alertmanager์ ์ฃผ์ ๊ธฐ๋ฅ์:
โข Grouping (๊ทธ๋ฃนํ)
๋น์ทํ ์๋ฆผ๋ค์ ํ๋๋ก ๋ฌถ์ด์ ์๋ฆผ ํญํ์ ๋ฐฉ์งํด. ์๋ฅผ ๋ค์ด, ๋คํธ์ํฌ ์ฅ์ ๋ก 100๊ฐ์ ์๋น์ค๊ฐ ๋์์ ๋ค์ด๋๋ฉด 100๊ฐ์ ์๋ฆผ ๋์ ํ๋์ ๊ทธ๋ฃนํ๋ ์๋ฆผ์ ๋ณด๋ด๋ ๊ฑฐ์ง.
โข Inhibition (์ต์ )
ํน์ ์๋ฆผ์ด ๋ฐ์ํ๋ฉด ๋ค๋ฅธ ๊ด๋ จ ์๋ฆผ์ ์ต์ ํด. ์๋ฅผ ๋ค์ด, ๋ฐ์ดํฐ์ผํฐ ์ ์ฒด๊ฐ ๋ค์ด๋๋ฉด ๊ฐ๋ณ ์๋ฒ ๋ค์ด ์๋ฆผ์ ์๋ฏธ๊ฐ ์์ผ๋๊น ์ต์ ํ๋ ๊ฑฐ์ผ.
โข Silencing (์์๊ฑฐ)
์ ์ง๋ณด์ ๊ธฐ๊ฐ ๋์ ํน์ ์๋ฆผ์ ์ผ์์ ์ผ๋ก ์์๊ฑฐํ ์ ์์ด.
โข Routing (๋ผ์ฐํ )
์๋ฆผ์ ๋ ์ด๋ธ์ ๋ฐ๋ผ ๋ค๋ฅธ ์์ ์๋ ์ฑ๋๋ก ๋ผ์ฐํ ํด. ์๋ฅผ ๋ค์ด, ๋ฐ์ดํฐ๋ฒ ์ด์ค ์๋ฆผ์ DBA ํ์๊ฒ, ์ ํ๋ฆฌ์ผ์ด์ ์๋ฆผ์ ๊ฐ๋ฐํ์๊ฒ ๋ณด๋ด๋ ์์ด์ง.
Slack, PagerDuty, Email, Webhook ๋ฑ ๋ค์ํ ์๋ฆผ ์ฑ๋์ ์ง์ํด!
ํด๋ผ์ฐ๋ ๋ค์ดํฐ๋ธ ํ๊ฒฝ์์๋ ์๋น์ค ์ธ์คํด์ค๊ฐ ๋์ ์ผ๋ก ์์ฑ๋๊ณ ์ฌ๋ผ์ ธ. ์๋์ผ๋ก ํ๊ฒ์ ๊ด๋ฆฌํ๋ ๊ฑด ๋ถ๊ฐ๋ฅํ์ง! ๊ทธ๋์ Prometheus๋ ๋ค์ํ ์๋น์ค ๋์ค์ปค๋ฒ๋ฆฌ ๋ฉ์ปค๋์ฆ์ ์ง์ํด:
โข Kubernetes - Pod, Service, Endpoint, Ingress ๋ฑ์ ์๋์ผ๋ก ๋ฐ๊ฒฌ
โข Consul - Consul ์๋น์ค ์นดํ๋ก๊ทธ ํตํฉ
โข EC2 - AWS EC2 ์ธ์คํด์ค ์๋ ๋ฐ๊ฒฌ
โข Azure - Azure VM ์๋ ๋ฐ๊ฒฌ
โข DNS - DNS SRV ๋ ์ฝ๋ ๊ธฐ๋ฐ ๋ฐ๊ฒฌ
โข File - JSON/YAML ํ์ผ ๊ธฐ๋ฐ ์ ์ ์ค์ (๋์ ์ ๋ฐ์ดํธ ์ง์)
์๋น์ค ๋์ค์ปค๋ฒ๋ฆฌ๋ฅผ ์ฌ์ฉํ๋ฉด ์๋ก์ด ์ธ์คํด์ค๊ฐ ์ถ๊ฐ๋๊ฑฐ๋ ์ ๊ฑฐ๋ ๋ ์๋์ผ๋ก ๋ชจ๋ํฐ๋ง ํ๊ฒ์ด ์ ๋ฐ์ดํธ๋ผ. ์์ ํธ๋ฆฌํ์ง! ๐
๐ ๋ฉํธ๋ฆญ ํ์ ์์ ์ ๋ณต
Prometheus๋ ๋ค ๊ฐ์ง ํต์ฌ ๋ฉํธ๋ฆญ ํ์ ์ ์ง์ํด. ๊ฐ ํ์ ์ ํน์ฑ์ ์ดํดํ๋ฉด ์ด๋ค ์ํฉ์ ์ด๋ค ๋ฉํธ๋ฆญ์ ์ฌ์ฉํด์ผ ํ ์ง ๋ช ํํด์ ธ! ๐
1๏ธโฃ Counter (์นด์ดํฐ) - ๊ณ์ ์ฆ๊ฐํ๋ ๊ฐ
Counter๋ ๋์ ๊ฐ์ ๋ํ๋ด๋ ๋ฉํธ๋ฆญ์ด์ผ. ์๊ฐ์ด ์ง๋๋ฉด์ ๊ณ์ ์ฆ๊ฐํ๊ฑฐ๋, ์ฌ์์ ์ 0์ผ๋ก ๋ฆฌ์
๋๋ ํน์ง์ด ์์ด.
์ฌ์ฉ ์์:
โข HTTP ์์ฒญ ์ด ๊ฐ์ (`http_requests_total`)
โข ์ฒ๋ฆฌ๋ ์์
์ (`jobs_processed_total`)
โข ์๋ฌ ๋ฐ์ ํ์ (`errors_total`)
โข ์ ์ก๋ ๋ฐ์ดํธ ์ (`bytes_sent_total`)
์ค์ํ ์ : Counter ์์ฒด ๊ฐ์ ๋ณ๋ก ์๋ฏธ๊ฐ ์์ด. ๋์ ์๊ฐ์ ๋ฐ๋ฅธ ์ฆ๊ฐ์จ(rate)์ ๊ณ์ฐํด์ ์ฌ์ฉํด. ์๋ฅผ ๋ค์ด, ์ด๋น ์์ฒญ ์๋ฅผ ์๊ณ ์ถ๋ค๋ฉด `rate(http_requests_total[5m])`์ฒ๋ผ ์ฟผ๋ฆฌํ๋ ๊ฑฐ์ง!
๋ค์ด๋ฐ ๊ท์น: Counter ๋ฉํธ๋ฆญ ์ด๋ฆ์ `_total`๋ก ๋๋์ผ ํด. ์ด๊ฑด Prometheus ์ปค๋ฎค๋ํฐ์ ๋ฒ ์คํธ ํ๋ํฐ์ค์ผ.
2๏ธโฃ Gauge (๊ฒ์ด์ง) - ์ค๋ฅด๋ฝ๋ด๋ฆฌ๋ฝํ๋ ๊ฐ
Gauge๋ ํ์ฌ ์ํ๋ฅผ ๋ํ๋ด๋ ๋ฉํธ๋ฆญ์ด์ผ. ์ฆ๊ฐํ ์๋ ์๊ณ ๊ฐ์ํ ์๋ ์์ด.
์ฌ์ฉ ์์:
โข ํ์ฌ ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋ (`memory_usage_bytes`)
โข CPU ์ฌ์ฉ๋ฅ (`cpu_usage_percent`)
โข ํ์ฌ ํ์ฑ ์ฐ๊ฒฐ ์ (`active_connections`)
โข ํ์ ๋๊ธฐ ์ค์ธ ์์
์ (`queue_size`)
โข ์จ๋, ์ต๋ ๊ฐ์ ์ผ์ ๊ฐ
์ค์ํ ์ : Gauge๋ ํ์ฌ ๊ฐ ์์ฒด๊ฐ ์๋ฏธ ์์ด. ํ๊ท , ์ต๋, ์ต์ ๊ฐ์ ์ง๊ณ ํจ์๋ฅผ ์ฌ์ฉํ ์ ์์ง. ์๋ฅผ ๋ค์ด, `avg_over_time(memory_usage_bytes[5m])`๋ก ์ง๋ 5๋ถ๊ฐ ํ๊ท ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋์ ๊ตฌํ ์ ์์ด.
Gauge๋ Counter์ ๋ฌ๋ฆฌ ๊ฐ์ด ๊ฐ์ํ ์ ์์ผ๋๊น, rate() ํจ์๋ฅผ ์ฌ์ฉํ๋ฉด ์ ๋ผ!
3๏ธโฃ Histogram (ํ์คํ ๊ทธ๋จ) - ๋ถํฌ๋ฅผ ๊ด์ฐฐ
Histogram์ ๊ด์ฐฐ๊ฐ๋ค์ ๋ฒํท(bucket)์ผ๋ก ๋๋ ์ ์ํ๋งํด. ์ฃผ๋ก ์์ฒญ ์ง์ ์๊ฐ์ด๋ ์๋ต ํฌ๊ธฐ ๊ฐ์ ๊ฑธ ์ธก์ ํ ๋ ์ฌ์ฉํด.
Histogram์ด ์์ฑํ๋ ๋ฉํธ๋ฆญ:
โข `
โข `
โข `
์ฌ์ฉ ์์:
์๋ฅผ ๋ค์ด, `http_request_duration_seconds` Histogram์ด ์๋ค๋ฉด:
โข `http_request_duration_seconds_bucket{le="0.1"}` - 0.1์ด ์ดํ ์์ฒญ ์
โข `http_request_duration_seconds_bucket{le="0.5"}` - 0.5์ด ์ดํ ์์ฒญ ์
โข `http_request_duration_seconds_bucket{le="1.0"}` - 1.0์ด ์ดํ ์์ฒญ ์
โข `http_request_duration_seconds_bucket{le="+Inf"}` - ๋ชจ๋ ์์ฒญ ์
โข `http_request_duration_seconds_sum` - ๋ชจ๋ ์์ฒญ ์๊ฐ์ ํฉ
โข `http_request_duration_seconds_count` - ์ด ์์ฒญ ์
์ฅ์ :
โข ๋ฐฑ๋ถ์์(percentile) ๊ณ์ฐ ๊ฐ๋ฅ - ์: 95% ์์ฒญ์ด ๋ช ์ด ์์ ์๋ฃ๋๋์ง
โข ์ฌ๋ฌ Histogram์ ์ง๊ณ ๊ฐ๋ฅ - ์ฌ๋ฌ ์๋ฒ์ ์๋ต ์๊ฐ์ ํฉ์ณ์ ๋ถ์
โข ์๋ฒ ์ธก์์ ํจ์จ์ ์ผ๋ก ๊ณ์ฐ
๋จ์ :
โข ๋ฒํท ๊ฒฝ๊ณ๋ฅผ ๋ฏธ๋ฆฌ ์ ์ํด์ผ ํด
โข ์ ํํ ๋ฐฑ๋ถ์์๊ฐ ์๋๋ผ ๊ทผ์ฌ์น์ผ (๋ฒํท ๊ธฐ๋ฐ์ด๋ผ์)
โข ๋ฉํธ๋ฆญ ์๊ฐ ๋ง์์ ธ (๋ฒํท ๊ฐ์๋งํผ)
4๏ธโฃ Summary (์์ฝ) - ์ ํํ ๋ฐฑ๋ถ์์
Summary๋ Histogram์ฒ๋ผ ๊ด์ฐฐ๊ฐ์ ๋ถํฌ๋ฅผ ์ธก์ ํ์ง๋ง, ํด๋ผ์ด์ธํธ ์ธก์์ ๋ฐฑ๋ถ์์๋ฅผ ์ง์ ๊ณ์ฐํด.
Summary๊ฐ ์์ฑํ๋ ๋ฉํธ๋ฆญ:
โข `
โข `
โข `
์ฌ์ฉ ์์:
`http_request_duration_seconds` Summary๊ฐ ์๋ค๋ฉด:
โข `http_request_duration_seconds{quantile="0.5"}` - ์ค์๊ฐ (50 percentile)
โข `http_request_duration_seconds{quantile="0.9"}` - 90 percentile
โข `http_request_duration_seconds{quantile="0.99"}` - 99 percentile
โข `http_request_duration_seconds_sum` - ๋ชจ๋ ์์ฒญ ์๊ฐ์ ํฉ
โข `http_request_duration_seconds_count` - ์ด ์์ฒญ ์
์ฅ์ :
โข ์ ํํ ๋ฐฑ๋ถ์์ ์ ๊ณต
โข ๋ฒํท ๊ฒฝ๊ณ๋ฅผ ๋ฏธ๋ฆฌ ์ ์ํ ํ์ ์์
๋จ์ :
โข ์ฌ๋ฌ Summary๋ฅผ ์ง๊ณํ ์ ์์ด (์ด๋ฏธ ๊ณ์ฐ๋ ๋ฐฑ๋ถ์์๋ ํฉ์น ์ ์์)
โข ํด๋ผ์ด์ธํธ ์ธก ๊ณ์ฐ ๋ถํ
โข ์๊ฐ ๋ฒ์๋ฅผ ๋ณ๊ฒฝํ ์ ์์ด (๋ฏธ๋ฆฌ ์ ์๋ ์๊ฐ ์๋์ฐ ์ฌ์ฉ)
๐ค Histogram vs Summary, ๋ญ ์จ์ผ ํ ๊น?
โข ์ฌ๋ฌ ์ธ์คํด์ค์ ๋ฉํธ๋ฆญ์ ์ง๊ณํด์ผ ํ๋ค๋ฉด โ Histogram
โข ์ ํํ ๋ฐฑ๋ถ์์๊ฐ ํ์ํ๊ณ ๋จ์ผ ์ธ์คํด์ค๋ง ๋ณธ๋ค๋ฉด โ Summary
โข ์ผ๋ฐ์ ์ผ๋ก๋ Histogram์ ์ถ์ฒํด! ๋ ์ ์ฐํ๊ฑฐ๋ . ๐
๐ฏ ๋ฉํธ๋ฆญ ์์ง ๊ตฌ์กฐ ์ค๊ณํ๊ธฐ
์ด์ ์ค์ ์ด์ผ! Prometheus๋ก ๋ฉํธ๋ฆญ ์์ง ๊ตฌ์กฐ๋ฅผ ์ด๋ป๊ฒ ์ค๊ณํ๊ณ ๊ตฌ์ฑํ๋์ง ๋จ๊ณ๋ณ๋ก ์์๋ณด์. ๐
โข ์ด๋ค ์์คํ /์๋น์ค๋ฅผ ๋ชจ๋ํฐ๋งํ ๊ฑด๊ฐ?
โข ๊ฐ ์์คํ ์์ ์ด๋ค ๋ฉํธ๋ฆญ์ด ํ์ํ๊ฐ?
โข ๋ฉํธ๋ฆญ ๋ณด๊ด ๊ธฐ๊ฐ์ ์ผ๋ง๋ ํ์ํ๊ฐ?
โข ์์ ๋ฉํธ๋ฆญ ๋ณผ๋ฅจ์ ์ผ๋ง๋ ๋๋?
โข ๊ณ ๊ฐ์ฉ์ฑ์ด ํ์ํ๊ฐ?
โข ์ด๋ค ์๋ฆผ์ด ํ์ํ๊ฐ?
๐๏ธ ๊ธฐ๋ณธ ์ํคํ ์ฒ ํจํด
ํจํด 1: ๋จ์ผ Prometheus ์๋ฒ (Small Scale)
๊ฐ์ฅ ๊ฐ๋จํ ๊ตฌ์กฐ์ผ. ์๊ท๋ชจ ํ๊ฒฝ์ด๋ ์์ ๋จ๊ณ์ ์ ํฉํด.
๊ตฌ์ฑ ์์:
โข Prometheus Server 1๋
โข ๋ชจ๋ํฐ๋ง ํ๊ฒ๋ค (์ ํ๋ฆฌ์ผ์ด์
, Exporter ๋ฑ)
โข Grafana (์๊ฐํ)
โข Alertmanager (์๋ฆผ)
์ฅ์ :
โข ์ค์ ๊ณผ ๊ด๋ฆฌ๊ฐ ๊ฐ๋จํด
โข ๋ฆฌ์์ค ์๊ตฌ์ฌํญ์ด ๋ฎ์
โข ๋น ๋ฅด๊ฒ ์์ํ ์ ์์ด
๋จ์ :
โข ๋จ์ผ ์ฅ์ ์ (SPOF)
โข ํ์ฅ์ฑ ์ ํ
โข ํ๊ฒ ์๊ฐ ๋ง์์ง๋ฉด ์ฑ๋ฅ ์ ํ
์ ํฉํ ๊ฒฝ์ฐ:
โข ๋ชจ๋ํฐ๋ง ํ๊ฒ์ด 100๊ฐ ๋ฏธ๋ง
โข ๋ฉํธ๋ฆญ ์๊ฐ 100๋ง ๊ฐ ๋ฏธ๋ง
โข ๊ณ ๊ฐ์ฉ์ฑ์ด ํ์๊ฐ ์๋ ๊ฒฝ์ฐ
ํจํด 2: Federation (๊ณ์ธต์ ๊ตฌ์กฐ)
์ฌ๋ฌ Prometheus ์๋ฒ๋ฅผ ๊ณ์ธต์ ์ผ๋ก ๊ตฌ์ฑํ๋ ๋ฐฉ์์ด์ผ. ๊ฐ ํ์ด๋ ํ๊ฒฝ๋ณ๋ก Prometheus๋ฅผ ์ด์ํ๊ณ , ์์ Prometheus๊ฐ ํ์ ์๋ฒ๋ค๋ก๋ถํฐ ์ง๊ณ๋ ๋ฉํธ๋ฆญ์ ์์งํด.
๊ตฌ์ฑ ์์:
โข ์ฌ๋ฌ ๊ฐ์ Leaf Prometheus (๊ฐ ํ/ํ๊ฒฝ๋ณ)
โข 1๊ฐ ์ด์์ Global Prometheus (์ง๊ณ์ฉ)
โข ๊ฐ ๋ ๋ฒจ๋ณ Grafana
โข ๊ฐ ๋ ๋ฒจ๋ณ Alertmanager
์ฅ์ :
โข ํ๋ณ ๋
๋ฆฝ์ ์ด์ ๊ฐ๋ฅ
โข ๋ถํ ๋ถ์ฐ
โข ๋คํธ์ํฌ ๊ฒฝ๊ณ๋ฅผ ๋์ด ๋ฉํธ๋ฆญ ์์ง ๊ฐ๋ฅ
โข ๋ถ๋ถ ์ฅ์ ์ ์ํฅ ๋ฒ์ ์ ํ
๋จ์ :
โข ์ค์ ๋ณต์ก๋ ์ฆ๊ฐ
โข ๋ฉํธ๋ฆญ ์ค๋ณต ์ ์ฅ (๊ฐ ๋ ๋ฒจ์์)
โข ์ฟผ๋ฆฌ ๋ณต์ก๋ ์ฆ๊ฐ
Federation ์ค์ ์์:
# Global Prometheus ์ค์
scrape_configs:
- job_name: 'federate'
scrape_interval: 30s
honor_labels: true
metrics_path: '/federate'
params:
'match[]':
- '{job="prometheus"}'
- '{__name__=~"job:.*"}' # ์ง๊ณ๋ ๋ฉํธ๋ฆญ๋ง
static_configs:
- targets:
- 'prometheus-team-a:9090'
- 'prometheus-team-b:9090'
- 'prometheus-team-c:9090'
ํจํด 3: Remote Storage (์ฅ๊ธฐ ๋ณด๊ด)
Prometheus์ ๋ก์ปฌ ์คํ ๋ฆฌ์ง๋ ๋จ๊ธฐ ๋ฐ์ดํฐ ์ ์ฅ์ ์ต์ ํ๋์ด ์์ด. ์ฅ๊ธฐ ๋ณด๊ด์ด ํ์ํ๋ค๋ฉด Remote Storage๋ฅผ ์ฌ์ฉํด์ผ ํด.
์ธ๊ธฐ ์๋ Remote Storage ์๋ฃจ์
:
โข Thanos - Prometheus์ ๊ณ ๊ฐ์ฉ์ฑ๊ณผ ์ฅ๊ธฐ ๋ณด๊ด์ ์ํ ์คํ์์ค ์๋ฃจ์
โข Cortex - ๋ฉํฐํ
๋ํธ Prometheus as a Service
โข VictoriaMetrics - ๊ณ ์ฑ๋ฅ ์๊ณ์ด ๋ฐ์ดํฐ๋ฒ ์ด์ค
โข M3DB - Uber์์ ๊ฐ๋ฐํ ๋ถ์ฐ ์๊ณ์ด ๋ฐ์ดํฐ๋ฒ ์ด์ค
โข InfluxDB - ์๊ณ์ด ๋ฐ์ดํฐ๋ฒ ์ด์ค
Remote Write ์ค์ ์์:
remote_write:
- url: "http://thanos-receive:19291/api/v1/receive"
queue_config:
capacity: 10000
max_shards: 50
min_shards: 1
max_samples_per_send: 5000
batch_send_deadline: 5s
min_backoff: 30ms
max_backoff: 100ms
ํจํด 4: Thanos ์ํคํ ์ฒ (์ถ์ฒ! ๐)
Thanos๋ Prometheus๋ฅผ ํ์ฅํด์ ๊ณ ๊ฐ์ฉ์ฑ, ์ฅ๊ธฐ ๋ณด๊ด, ๊ธ๋ก๋ฒ ์ฟผ๋ฆฌ๋ฅผ ์ ๊ณตํ๋ ์คํ์์ค ํ๋ก์ ํธ์ผ. ๋ง์ ๊ธฐ์
๋ค์ด ํ๋ก๋์
์์ ์ฌ์ฉํ๊ณ ์์ด!
Thanos ์ปดํฌ๋ํธ:
โข Sidecar
๊ฐ Prometheus ์๋ฒ ์์ ๋ถ์ด์ ๋ฉํธ๋ฆญ์ ์ค๋ธ์ ํธ ์คํ ๋ฆฌ์ง(S3, GCS ๋ฑ)์ ์
๋ก๋ํ๊ณ , Querier๊ฐ ์ค์๊ฐ ๋ฐ์ดํฐ๋ฅผ ์กฐํํ ์ ์๊ฒ ํด์ค.
โข Store Gateway
์ค๋ธ์ ํธ ์คํ ๋ฆฌ์ง์ ์ ์ฅ๋ ๊ณผ๊ฑฐ ๋ฐ์ดํฐ๋ฅผ ์ฟผ๋ฆฌํ ์ ์๊ฒ ํด์ค.
โข Querier
์ฌ๋ฌ Prometheus ์๋ฒ์ Store Gateway๋ฅผ ํตํฉํด์ ์ฟผ๋ฆฌํ ์ ์๋ ๊ธ๋ก๋ฒ ์ฟผ๋ฆฌ ๋ ์ด์ด์ผ. Grafana๋ Querier๋ฅผ ๋ฐ์ดํฐ์์ค๋ก ์ฌ์ฉํด.
โข Compactor
์ค๋ธ์ ํธ ์คํ ๋ฆฌ์ง์ ๋ฐ์ดํฐ๋ฅผ ์์ถํ๊ณ ๋ค์ด์ํ๋งํด์ ์ ์ฅ ๊ณต๊ฐ์ ์ ์ฝํ๊ณ ์ฟผ๋ฆฌ ์ฑ๋ฅ์ ํฅ์์์ผ.
โข Ruler
Recording rule๊ณผ Alert rule์ ํ๊ฐํด. ์ฌ๋ฌ Prometheus ์๋ฒ์ ๋ฐ์ดํฐ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ๊ธ๋ก๋ฒ ์๋ฆผ์ ์์ฑํ ์ ์์ด.
โข Receiver
Remote Write ํ๋กํ ์ฝ๋ก ๋ฉํธ๋ฆญ์ ๋ฐ์์ ์ ์ฅํด. Prometheus ์๋ฒ ์์ด๋ ๋ฉํธ๋ฆญ์ ์์งํ ์ ์์ด.
์ฅ์ :
โข ๋ฌด์ ํ ๋ฐ์ดํฐ ๋ณด๊ด (์ค๋ธ์ ํธ ์คํ ๋ฆฌ์ง ์ฌ์ฉ)
โข ๊ณ ๊ฐ์ฉ์ฑ (์ฌ๋ฌ Prometheus ๋ณต์ ๋ณธ ํตํฉ)
โข ๊ธ๋ก๋ฒ ์ฟผ๋ฆฌ ๋ทฐ
โข ๋น์ฉ ํจ์จ์ (์ค๋ธ์ ํธ ์คํ ๋ฆฌ์ง๋ ์ ๋ ดํด)
โข ๋ค์ด์ํ๋ง์ผ๋ก ์ฅ๊ธฐ ๋ฐ์ดํฐ ์ฟผ๋ฆฌ ์ฑ๋ฅ ํฅ์
๋จ์ :
โข ์ํคํ
์ฒ ๋ณต์ก๋ ์ฆ๊ฐ
โข ์ด์ ์ค๋ฒํค๋
โข ์ค๋ธ์ ํธ ์คํ ๋ฆฌ์ง ์์กด์ฑ
โ๏ธ Prometheus ์ค์ ํ์ผ ์์ ์ ๋ณต
Prometheus์ ํต์ฌ์ `prometheus.yml` ์ค์ ํ์ผ์ด์ผ. ์ด ํ์ผ์์ ๋ชจ๋ ๊ฑธ ์ ์ดํ๊ฑฐ๋ ! ์ฃผ์ ์น์ ๋ค์ ํ๋์ฉ ํํค์ณ๋ณด์. ๐
๐ Global ์ค์
์ ์ญ ์ค์ ์ ๋ชจ๋ ์คํฌ๋ฉ ์์ ์ ๊ธฐ๋ณธ๊ฐ์ผ๋ก ์ ์ฉ๋ผ. ๊ฐ๋ณ ์์ ์์ ์ค๋ฒ๋ผ์ด๋ํ ์ ์์ด.
global:
# ๋ฉํธ๋ฆญ ์์ง ๊ฐ๊ฒฉ (๊ธฐ๋ณธ๊ฐ: 1๋ถ)
scrape_interval: 15s
# ์คํฌ๋ฉ ํ์์์ (๊ธฐ๋ณธ๊ฐ: 10์ด)
scrape_timeout: 10s
# ์๋ฆผ ๊ท์น ํ๊ฐ ๊ฐ๊ฒฉ (๊ธฐ๋ณธ๊ฐ: 1๋ถ)
evaluation_interval: 15s
# ๋ชจ๋ ๋ฉํธ๋ฆญ์ ์ถ๊ฐํ ์ธ๋ถ ๋ ์ด๋ธ
external_labels:
cluster: 'production'
region: 'us-west-2'
monitor: 'prometheus-main'
๐ฏ Scrape ์ค์ (ํต์ฌ!)
์ด๋ค ํ๊ฒ์์ ์ด๋ป๊ฒ ๋ฉํธ๋ฆญ์ ์์งํ ์ง ์ ์ํ๋ ๋ถ๋ถ์ด์ผ. ๊ฐ์ฅ ์ค์ํ ์น์ ์ด์ง!
scrape_configs:
# Job ์ด๋ฆ (๋ฉํธ๋ฆญ์ job ๋ ์ด๋ธ๋ก ์ถ๊ฐ๋จ)
- job_name: 'prometheus'
# ์ด job์ ์คํฌ๋ฉ ๊ฐ๊ฒฉ (global ์ค์ ์ค๋ฒ๋ผ์ด๋)
scrape_interval: 5s
# ์ ์ ํ๊ฒ ์ค์
static_configs:
- targets: ['localhost:9090']
labels:
env: 'production'
team: 'platform'
# Node Exporter ๋ชจ๋ํฐ๋ง
- job_name: 'node'
static_configs:
- targets:
- 'node1.example.com:9100'
- 'node2.example.com:9100'
- 'node3.example.com:9100'
labels:
datacenter: 'dc1'
# ์ ํ๋ฆฌ์ผ์ด์
๋ชจ๋ํฐ๋ง
- job_name: 'my-app'
scrape_interval: 10s
metrics_path: '/metrics' # ๋ฉํธ๋ฆญ ์๋ํฌ์ธํธ ๊ฒฝ๋ก
scheme: 'https' # HTTP ๋๋ HTTPS
# TLS ์ค์
tls_config:
ca_file: /etc/prometheus/ca.crt
cert_file: /etc/prometheus/client.crt
key_file: /etc/prometheus/client.key
insecure_skip_verify: false
# Basic Auth
basic_auth:
username: 'prometheus'
password: 'secret'
static_configs:
- targets: ['app1.example.com:8080']
# ํ์ผ ๊ธฐ๋ฐ ์๋น์ค ๋์ค์ปค๋ฒ๋ฆฌ
- job_name: 'file-sd'
file_sd_configs:
- files:
- '/etc/prometheus/targets/*.json'
- '/etc/prometheus/targets/*.yml'
refresh_interval: 30s # ํ์ผ ๋ณ๊ฒฝ ํ์ธ ๊ฐ๊ฒฉ
[
{
"targets": ["web1.example.com:9100", "web2.example.com:9100"],
"labels": {
"job": "web-servers",
"env": "production",
"tier": "frontend"
}
},
{
"targets": ["web3.example.com:9100"],
"labels": {
"job": "web-servers",
"env": "staging",
"tier": "frontend"
}
}
]
๐ Kubernetes ์๋น์ค ๋์ค์ปค๋ฒ๋ฆฌ
Kubernetes ํ๊ฒฝ์์๋ ์๋น์ค ๋์ค์ปค๋ฒ๋ฆฌ๊ฐ ํ์์ผ! Prometheus๋ K8s API๋ฅผ ํตํด ์๋์ผ๋ก ํ๊ฒ์ ๋ฐ๊ฒฌํด.
scrape_configs:
# Kubernetes Pod ๋ชจ๋ํฐ๋ง
- job_name: 'kubernetes-pods'
kubernetes_sd_configs:
- role: pod
namespaces:
names:
- default
- production
# ๋ฉํธ๋ฆญ์ ๋
ธ์ถํ๋ Pod๋ง ์คํฌ๋ฉ
relabel_configs:
# prometheus.io/scrape ์ด๋
ธํ
์ด์
์ด true์ธ Pod๋ง
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
action: keep
regex: true
# prometheus.io/path ์ด๋
ธํ
์ด์
์์ ๋ฉํธ๋ฆญ ๊ฒฝ๋ก ๊ฐ์ ธ์ค๊ธฐ
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
action: replace
target_label: __metrics_path__
regex: (.+)
# prometheus.io/port ์ด๋
ธํ
์ด์
์์ ํฌํธ ๊ฐ์ ธ์ค๊ธฐ
- source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
action: replace
regex: ([^:]+)(?::\d+)?;(\d+)
replacement: $1:$2
target_label: __address__
# Pod ๋ฉํ๋ฐ์ดํฐ๋ฅผ ๋ ์ด๋ธ๋ก ์ถ๊ฐ
- action: labelmap
regex: __meta_kubernetes_pod_label_(.+)
- source_labels: [__meta_kubernetes_namespace]
action: replace
target_label: kubernetes_namespace
- source_labels: [__meta_kubernetes_pod_name]
action: replace
target_label: kubernetes_pod_name
# Kubernetes Service ๋ชจ๋ํฐ๋ง
- job_name: 'kubernetes-services'
kubernetes_sd_configs:
- role: service
metrics_path: /probe
params:
module: [http_2xx]
relabel_configs:
- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_probe]
action: keep
regex: true
- source_labels: [__address__]
target_label: __param_target
- target_label: __address__
replacement: blackbox-exporter:9115
- source_labels: [__param_target]
target_label: instance
- action: labelmap
regex: __meta_kubernetes_service_label_(.+)
- source_labels: [__meta_kubernetes_namespace]
target_label: kubernetes_namespace
- source_labels: [__meta_kubernetes_service_name]
target_label: kubernetes_service_name
# Kubernetes Node ๋ชจ๋ํฐ๋ง
- job_name: 'kubernetes-nodes'
kubernetes_sd_configs:
- role: node
scheme: https
tls_config:
ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
relabel_configs:
- action: labelmap
regex: __meta_kubernetes_node_label_(.+)
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
template:
metadata:
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "8080"
prometheus.io/path: "/metrics"
spec:
containers:
- name: my-app
image: my-app:latest
ports:
- containerPort: 8080
๐จ Relabeling (๋ ์ด๋ธ ์ฌ์์ฑ)
Relabeling์ Prometheus์ ๊ฐ๋ ฅํ ๊ธฐ๋ฅ ์ค ํ๋์ผ. ์คํฌ๋ฉ ์ ํ์ ๋ ์ด๋ธ์ ์ถ๊ฐ, ์์ , ์ญ์ ํ ์ ์์ด. ๋ณต์กํด ๋ณด์ด์ง๋ง ์ต์ํด์ง๋ฉด ์ ๋ง ์ ์ฉํด! ๐ฏ
scrape_configs:
- job_name: 'relabeling-example'
static_configs:
- targets: ['server1:9100', 'server2:9100']
relabel_configs:
# 1. ํน์ ํ๊ฒ ์ ์ธํ๊ธฐ
- source_labels: [__address__]
regex: 'server2:9100'
action: drop
# 2. ํน์ ํ๊ฒ๋ง ํฌํจํ๊ธฐ
- source_labels: [__meta_kubernetes_namespace]
regex: '(production|staging)'
action: keep
# 3. ๋ ์ด๋ธ ๊ฐ ๋ณ๊ฒฝํ๊ธฐ
- source_labels: [__address__]
regex: '([^:]+):.*'
replacement: '$1'
target_label: instance
# 4. ์ฌ๋ฌ ๋ ์ด๋ธ ์กฐํฉํด์ ์ ๋ ์ด๋ธ ๋ง๋ค๊ธฐ
- source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_name]
separator: '/'
target_label: kubernetes_pod
# 5. ๋ ์ด๋ธ ์ด๋ฆ ๋ณ๊ฒฝํ๊ธฐ (์ ๊ท์ ๋งค์นญ)
- action: labelmap
regex: '__meta_kubernetes_pod_label_app_(.+)'
replacement: 'app_$1'
# 6. ๋ ์ด๋ธ ์ญ์ ํ๊ธฐ
- regex: 'unwanted_label'
action: labeldrop
# 7. ๋ฉํธ๋ฆญ ๊ฒฝ๋ก ๋์ ์ค์
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
target_label: __metrics_path__
regex: '(.+)'
action: replace
# metric_relabel_configs: ์คํฌ๋ฉ ํ ๋ฉํธ๋ฆญ ๋ ์ด๋ธ ์์
metric_relabel_configs:
# ํน์ ๋ฉํธ๋ฆญ ์ ์ธ
- source_labels: [__name__]
regex: 'go_.*'
action: drop
# ๊ณ ์นด๋๋๋ฆฌํฐ ๋ ์ด๋ธ ์ ๊ฑฐ
- regex: 'user_id'
action: labeldrop
โข `metric_relabel_configs`๋ ์คํฌ๋ฉ ํ์ ์ ์ฉ๋ผ (๋ฉํธ๋ฆญ ํํฐ๋ง ๋ฐ ๋ ์ด๋ธ ์์ )
โข ๊ณ ์นด๋๋๋ฆฌํฐ ๋ ์ด๋ธ(์: user_id, request_id)์ ์ ๊ฑฐํ๋ ๊ฒ ์ข์. ๋ฉํธ๋ฆญ ์๊ฐ ํญ๋ฐ์ ์ผ๋ก ์ฆ๊ฐํ ์ ์๊ฑฐ๋ ! ๐ฅ
โข `action: drop`๊ณผ `action: keep`์ ์ ํ์ฉํด์ ๋ถํ์ํ ํ๊ฒ์ด๋ ๋ฉํธ๋ฆญ์ ์ ์ธํด์ผ ํด
๐ ์ค์ ๊ตฌ์ฑ ์์
์ด๋ก ์ ์ถฉ๋ถํ ๋ฐฐ์ ์ผ๋, ์ด์ ์ค์ ๋ก Prometheus ๋ฉํธ๋ฆญ ์์ง ๊ตฌ์กฐ๋ฅผ ๊ตฌ์ฑํด๋ณด์! ๋จ๊ณ๋ณ๋ก ๋ฐ๋ผํ๋ฉด ๋ผ. ๐
Docker๋ก ๋น ๋ฅด๊ฒ ์์ํ๊ธฐ:
# Prometheus ์ค์ ํ์ผ ์์ฑ
cat > prometheus.yml << EOF
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
EOF
# Prometheus ์คํ
docker run -d \
--name prometheus \
-p 9090:9090 \
-v $(pwd)/prometheus.yml:/etc/prometheus/prometheus.yml \
prom/prometheus:latest
# ์น UI ์ ์: http://localhost:9090
Linux ์๋ฒ์ CPU, ๋ฉ๋ชจ๋ฆฌ, ๋์คํฌ, ๋คํธ์ํฌ ๋ฑ์ ๋ชจ๋ํฐ๋งํ๋ ค๋ฉด Node Exporter๊ฐ ํ์ํด.
# Docker๋ก Node Exporter ์คํ
docker run -d \
--name node-exporter \
--net="host" \
--pid="host" \
-v "/:/host:ro,rslave" \
prom/node-exporter:latest \
--path.rootfs=/host
# ๋ฉํธ๋ฆญ ํ์ธ: http://localhost:9100/metrics
# Prometheus ์ค์ ์ ์ถ๊ฐ
cat >> prometheus.yml << EOF
- job_name: 'node'
static_configs:
- targets: ['localhost:9100']
labels:
instance: 'my-server'
EOF
# Prometheus ์ฌ์์
docker restart prometheus
์ ํ๋ฆฌ์ผ์ด์ ์์ ์ง์ ๋ฉํธ๋ฆญ์ ๋ ธ์ถํ๋ ค๋ฉด Prometheus ํด๋ผ์ด์ธํธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํด์ผ ํด. ์ฌ๊ธฐ์๋ Python ์์ ๋ฅผ ๋ณด์ฌ์ค๊ฒ!
# Python ์ ํ๋ฆฌ์ผ์ด์
์์
from prometheus_client import Counter, Histogram, Gauge, start_http_server
import time
import random
# ๋ฉํธ๋ฆญ ์ ์
REQUEST_COUNT = Counter(
'http_requests_total',
'Total HTTP requests',
['method', 'endpoint', 'status']
)
REQUEST_DURATION = Histogram(
'http_request_duration_seconds',
'HTTP request duration',
['method', 'endpoint']
)
ACTIVE_USERS = Gauge(
'active_users',
'Number of active users'
)
QUEUE_SIZE = Gauge(
'queue_size',
'Number of items in queue'
)
def process_request(method, endpoint):
# ์์ฒญ ์นด์ดํธ ์ฆ๊ฐ
status = random.choice([200, 200, 200, 404, 500])
REQUEST_COUNT.labels(method=method, endpoint=endpoint, status=status).inc()
# ์์ฒญ ์๊ฐ ์ธก์
with REQUEST_DURATION.labels(method=method, endpoint=endpoint).time():
time.sleep(random.uniform(0.1, 0.5))
# Gauge ์
๋ฐ์ดํธ
ACTIVE_USERS.set(random.randint(10, 100))
QUEUE_SIZE.set(random.randint(0, 50))
if __name__ == '__main__':
# ๋ฉํธ๋ฆญ ์๋ํฌ์ธํธ ์์ (ํฌํธ 8000)
start_http_server(8000)
print("Metrics server started on port 8000")
print("Visit http://localhost:8000/metrics")
# ์๋ฎฌ๋ ์ด์
while True:
process_request('GET', '/api/users')
process_request('POST', '/api/orders')
time.sleep(1)
โข Java: io.prometheus:simpleclient
โข Node.js: prom-client
โข Ruby: prometheus-client
โข .NET: prometheus-net
โข Rust: prometheus crate
๋ชจ๋ ์ฃผ์ ์ธ์ด๋ฅผ ์ง์ํ๋๊น ๊ฑฑ์ ๋ง! ๐
Kubernetes์์ Prometheus๋ฅผ ์ด์ํ๋ ๊ฐ์ฅ ์ฌ์ด ๋ฐฉ๋ฒ์ Prometheus Operator๋ฅผ ์ฌ์ฉํ๋ ๊ฑฐ์ผ!
# Helm์ผ๋ก kube-prometheus-stack ์ค์น
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
# ๋ค์์คํ์ด์ค ์์ฑ
kubectl create namespace monitoring
# ์ค์น
helm install prometheus prometheus-community/kube-prometheus-stack \
--namespace monitoring \
--set prometheus.prometheusSpec.retention=30d \
--set prometheus.prometheusSpec.storageSpec.volumeClaimTemplate.spec.resources.requests.storage=50Gi
# ์ค์น ํ์ธ
kubectl get pods -n monitoring
# Prometheus UI ์ ์ (ํฌํธ ํฌ์๋ฉ)
kubectl port-forward -n monitoring svc/prometheus-kube-prometheus-prometheus 9090:9090
# Grafana ์ ์ (๊ธฐ๋ณธ ๋น๋ฐ๋ฒํธ: prom-operator)
kubectl port-forward -n monitoring svc/prometheus-grafana 3000:80
ServiceMonitor๋ก ์ ํ๋ฆฌ์ผ์ด์ ๋ชจ๋ํฐ๋ง
Prometheus Operator๋ฅผ ์ฌ์ฉํ๋ฉด ServiceMonitor CRD๋ก ์ฝ๊ฒ ์คํฌ๋ฉ ํ๊ฒ์ ์ถ๊ฐํ ์ ์์ด!
apiVersion: v1
kind: Service
metadata:
name: my-app
namespace: default
labels:
app: my-app
spec:
selector:
app: my-app
ports:
- name: metrics
port: 8080
targetPort: 8080
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: my-app
namespace: default
labels:
app: my-app
spec:
selector:
matchLabels:
app: my-app
endpoints:
- port: metrics
interval: 30s
path: /metrics
์๋ฆผ ๊ท์น์ ์ ์ํ๊ณ Alertmanager๋ฅผ ์ค์ ํด๋ณด์!
# alert-rules.yml
groups:
- name: example-alerts
interval: 30s
rules:
# ์ธ์คํด์ค ๋ค์ด ์๋ฆผ
- alert: InstanceDown
expr: up == 0
for: 5m
labels:
severity: critical
annotations:
summary: "Instance {{ $labels.instance }} down"
description: "{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes."
# ๋์ CPU ์ฌ์ฉ๋ฅ ์๋ฆผ
- alert: HighCPUUsage
expr: 100 - (avg by(instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100) > 80
for: 10m
labels:
severity: warning
annotations:
summary: "High CPU usage on {{ $labels.instance }}"
description: "CPU usage is above 80% for more than 10 minutes. Current value: {{ $value }}%"
# ๋ฉ๋ชจ๋ฆฌ ๋ถ์กฑ ์๋ฆผ
- alert: HighMemoryUsage
expr: (1 - (node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes)) * 100 > 90
for: 5m
labels:
severity: critical
annotations:
summary: "High memory usage on {{ $labels.instance }}"
description: "Memory usage is above 90%. Current value: {{ $value }}%"
# ๋์คํฌ ๊ณต๊ฐ ๋ถ์กฑ ์๋ฆผ
- alert: DiskSpaceLow
expr: (node_filesystem_avail_bytes{fstype!~"tmpfs|fuse.lxcfs"} / node_filesystem_size_bytes) * 100 < 10
for: 5m
labels:
severity: warning
annotations:
summary: "Low disk space on {{ $labels.instance }}"
description: "Disk {{ $labels.mountpoint }} has less than 10% free space. Current value: {{ $value }}%"
# HTTP ์๋ฌ์จ ๋์
- alert: HighErrorRate
expr: rate(http_requests_total{status=~"5.."}[5m]) / rate(http_requests_total[5m]) > 0.05
for: 5m
labels:
severity: critical
annotations:
summary: "High HTTP error rate"
description: "Error rate is above 5% for {{ $labels.job }}. Current value: {{ $value }}"
# ์๋ต ์๊ฐ ๋๋ฆผ
- alert: SlowResponseTime
expr: histogram_quantile(0.95, rate(http_request_duration_seconds_bucket[5m])) > 1
for: 10m
labels:
severity: warning
annotations:
summary: "Slow response time"
description: "95th percentile response time is above 1 second for {{ $labels.job }}. Current value: {{ $value }}s"
# alertmanager.yml
global:
resolve_timeout: 5m
slack_api_url: 'https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK'
# ์๋ฆผ ๋ผ์ฐํ
route:
group_by: ['alertname', 'cluster', 'service']
group_wait: 10s
group_interval: 10s
repeat_interval: 12h
receiver: 'default'
routes:
# Critical ์๋ฆผ์ ์ฆ์ PagerDuty๋ก
- match:
severity: critical
receiver: 'pagerduty'
continue: true
# Warning ์๋ฆผ์ Slack์ผ๋ก
- match:
severity: warning
receiver: 'slack'
# ๋ฐ์ดํฐ๋ฒ ์ด์ค ์๋ฆผ์ DBA ํ์ผ๋ก
- match_re:
service: '.*database.*'
receiver: 'dba-team'
# ์์ ์ ์ค์
receivers:
- name: 'default'
email_configs:
- to: 'team@example.com'
from: 'alertmanager@example.com'
smarthost: 'smtp.gmail.com:587'
auth_username: 'alertmanager@example.com'
auth_password: 'password'
- name: 'slack'
slack_configs:
- channel: '#alerts'
title: '{{ .GroupLabels.alertname }}'
text: '{{ range .Alerts }}{{ .Annotations.description }}{{ end }}'
send_resolved: true
- name: 'pagerduty'
pagerduty_configs:
- service_key: 'YOUR_PAGERDUTY_SERVICE_KEY'
description: '{{ .GroupLabels.alertname }}'
- name: 'dba-team'
email_configs:
- to: 'dba-team@example.com'
# ์๋ฆผ ์ต์ ๊ท์น
inhibit_rules:
# ์ธ์คํด์ค๊ฐ ๋ค์ด๋๋ฉด ํด๋น ์ธ์คํด์ค์ ๋ค๋ฅธ ์๋ฆผ ์ต์
- source_match:
severity: 'critical'
alertname: 'InstanceDown'
target_match_re:
severity: 'warning|critical'
equal: ['instance']
Prometheus ๋ฐ์ดํฐ๋ฅผ ์๊ฐํํ๋ ค๋ฉด Grafana๊ฐ ์ต๊ณ ์ผ! ๐จ
# Docker๋ก Grafana ์คํ
docker run -d \
--name grafana \
-p 3000:3000 \
-e "GF_SECURITY_ADMIN_PASSWORD=admin" \
grafana/grafana:latest
# ์ ์: http://localhost:3000 (admin/admin)
# Prometheus ๋ฐ์ดํฐ์์ค ์ถ๊ฐ:
# Configuration > Data Sources > Add data source > Prometheus
# URL: http://prometheus:9090 (Docker ๋คํธ์ํฌ ์ฌ์ฉ ์)
โข Node Exporter Full (ID: 1860) - ์์คํ ๋ฉํธ๋ฆญ ์ข ํฉ
โข Kubernetes Cluster Monitoring (ID: 7249) - K8s ํด๋ฌ์คํฐ ์ ์ฒด ๋ทฐ
โข Kubernetes Pod Monitoring (ID: 6417) - Pod ์์ธ ๋ชจ๋ํฐ๋ง
โข Prometheus Stats (ID: 2) - Prometheus ์์ฒด ๋ชจ๋ํฐ๋ง
โข MySQL Overview (ID: 7362) - MySQL ๋ฐ์ดํฐ๋ฒ ์ด์ค
์ํฌํธ ๋ฐฉ๋ฒ: Dashboard > Import > Dashboard ID ์ ๋ ฅ!
๐ PromQL ์ฟผ๋ฆฌ ๋ง์คํฐํ๊ธฐ
Prometheus Query Language(PromQL)๋ ๋ฉํธ๋ฆญ์ ์กฐํํ๊ณ ๋ถ์ํ๋ ๊ฐ๋ ฅํ ๋๊ตฌ์ผ. ๊ธฐ๋ณธ๋ถํฐ ๊ณ ๊ธ๊น์ง ์์๋ณด์! ๐
๐ ๊ธฐ๋ณธ ์ฟผ๋ฆฌ
# 1. ๋จ์ ๋ฉํธ๋ฆญ ์กฐํ
http_requests_total
# 2. ๋ ์ด๋ธ ํํฐ๋ง
http_requests_total{method="GET"}
http_requests_total{method="GET", status="200"}
# 3. ์ ๊ท์ ๋งค์นญ
http_requests_total{status=~"2.."} # 2๋ก ์์ํ๋ ๋ชจ๋ status
http_requests_total{endpoint!~"/admin.*"} # /admin์ผ๋ก ์์ํ์ง ์๋ ๊ฒ
# 4. ๋ฒ์ ๋ฒกํฐ (์๊ฐ ๋ฒ์)
http_requests_total[5m] # ์ง๋ 5๋ถ๊ฐ์ ๋ชจ๋ ๋ฐ์ดํฐ ํฌ์ธํธ
๐ ์ง๊ณ ํจ์
# 1. sum - ํฉ๊ณ
sum(http_requests_total)
sum by(method) (http_requests_total) # method๋ณ๋ก ๊ทธ๋ฃนํํด์ ํฉ๊ณ
sum without(instance) (http_requests_total) # instance ์ ์ธํ๊ณ ํฉ๊ณ
# 2. avg - ํ๊ท
avg(node_cpu_seconds_total)
avg by(cpu) (rate(node_cpu_seconds_total[5m]))
# 3. min, max - ์ต์, ์ต๋
max(node_memory_MemTotal_bytes)
min by(instance) (node_filesystem_avail_bytes)
# 4. count - ๊ฐ์
count(up == 1) # ์ด์์๋ ์ธ์คํด์ค ์
count by(job) (up) # job๋ณ ์ธ์คํด์ค ์
# 5. topk, bottomk - ์์/ํ์ k๊ฐ
topk(5, http_requests_total) # ์์ฒญ์ด ๊ฐ์ฅ ๋ง์ 5๊ฐ
bottomk(3, node_filesystem_avail_bytes) # ๋์คํฌ ๊ณต๊ฐ์ด ๊ฐ์ฅ ์ ์ 3๊ฐ
# 6. quantile - ๋ฐฑ๋ถ์์
quantile(0.95, http_request_duration_seconds) # 95 percentile
โฑ๏ธ ์๊ฐ ๊ด๋ จ ํจ์
# 1. rate - ์ด๋น ์ฆ๊ฐ์จ (Counter์ฉ)
rate(http_requests_total[5m]) # ์ง๋ 5๋ถ๊ฐ ์ด๋น ํ๊ท ์์ฒญ ์
# 2. irate - ์๊ฐ ์ฆ๊ฐ์จ (๋ ๋ฏผ๊ฐํจ)
irate(http_requests_total[5m]) # ๋ง์ง๋ง ๋ ๋ฐ์ดํฐ ํฌ์ธํธ ๊ธฐ๋ฐ
# 3. increase - ์ฆ๊ฐ๋
increase(http_requests_total[1h]) # ์ง๋ 1์๊ฐ ๋์์ ์ด ์ฆ๊ฐ๋
# 4. delta - ๋ณํ๋ (Gauge์ฉ)
delta(node_memory_MemAvailable_bytes[5m]) # 5๋ถ๊ฐ ๋ฉ๋ชจ๋ฆฌ ๋ณํ๋
# 5. deriv - ๋ฏธ๋ถ (์ด๋น ๋ณํ์จ)
deriv(node_memory_MemAvailable_bytes[5m])
# 6. predict_linear - ์ ํ ์์ธก
predict_linear(node_filesystem_avail_bytes[1h], 4*3600) # 4์๊ฐ ํ ์์ ๊ฐ
๐งฎ ์ํ ์ฐ์ฐ
# 1. ์ฐ์ ์ฐ์ฐ
node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes # ์ฌ์ฉ ์ค์ธ ๋ฉ๋ชจ๋ฆฌ
# 2. ๋ฐฑ๋ถ์จ ๊ณ์ฐ
100 * (1 - node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes) # ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋ฅ
# 3. CPU ์ฌ์ฉ๋ฅ ๊ณ์ฐ
100 - (avg by(instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)
# 4. ๋์คํฌ ์ฌ์ฉ๋ฅ
100 * (1 - node_filesystem_avail_bytes / node_filesystem_size_bytes)
# 5. ์๋ฌ์จ ๊ณ์ฐ
rate(http_requests_total{status=~"5.."}[5m]) / rate(http_requests_total[5m]) * 100
๐ฏ ์ค์ ์ฟผ๋ฆฌ ์์
# 1. ์๋น์ค๋ณ QPS (์ด๋น ์ฟผ๋ฆฌ ์)
sum by(service) (rate(http_requests_total[5m]))
# 2. 95 percentile ์๋ต ์๊ฐ
histogram_quantile(0.95,
sum by(le) (rate(http_request_duration_seconds_bucket[5m]))
)
# 3. ์๋ฌ์จ์ด 1% ์ด์์ธ ์๋น์ค
(
sum by(service) (rate(http_requests_total{status=~"5.."}[5m]))
/
sum by(service) (rate(http_requests_total[5m]))
) > 0.01
# 4. ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋ ์์ 5๊ฐ Pod
topk(5,
sum by(pod) (container_memory_usage_bytes{container!=""})
)
# 5. ์ง๋ 1์๊ฐ ๋์ ์ฌ์์๋ Pod
changes(kube_pod_container_status_restarts_total[1h]) > 0
# 6. ๋คํธ์ํฌ ํธ๋ํฝ (์์ /์ก์ )
sum(rate(node_network_receive_bytes_total[5m])) by (instance) # ์์
sum(rate(node_network_transmit_bytes_total[5m])) by (instance) # ์ก์
# 7. ๋์คํฌ I/O
rate(node_disk_read_bytes_total[5m]) # ์ฝ๊ธฐ
rate(node_disk_written_bytes_total[5m]) # ์ฐ๊ธฐ
# 8. ์๋น์ค ๊ฐ์ฉ์ฑ (์ง๋ 24์๊ฐ)
avg_over_time(up{job="my-service"}[24h]) * 100
# 9. ์์ฒญ ์ฑ๊ณต๋ฅ
sum(rate(http_requests_total{status=~"2.."}[5m]))
/
sum(rate(http_requests_total[5m]))
* 100
# 10. ์์ธก: 2์๊ฐ ํ ๋์คํฌ ํ ์์
predict_linear(node_filesystem_avail_bytes{mountpoint="/"}[1h], 2*3600) < 0
โข ๋ฒ์ ์ ํ: rate()๋ increase() ์ฌ์ฉ ์ ๋ฒ์๋ ์คํฌ๋ฉ ๊ฐ๊ฒฉ์ ์ต์ 4๋ฐฐ ์ด์์ผ๋ก ์ค์ ํด.
โข ๋ ์ด๋ธ ์นด๋๋๋ฆฌํฐ: ๋๋ฌด ๋ง์ ๊ณ ์ ๋ ์ด๋ธ ๊ฐ์ ์ฑ๋ฅ ๋ฌธ์ ๋ฅผ ์ผ์ผ์ผ. ์ ์คํ๊ฒ ์ ํํด!
โข ์ง๊ณ ์์: sum(rate(...))๋ ๋์ง๋ง rate(sum(...))๋ ์ ๋ผ. rate()๋ Counter์๋ง ์ฌ์ฉ!
โข ํ ์คํธ: Prometheus UI์ Graph ํญ์์ ์ฟผ๋ฆฌ๋ฅผ ํ ์คํธํ๊ณ ๊ฒฐ๊ณผ๋ฅผ ํ์ธํด๋ด.
๐ง ์ฑ๋ฅ ์ต์ ํ ๋ฐ ๋ฒ ์คํธ ํ๋ํฐ์ค
Prometheus๋ฅผ ํ๋ก๋์ ์์ ์ด์ํ๋ ค๋ฉด ์ฑ๋ฅ ์ต์ ํ๊ฐ ํ์์ผ! ์ค์ ํ๋ค์ ๊ณต์ ํ ๊ฒ. ๐ช
โก ์ฑ๋ฅ ์ต์ ํ ์ ๋ต
1. ๋ฉํธ๋ฆญ ์นด๋๋๋ฆฌํฐ ๊ด๋ฆฌ
์นด๋๋๋ฆฌํฐ๋ ๊ณ ์ ํ ์๊ณ์ด์ ์๋ฅผ ์๋ฏธํด. ๋์ ์นด๋๋๋ฆฌํฐ๋ Prometheus์ ์ต๋ ์ ์ด์ผ! ๐ฏ
โ ๋์ ์ (๋์ ์นด๋๋๋ฆฌํฐ):
# user_id๋ฅผ ๋ ์ด๋ธ๋ก ์ฌ์ฉ (์๋ฐฑ๋ง ๊ฐ์ ์๊ณ์ด ์์ฑ!)
http_requests_total{user_id="12345", endpoint="/api/users"}
# request_id๋ฅผ ๋ ์ด๋ธ๋ก ์ฌ์ฉ (๋งค ์์ฒญ๋ง๋ค ์ ์๊ณ์ด!)
http_requests_total{request_id="abc-123-def", endpoint="/api/users"}
# ํ์์คํฌํ๋ฅผ ๋ ์ด๋ธ๋ก ์ฌ์ฉ
http_requests_total{timestamp="2024-01-15T10:30:00Z"}
โ ์ข์ ์ (๋ฎ์ ์นด๋๋๋ฆฌํฐ):
# ์ ์ ํ ๋ ์ด๋ธ ์ฌ์ฉ (์ ํ๋ ์์ ์๊ณ์ด)
http_requests_total{method="GET", endpoint="/api/users", status="200"}
# ๊ทธ๋ฃนํ๋ ๋ ์ด๋ธ
http_requests_total{user_tier="premium", endpoint="/api/users"}
# ๋ฒํทํ๋ ๊ฐ
http_request_duration_bucket{le="0.1", endpoint="/api/users"}
# ์ด ์๊ณ์ด ์
count({__name__=~".+"})
# ๋ฉํธ๋ฆญ๋ณ ์๊ณ์ด ์
count by(__name__) ({__name__=~".+"})
# ๊ฐ์ฅ ๋ง์ ์๊ณ์ด์ ๊ฐ์ง ๋ฉํธ๋ฆญ Top 10
topk(10, count by(__name__) ({__name__=~".+"}))
2. ์คํฌ๋ฉ ์ต์ ํ
์คํฌ๋ฉ ๊ฐ๊ฒฉ ์กฐ์ :
โข ๊ธฐ๋ณธ๊ฐ 15์ด๋ ๋๋ถ๋ถ์ ๊ฒฝ์ฐ ์ ์ ํด
โข ๋น ๋ฅธ ๋ณํ๊ฐ ํ์ํ ๊ฒฝ์ฐ: 5-10์ด
โข ๋๋ฆฐ ๋ณํ๋ง ํ์ํ ๊ฒฝ์ฐ: 30-60์ด
ํ์์์ ์ค์ :
โข scrape_timeout์ scrape_interval๋ณด๋ค ์์์ผ ํด
โข ์ผ๋ฐ์ ์ผ๋ก scrape_interval์ 80% ์ ๋๋ก ์ค์
๋ถํ์ํ ๋ฉํธ๋ฆญ ์ ๊ฑฐ:
scrape_configs:
- job_name: 'my-app'
static_configs:
- targets: ['app:8080']
# ๋ถํ์ํ ๋ฉํธ๋ฆญ ์ ๊ฑฐ
metric_relabel_configs:
# Go runtime ๋ฉํธ๋ฆญ ์ ๊ฑฐ (ํ์ ์๋ค๋ฉด)
- source_labels: [__name__]
regex: 'go_.*'
action: drop
# ํน์ prefix ๋ฉํธ๋ฆญ๋ง ์ ์ง
- source_labels: [__name__]
regex: '(http_|db_|cache_).*'
action: keep
# ๋๋ฒ๊ทธ ๋ฉํธ๋ฆญ ์ ๊ฑฐ
- source_labels: [__name__]
regex: '.*_debug_.*'
action: drop
3. ์คํ ๋ฆฌ์ง ์ต์ ํ
๋ณด๊ด ๊ธฐ๊ฐ ์ค์ :
# Prometheus ์คํ ์ ํ๋๊ทธ๋ก ์ค์
prometheus \
--storage.tsdb.retention.time=30d \ # 30์ผ ๋ณด๊ด
--storage.tsdb.retention.size=50GB \ # ๋๋ ํฌ๊ธฐ ์ ํ
--storage.tsdb.path=/prometheus
์์ถ ๋ฐ ๋ค์ด์ํ๋ง:
โข Prometheus๋ ์๋์ผ๋ก ๋ฐ์ดํฐ๋ฅผ ์์ถํด
โข ์ฅ๊ธฐ ๋ณด๊ด์ด ํ์ํ๋ฉด Thanos๋ Cortex ์ฌ์ฉ
โข Thanos Compactor๋ก ๋ค์ด์ํ๋ง (5m, 1h ํด์๋)
๋์คํฌ I/O ์ต์ ํ:
โข SSD ์ฌ์ฉ ๊ถ์ฅ
โข WAL(Write-Ahead Log)๊ณผ ๋ฐ์ดํฐ ๋๋ ํ ๋ฆฌ๋ฅผ ๋ถ๋ฆฌ ๊ฐ๋ฅ
โข ์ถฉ๋ถํ IOPS ํ๋ณด
4. ์ฟผ๋ฆฌ ์ต์ ํ
ํจ์จ์ ์ธ ์ฟผ๋ฆฌ ์์ฑ:
# โ ๋นํจ์จ์ - ๋ชจ๋ ์๊ณ์ด ์ค์บ
sum(rate(http_requests_total[5m]))
# โ
ํจ์จ์ - ํ์ํ ๋ ์ด๋ธ๋ง ํํฐ๋ง
sum(rate(http_requests_total{job="my-app", status="200"}[5m]))
# โ ๋นํจ์จ์ - ๊ธด ๋ฒ์
rate(http_requests_total[1h])
# โ
ํจ์จ์ - ์ ์ ํ ๋ฒ์ (์คํฌ๋ฉ ๊ฐ๊ฒฉ์ 4๋ฐฐ)
rate(http_requests_total[1m])
# โ ๋นํจ์จ์ - ์ค์ฒฉ๋ ์ง๊ณ
sum(sum by(instance) (rate(http_requests_total[5m])))
# โ
ํจ์จ์ - ๋จ์ผ ์ง๊ณ
sum(rate(http_requests_total[5m]))
5. Recording Rules ํ์ฉ
์์ฃผ ์ฌ์ฉํ๋ ๋ณต์กํ ์ฟผ๋ฆฌ๋ Recording Rule๋ก ๋ฏธ๋ฆฌ ๊ณ์ฐํด๋๋ฉด ์ฟผ๋ฆฌ ์ฑ๋ฅ์ด ํฌ๊ฒ ํฅ์๋ผ!
# recording-rules.yml
groups:
- name: http-metrics
interval: 30s
rules:
# ์๋น์ค๋ณ QPS ๋ฏธ๋ฆฌ ๊ณ์ฐ
- record: job:http_requests:rate5m
expr: sum by(job) (rate(http_requests_total[5m]))
# ์๋ฌ์จ ๋ฏธ๋ฆฌ ๊ณ์ฐ
- record: job:http_errors:rate5m
expr: |
sum by(job) (rate(http_requests_total{status=~"5.."}[5m]))
/
sum by(job) (rate(http_requests_total[5m]))
# CPU ์ฌ์ฉ๋ฅ ๋ฏธ๋ฆฌ ๊ณ์ฐ
- record: instance:cpu_usage:rate5m
expr: |
100 - (
avg by(instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100
)
# ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋ฅ ๋ฏธ๋ฆฌ ๊ณ์ฐ
- record: instance:memory_usage:ratio
expr: |
1 - (
node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes
)
# ์ด์ ๊ฐ๋จํ๊ฒ ์ฟผ๋ฆฌ ๊ฐ๋ฅ!
# job:http_requests:rate5m
# job:http_errors:rate5m > 0.01
6. ๋ฆฌ์์ค ํ ๋น
๋ฉ๋ชจ๋ฆฌ ์๊ตฌ์ฌํญ ์ถ์ :
โข ์๊ณ์ด๋น ์ฝ 1-2KB ๋ฉ๋ชจ๋ฆฌ ํ์
โข 100๋ง ๊ฐ ์๊ณ์ด = ์ฝ 1-2GB ๋ฉ๋ชจ๋ฆฌ
โข ์ฟผ๋ฆฌ ๋ฒํผ, ์บ์ ๋ฑ์ ์ํ ์ถ๊ฐ ๋ฉ๋ชจ๋ฆฌ ํ์
๊ถ์ฅ ๋ฆฌ์์ค (์ค๊ฐ ๊ท๋ชจ):
โข CPU: 4-8 ์ฝ์ด
โข ๋ฉ๋ชจ๋ฆฌ: 16-32GB
โข ๋์คํฌ: 100-500GB SSD
โข ๋คํธ์ํฌ: 1Gbps
Kubernetes ๋ฆฌ์์ค ์ค์ ์์:
apiVersion: v1
kind: Pod
metadata:
name: prometheus
spec:
containers:
- name: prometheus
image: prom/prometheus:latest
resources:
requests:
memory: "16Gi"
cpu: "4"
limits:
memory: "32Gi"
cpu: "8"
volumeMounts:
- name: storage
mountPath: /prometheus
volumes:
- name: storage
persistentVolumeClaim:
claimName: prometheus-storage
๐ก๏ธ ๋ณด์ ๋ฐ ์ด์ ๋ฒ ์คํธ ํ๋ํฐ์ค
๐ ๋ณด์ ์ค์
1. ์ธ์ฆ ๋ฐ ๊ถํ ๊ด๋ฆฌ
Prometheus ์์ฒด๋ ๊ธฐ๋ณธ์ ์ผ๋ก ์ธ์ฆ ๊ธฐ๋ฅ์ด ์์ด. ํ๋ก๋์
์์๋ ๋ฐ๋์ ๋ณด์ ์กฐ์น๋ฅผ ํด์ผ ํด!
# Nginx๋ฅผ ๋ฆฌ๋ฒ์ค ํ๋ก์๋ก ์ฌ์ฉํ Basic Auth ์์
server {
listen 80;
server_name prometheus.example.com;
location / {
auth_basic "Prometheus";
auth_basic_user_file /etc/nginx/.htpasswd;
proxy_pass http://localhost:9090;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
# .htpasswd ํ์ผ ์์ฑ
htpasswd -c /etc/nginx/.htpasswd admin
2. TLS/SSL ์ค์
# Prometheus TLS ์ค์
# prometheus.yml
global:
external_labels:
cluster: 'production'
# TLS ์ค์
tls_server_config:
cert_file: /etc/prometheus/prometheus.crt
key_file: /etc/prometheus/prometheus.key
client_auth_type: "RequireAndVerifyClientCert"
client_ca_file: /etc/prometheus/ca.crt
# ์คํฌ๋ฉ ํ๊ฒ TLS ์ค์
scrape_configs:
- job_name: 'secure-app'
scheme: https
tls_config:
ca_file: /etc/prometheus/ca.crt
cert_file: /etc/prometheus/client.crt
key_file: /etc/prometheus/client.key
static_configs:
- targets: ['app.example.com:8443']
3. ๋คํธ์ํฌ ๋ณด์
โข ๋ฐฉํ๋ฒฝ ๊ท์น์ผ๋ก Prometheus ํฌํธ ์ ํ
โข VPN์ด๋ Private Network ์ฌ์ฉ
โข ๋ถํ์ํ ๋ฉํธ๋ฆญ ์๋ํฌ์ธํธ ๋
ธ์ถ ๊ธ์ง
โข ๋ฏผ๊ฐํ ์ ๋ณด(๋น๋ฐ๋ฒํธ, API ํค ๋ฑ)๋ฅผ ๋ฉํธ๋ฆญ์ ํฌํจํ์ง ๋ง ๊ฒ!
โข ๋ฉํธ๋ฆญ ๋ ์ด๋ธ์ ๋น๋ฐ๋ฒํธ๋ ํ ํฐ ํฌํจ โ
โข Prometheus๋ฅผ ๊ณต๊ฐ ์ธํฐ๋ท์ ๋ ธ์ถ โ
โข ์ธ์ฆ ์์ด ํ๋ก๋์ ํ๊ฒฝ์์ ์ฌ์ฉ โ
๐ ์ด์ ์ฒดํฌ๋ฆฌ์คํธ
์ผ์ผ ์ฒดํฌ:
โ
Prometheus ์๋ฒ ์ํ ํ์ธ (up ๋ฉํธ๋ฆญ)
โ
์คํฌ๋ฉ ์คํจ ํ์ธ (up == 0)
โ
์๋ฆผ ์ํ ํ์ธ
โ
๋์คํฌ ์ฌ์ฉ๋ ํ์ธ
์ฃผ๊ฐ ์ฒดํฌ:
โ
๋ฉํธ๋ฆญ ์นด๋๋๋ฆฌํฐ ์ฆ๊ฐ ์ถ์ด
โ
์ฟผ๋ฆฌ ์ฑ๋ฅ ๋ถ์
โ
์คํ ๋ฆฌ์ง ์ฆ๊ฐ์จ ํ์ธ
โ
๋ฐฑ์
์ํ ํ์ธ
์๊ฐ ์ฒดํฌ:
โ
Recording Rule ์ต์ ํ
โ
Alert Rule ํ๋
โ
๋ถํ์ํ ๋ฉํธ๋ฆญ ์ ๋ฆฌ
โ
๋ฒ์ ์
๋ฐ์ดํธ ๊ฒํ
โ
์ฉ๋ ๊ณํ ๋ฆฌ๋ทฐ
๐ ๋ฐฑ์ ๋ฐ ๋ณต๊ตฌ
# Prometheus ๋ฐ์ดํฐ ๋ฐฑ์
(์ค๋
์ท ์์ฑ)
curl -XPOST http://localhost:9090/api/v1/admin/tsdb/snapshot
# ์ค๋
์ท ์์น ํ์ธ
# /prometheus/snapshots/<timestamp>
# ๋ฐฑ์
์คํฌ๋ฆฝํธ ์์
#!/bin/bash
BACKUP_DIR="/backup/prometheus"
SNAPSHOT_NAME=$(date +%Y%m%d_%H%M%S)
# ์ค๋
์ท ์์ฑ
curl -XPOST http://localhost:9090/api/v1/admin/tsdb/snapshot
# ์ต์ ์ค๋
์ท ๋ณต์ฌ
LATEST_SNAPSHOT=$(ls -t /prometheus/snapshots | head -1)
cp -r /prometheus/snapshots/$LATEST_SNAPSHOT $BACKUP_DIR/$SNAPSHOT_NAME
# ์ค๋๋ ๋ฐฑ์
์ญ์ (30์ผ ์ด์)
find $BACKUP_DIR -type d -mtime +30 -exec rm -rf {} \;
# ๋ณต๊ตฌ ๋ฐฉ๋ฒ
# 1. Prometheus ์ค์ง
# 2. ๋ฐฑ์
๋ฐ์ดํฐ๋ฅผ /prometheus/data๋ก ๋ณต์ฌ
# 3. Prometheus ์ฌ์์
๐ ์ค์ ์๋๋ฆฌ์ค ๋ฐ ๋ฌธ์ ํด๊ฒฐ
์ค์ ์ด์ํ๋ฉด์ ๋ง์ฃผ์น ์ ์๋ ๋ฌธ์ ๋ค๊ณผ ํด๊ฒฐ ๋ฐฉ๋ฒ์ ์์๋ณด์! ๐ก
๐ฅ ์๋๋ฆฌ์ค 1: ๋ฉํธ๋ฆญ ์๊ฐ ํญ๋ฐ์ ์ผ๋ก ์ฆ๊ฐ!
์ฆ์:
โข Prometheus ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋ ๊ธ์ฆ
โข ์ฟผ๋ฆฌ ์๋ ์ ํ
โข ์คํฌ๋ฉ ์ง์ฐ ๋ฐ์
์์ธ ํ์
:
# 1. ์นด๋๋๋ฆฌํฐ ํญ๋ฐ ํ์ธ
topk(10, count by(__name__) ({__name__=~".+"}))
# 2. ์ต๊ทผ ์ถ๊ฐ๋ ๋ฉํธ๋ฆญ ํ์ธ
topk(10,
count by(__name__) ({__name__=~".+"})
-
count by(__name__) ({__name__=~".+"} offset 1h)
)
# 3. ๋ ์ด๋ธ๋ณ ์นด๋๋๋ฆฌํฐ ํ์ธ
count by(__name__, job) ({__name__=~".+"})
ํด๊ฒฐ ๋ฐฉ๋ฒ:
โข ๊ณ ์นด๋๋๋ฆฌํฐ ๋ ์ด๋ธ ์ ๊ฑฐ (user_id, request_id ๋ฑ)
โข metric_relabel_configs๋ก ๋ถํ์ํ ๋ฉํธ๋ฆญ ํํฐ๋ง
โข ์ ํ๋ฆฌ์ผ์ด์
์ฝ๋ ์์ (๋ฉํธ๋ฆญ ์์ฑ ๋ก์ง ๊ฐ์ )
โข Recording Rule๋ก ์ง๊ณ๋ ๋ฉํธ๋ฆญ๋ง ์ ์ฅ
โ ๏ธ ์๋๋ฆฌ์ค 2: ์คํฌ๋ฉ ์คํจ๊ฐ ๊ณ์ ๋ฐ์!
์ฆ์:
โข up ๋ฉํธ๋ฆญ์ด 0
โข "context deadline exceeded" ์๋ฌ
โข ๋ฉํธ๋ฆญ ๋ฐ์ดํฐ ๋๋ฝ
์์ธ ๋ฐ ํด๊ฒฐ:
# 1. ํ์์์ ํ์ธ ๋ฐ ์กฐ์
scrape_configs:
- job_name: 'slow-app'
scrape_interval: 30s
scrape_timeout: 25s # interval๋ณด๋ค ์๊ฒ!
# 2. ํ๊ฒ ์๋ํฌ์ธํธ ์๋ต ์๊ฐ ํ์ธ
curl -w "@curl-format.txt" -o /dev/null -s http://target:9100/metrics
# curl-format.txt ๋ด์ฉ:
# time_total: %{time_total}s
# 3. ๋คํธ์ํฌ ์ฐ๊ฒฐ ํ์ธ
telnet target-host 9100
curl -v http://target-host:9100/metrics
# 4. ๋ฉํธ๋ฆญ ์๋ํฌ์ธํธ ์ต์ ํ
# - ๋ถํ์ํ ๋ฉํธ๋ฆญ ์ ๊ฑฐ
# - ๋ฉํธ๋ฆญ ๊ณ์ฐ ๋ก์ง ์ต์ ํ
# - ์บ์ฑ ๊ตฌํ
๐พ ์๋๋ฆฌ์ค 3: ๋์คํฌ ๊ณต๊ฐ ๋ถ์กฑ!
์ฆ์:
โข "no space left on device" ์๋ฌ
โข Prometheus ํฌ๋์
โข ์๋ก์ด ๋ฉํธ๋ฆญ ์ ์ฅ ์คํจ
์ฆ์ ์กฐ์น:
# 1. ๋ณด๊ด ๊ธฐ๊ฐ ๋จ์ถ
prometheus \
--storage.tsdb.retention.time=7d \ # 30d์์ 7d๋ก ๋จ์ถ
--storage.tsdb.path=/prometheus
# 2. ์ค๋๋ ๋ฐ์ดํฐ ์๋ ์ญ์
# Prometheus ์ค์ง ํ
rm -rf /prometheus/data/01XXXXXXXXXXXXXX # ์ค๋๋ ๋ธ๋ก ์ญ์
# 3. ๋์คํฌ ์ ๋ฆฌ
# WAL ํ์ผ ํ์ธ
du -sh /prometheus/wal
# 4. ์์ ๋ฐฉํธ: ์ธ๋ถ ์คํ ๋ฆฌ์ง๋ก ์ด๋
# Remote Write ์ค์ ์ผ๋ก ๋ฐ์ดํฐ ์ ์ก
์ฅ๊ธฐ ํด๊ฒฐ์ฑ
:
โข Remote Storage (Thanos, Cortex) ๋์
โข ๋์คํฌ ์ฉ๋ ์ฆ์ค
โข ๋ฉํธ๋ฆญ ์ ์ต์ ํ
โข ๋ค์ด์ํ๋ง ์ ์ฉ
๐ ์๋๋ฆฌ์ค 4: ์ฟผ๋ฆฌ๊ฐ ๋๋ฌด ๋๋ ค์!
์ฆ์:
โข Grafana ๋์๋ณด๋ ๋ก๋ฉ ์ง์ฐ
โข ์ฟผ๋ฆฌ ํ์์์
โข Prometheus CPU ์ฌ์ฉ๋ฅ ๋์
์ต์ ํ ๋ฐฉ๋ฒ:
# 1. ์ฟผ๋ฆฌ ์ฑ๋ฅ ๋ถ์
# Prometheus UI > Status > Query Stats
# 2. ๋นํจ์จ์ ์ธ ์ฟผ๋ฆฌ ๊ฐ์
# Before (๋๋ฆผ)
sum(rate(http_requests_total[5m])) by (method, endpoint, status, instance, job)
# After (๋น ๋ฆ)
sum(rate(http_requests_total{job="my-app"}[5m])) by (method, status)
# 3. Recording Rule ํ์ฉ
# ์์ฃผ ์ฌ์ฉํ๋ ์ฟผ๋ฆฌ๋ฅผ ๋ฏธ๋ฆฌ ๊ณ์ฐ
groups:
- name: performance
interval: 30s
rules:
- record: job:http_requests:rate5m
expr: sum by(job) (rate(http_requests_total[5m]))
# 4. ์ฟผ๋ฆฌ ๋ฒ์ ์ต์ ํ
# Before
rate(http_requests_total[1h]) # ๋๋ฌด ๊ธด ๋ฒ์
# After
rate(http_requests_total[5m]) # ์ ์ ํ ๋ฒ์
# 5. ๋ถํ์ํ ๋ ์ด๋ธ ์ ๊ฑฐ
# Before
sum by(method, endpoint, status, instance, pod, namespace) (...)
# After
sum by(method, status) (...) # ํ์ํ ๋ ์ด๋ธ๋ง
๐จ ์๋๋ฆฌ์ค 5: ์๋ฆผ์ด ๋๋ฌด ๋ง์์! (Alert Fatigue)
์ฆ์:
โข ํ๋ฃจ์ ์๋ฐฑ ๊ฐ์ ์๋ฆผ
โข ์ค์ํ ์๋ฆผ์ ๋์นจ
โข ํ์๋ค์ด ์๋ฆผ์ ๋ฌด์
ํด๊ฒฐ ์ ๋ต:
# 1. ์๋ฆผ ์๊ณ๊ฐ ์กฐ์
# Before (๋๋ฌด ๋ฏผ๊ฐ)
- alert: HighCPU
expr: cpu_usage > 70
for: 1m
# After (์ ์ ํ ์๊ณ๊ฐ๊ณผ ์ง์ ์๊ฐ)
- alert: HighCPU
expr: cpu_usage > 85
for: 10m
# 2. ์๋ฆผ ๊ทธ๋ฃนํ
# alertmanager.yml
route:
group_by: ['alertname', 'cluster']
group_wait: 30s
group_interval: 5m
repeat_interval: 12h
# 3. ์๋ฆผ ์ต์ (Inhibition)
inhibit_rules:
- source_match:
severity: 'critical'
alertname: 'NodeDown'
target_match_re:
severity: 'warning'
equal: ['instance']
# 4. ์ฌ๊ฐ๋ ๋ถ๋ฅ
labels:
severity: critical # ์ฆ์ ๋์ ํ์
severity: warning # ์ฃผ์ ํ์
severity: info # ์ ๋ณด์ฑ
# 5. ๋น์ฆ๋์ค ์๊ฐ ๊ณ ๋ ค
- alert: NonCriticalIssue
expr: some_metric > threshold
for: 5m
labels:
severity: warning
annotations:
summary: "Issue detected"
# ์ฃผ๋ง/์ผ๊ฐ์๋ ์๋ฆผ ์ ๋ณด๋ด๊ธฐ
active_time_intervals:
- business_hours
๐ ์ฌ๋ฅ๋ท์์ Prometheus ์ ๋ฌธ๊ฐ ๋๊ธฐ
์ฌ๊ธฐ๊น์ง ์ฝ์๋ค๋ฉด ๋น์ ์ ์ด๋ฏธ Prometheus ๋ฉํธ๋ฆญ ์์ง ๊ตฌ์กฐ์ ๋ํด ์๋นํ ์ง์์ ๊ฐ์ถ๊ฒ ๋์ด! ๐
ํ์ง๋ง ์ค์ ์ ๋ ๋ค๋ฅธ ์ด์ผ๊ธฐ์ง. ์ค์ ํ๋ก์ ํธ์ ์ ์ฉํ๋ฉด์ ๋ถ๋ชํ๋ ๋ฌธ์ ๋ค, ํน์ ํ๊ฒฝ์ ๋ง๋ ์ต์ ํ, ํ ์ํฉ์ ๋ง๋ ์ด์ ์ ๋ต ๋ฑ์ ๊ฒฝํ์ด ํ์ํด.
์ฌ๋ฅ๋ท์์๋ Prometheus์ ๋ชจ๋ํฐ๋ง ์ ๋ฌธ๊ฐ๋ค์ด ํ๋ํ๊ณ ์์ด. ์ค์ ๊ฒฝํ์ ๊ณต์ ํ๊ณ , ๊ตฌ์ฒด์ ์ธ ๋ฌธ์ ํด๊ฒฐ์ ๋์์ฃผ๊ณ , ๋ฉํ ๋ง๋ ์ ๊ณตํ์ง! ํผ์ ๊ณ ๋ฏผํ์ง ๋ง๊ณ ์ ๋ฌธ๊ฐ์ ๋์์ ๋ฐ์๋ณด๋ ๊ฑด ์ด๋? ๐ช
๋ํ ๋น์ ์ด ์ด๋ฏธ Prometheus ์ ๋ฌธ๊ฐ๋ผ๋ฉด, ์ฌ๋ฅ๋ท์์ ๋น์ ์ ์ง์๊ณผ ๊ฒฝํ์ ๋๋๊ณ ์์ต๋ ์ฐฝ์ถํ ์ ์์ด. DevOps์ ๋ชจ๋ํฐ๋ง ๋ถ์ผ๋ ์์๊ฐ ์ ๋ง ๋ง๊ฑฐ๋ ! ๐
โข PromCon: Prometheus ๊ณต์ ์ปจํผ๋ฐ์ค ์์
โข Awesome Prometheus: github.com/roaldnefs/awesome-prometheus
โข Prometheus Operator: Kubernetes ํ๊ฒฝ ์ต์ ํ
โข Thanos ํ๋ก์ ํธ: ๋๊ท๋ชจ ํ๊ฒฝ ๊ตฌ์ถ
โข ์ปค๋ฎค๋ํฐ: CNCF Slack #prometheus ์ฑ๋
๐ฌ ๋ง๋ฌด๋ฆฌํ๋ฉฐ
Prometheus ๋ฉํธ๋ฆญ ์์ง ๊ตฌ์กฐ์ ๋ํ ๊ธด ์ฌ์ ์ ํจ๊ป ํ์ด! ๐
์ฐ๋ฆฌ๋ Prometheus์ ๊ธฐ๋ณธ ๊ฐ๋
๋ถํฐ ์์ํด์, ์ํคํ
์ฒ, ๋ฉํธ๋ฆญ ํ์
, ์ค์ ๋ฐฉ๋ฒ, PromQL, ์ต์ ํ, ๋ณด์, ๊ทธ๋ฆฌ๊ณ ์ค์ ๋ฌธ์ ํด๊ฒฐ๊น์ง ๋ชจ๋ ๊ฑธ ๋ค๋ค์ด. ์ด ์ ๋๋ฉด ํ๋ก๋์
ํ๊ฒฝ์์ Prometheus๋ฅผ ์์ ์๊ฒ ์ด์ํ ์ ์์ ๊ฑฐ์ผ! ๐ช
ํต์ฌ์ ๋ค์ ํ๋ฒ ์ ๋ฆฌํ๋ฉด:
1. ์ฌ๋ฐ๋ฅธ ๋ฉํธ๋ฆญ ์ค๊ณ๊ฐ ๊ฐ์ฅ ์ค์ํด
โข ์ ์ ํ ๋ฉํธ๋ฆญ ํ์
์ ํ (Counter, Gauge, Histogram, Summary)
โข ๋ฎ์ ์นด๋๋๋ฆฌํฐ ์ ์ง
โข ์๋ฏธ ์๋ ๋ ์ด๋ธ ์ฌ์ฉ
2. ์ํคํ
์ฒ๋ ๊ท๋ชจ์ ๋ง๊ฒ
โข ์๊ท๋ชจ: ๋จ์ผ Prometheus
โข ์ค๊ท๋ชจ: Federation
โข ๋๊ท๋ชจ: Thanos/Cortex
3. ์ฑ๋ฅ ์ต์ ํ๋ ํ์
โข Recording Rules ํ์ฉ
โข ํจ์จ์ ์ธ ์ฟผ๋ฆฌ ์์ฑ
โข ๋ถํ์ํ ๋ฉํธ๋ฆญ ์ ๊ฑฐ
4. ์ด์์ ์ง์์ ์ธ ๊ฐ์
โข ์ ๊ธฐ์ ์ธ ๋ชจ๋ํฐ๋ง
โข ์๋ฆผ ๊ท์น ํ๋
โข ์ฉ๋ ๊ณํ
๋ชจ๋ํฐ๋ง์ ์์คํ
์ด์์ ๋์ด์ ๊ท์ผ. Prometheus๋ฅผ ์ ํ์ฉํ๋ฉด ๋ฌธ์ ๋ฅผ ์กฐ๊ธฐ์ ๋ฐ๊ฒฌํ๊ณ , ์ฑ๋ฅ์ ์ต์ ํํ๊ณ , ๋ ์์ ์ ์ธ ์๋น์ค๋ฅผ ์ ๊ณตํ ์ ์์ด. ๐ฏ
์ด์ ๋น์ ์ฐจ๋ก์ผ! ์ค๋ ๋ฐฐ์ด ๋ด์ฉ์ ์ค์ ํ๋ก์ ํธ์ ์ ์ฉํด๋ณด๊ณ , ๊ฒฝํ์ ์์๊ฐ๋ฉด์ ์ง์ ํ ๋ชจ๋ํฐ๋ง ์ ๋ฌธ๊ฐ๊ฐ ๋๊ธธ ๋ฐ๋ผ! ํ์ดํ
! ๐ฅ
๊ถ๊ธํ ์ ์ด ์๊ฑฐ๋ ๋์์ด ํ์ํ๋ฉด ์ธ์ ๋ ์ฌ๋ฅ๋ท ์ปค๋ฎค๋ํฐ๋ฅผ ํ์ฉํด๋ด. ํจ๊ป ์ฑ์ฅํ๋ ๊ฒ ๊ฐ์ฅ ๋น ๋ฅธ ๊ธธ์ด๋๊น! ๐
๐ ์๊ณ ํ์ด์!
Prometheus ๋ฉํธ๋ฆญ ์์ง ๊ตฌ์กฐ ๋ง์คํฐ๋ฅผ ์ถํํฉ๋๋ค! ๐
๊ด๋ จ ํค์๋
๋๊ธ ์์ฑ
์ด ๊ธ์ ๋ํ ์ฌ๋ฌ๋ถ์ ์๊ฐ์ ๋ค๋ ค์ฃผ์ธ์
๋ก๊ทธ์ธ์ด ํ์ํฉ๋๋ค
๋๊ธ์ ์์ฑํ๋ ค๋ฉด ๋จผ์ ๋ก๊ทธ์ธํด์ฃผ์ธ์.
๋๊ธ 0
์ง์์ธ์ ์ฒ - ์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
- ์ ์๊ถ ๋ฐ ์์ ๊ถ: ๋ณธ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ๋ ์ AI ๊ธฐ์ ๋ก ์์ฑ๋์์ผ๋ฉฐ, ๋ํ๋ฏผ๊ตญ ์ ์๊ถ๋ฒ ๋ฐ ๊ตญ์ ์ ์๊ถ ํ์ฝ์ ์ํด ๋ณดํธ๋ฉ๋๋ค.
- AI ์์ฑ ์ปจํ ์ธ ์ ๋ฒ์ ์ง์: ๋ณธ AI ์์ฑ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ์ง์ ์ฐฝ์๋ฌผ๋ก ์ธ์ ๋๋ฉฐ, ๊ด๋ จ ๋ฒ๊ท์ ๋ฐ๋ผ ์ ์๊ถ ๋ณดํธ๋ฅผ ๋ฐ์ต๋๋ค.
- ์ฌ์ฉ ์ ํ: ์ฌ๋ฅ๋ท์ ๋ช ์์ ์๋ฉด ๋์ ์์ด ๋ณธ ์ปจํ ์ธ ๋ฅผ ๋ณต์ , ์์ , ๋ฐฐํฌ, ๋๋ ์์ ์ ์ผ๋ก ํ์ฉํ๋ ํ์๋ ์๊ฒฉํ ๊ธ์ง๋ฉ๋๋ค.
- ๋ฐ์ดํฐ ์์ง ๊ธ์ง: ๋ณธ ์ปจํ ์ธ ์ ๋ํ ๋ฌด๋จ ์คํฌ๋ํ, ํฌ๋กค๋ง, ๋ฐ ์๋ํ๋ ๋ฐ์ดํฐ ์์ง์ ๋ฒ์ ์ ์ฌ์ ๋์์ด ๋ฉ๋๋ค.
- AI ํ์ต ์ ํ: ์ฌ๋ฅ๋ท์ AI ์์ฑ ์ปจํ ์ธ ๋ฅผ ํ AI ๋ชจ๋ธ ํ์ต์ ๋ฌด๋จ ์ฌ์ฉํ๋ ํ์๋ ๊ธ์ง๋๋ฉฐ, ์ด๋ ์ง์ ์ฌ์ฐ๊ถ ์นจํด๋ก ๊ฐ์ฃผ๋ฉ๋๋ค.
์์ง ๋๊ธ์ด ์์ต๋๋ค.