์•ˆ๋…•ํ•˜์„ธ์š”? ์ด๋ฒˆ ํฌ์ŠคํŒ…์—์„œ๋Š” ์ง€๋‚œ๋ฒˆ Bluemix Node.js ์•ฑ ๋””๋ฒ„๊น… ํ•ด ๋ณด๊ธฐ #1 โ€“ ๋กœ๊ทธ ์ด์šฉํ•˜๊ธฐ์—์„œ ์ž ๊น ์–ธ๊ธ‰ํ–ˆ๋˜ ์™ธ๋ถ€ ๋กœ๊ทธ ์‹œ์Šคํ…œ ์—ฐ๋™์— ๋Œ€ํ•ด ๊ณต์œ ๋“œ๋ฆฌ๊ณ ์ž ํ•ฉ๋‹ˆ๋‹ค.

๋ธ”๋ฃจ๋ฏน์Šค์—์„œ์˜ ๋กœ๊น…

Bluemix ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ๋กœ๊น… ๊ธฐ๋Šฅ์€ ํ”Œ๋žซํผ์— ํ†ตํ•ฉ๋˜์–ด ์žˆ์œผ๋ฉฐ ๊ธฐ๋ณธ์ ์œผ๋กœ ์•ฑ, ์•ฑ ๋Ÿฐํƒ€์ž„ ๋ฐ ํ•ด๋‹น ์•ฑ์ด ์‹คํ–‰๋˜๋Š” ์ปดํ“จํŒ… ๋Ÿฐํƒ€์ž„์— ๋Œ€ํ•œ ๋กœ๊ทธ๋ฅผ ์ˆ˜์ง‘ํ•˜๊ณ  ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค.

https://github.com/IBM-Bluemix/docs/raw/master/monitor_log/logging/images/logging_cf_apps_ov.jpg

Cloud Foundry ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ๋กœ๊ทธ

Bluemix Cloud Foundry ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์€ ๋Œ€์‹œ๋ณด๋“œ UI๋‚˜ CLI (Command Line Interface)์˜ cf logs ๋ช…๋ น์œผ๋กœ ๊ทธ ๋‚ด์šฉ์„ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜, Bluemix๊ฐ€ ๊ฐ€์ง„ Log Storage์— ์ €์žฅ๋œ ๋กœ๊ทธ ์ •๋ณด๋Š” ์ผ์ • ๊ธฐ๊ฐ„(7์ผ) ์ง€๋‚˜๊ฑฐ๋‚˜ ์šฉ๋Ÿ‰(ํ•˜๋ฃจ1G)์ด ์ดˆ๊ณผ๋˜๋Š” ๊ฒฝ์šฐ ์ž๋™์œผ๋กœ ๊ณผ๊ฑฐ ์ •๋ณด๊ฐ€ ์‚ญ์ œ๋˜๋ฏ€๋กœ ์ง€์†์ ์œผ๋กœ ๋ฐœ์ƒํ•˜๋Š” ๋กœ๊ทธ ์ •๋ณด๋ฅผ ํ™œ์šฉํ•˜๋ ค๋ฉด ์™ธ๋ถ€ ๋กœ๊ทธ ์‹œ์Šคํ…œ๊ณผ ์—ฐ๊ฒฐ์„ ํ•ด ์ฃผ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์™ธ๋ถ€ ๋กœ๊ทธ ์‹œ์Šคํ…œ ์—ฐ๊ฒฐ

Bluemix์—์„œ๋Š” Cloud Foundry CLI์˜ create-user-provided-service ๋ช…๋ น(๋˜๋Š” cups)์œผ๋กœ ์‚ฌ์šฉ์ž ์ •์˜ ์„œ๋น„์Šค๋ฅผ ์ƒ์„ฑ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. cups ๋ช…๋ น์˜ -l ์˜ต์…˜์„ ์ด์šฉํ•˜๋ฉด ์™ธ๋ถ€ ๋กœ๊น… ์‹œ์Šคํ…œ์— ๋กœ๊ทธ๋ฅผ ์ „์†กํ•˜๋Š” ์‚ฌ์šฉ์ž ์ •์˜ ์„œ๋น„์Šค๋ฅผ ์ƒ์„ฑํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ์ƒ์„ฑํ•œ ์„œ๋น„์Šค๋ฅผ ๋กœ๊ทธ ๋ฉ”์‹œ์ง€๋ฅผ ์™ธ๋ถ€๋กœ ๋ณด๋‚ด๊ณ ์žํ•˜๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜๊ณผ ์—ฐ๊ฒฐ(bind)ํ•˜๋ฉด ๊ฐ„๋‹จํ•˜๊ฒŒ ์™ธ๋ถ€ ๋กœ๊ทธ ์‹œ์Šคํ…œ๊ณผ ์—ฐ๋™๋ฉ๋‹ˆ๋‹ค.

์™ธ๋ถ€ ๋กœ๊น… ์‹œ์Šคํ…œ์— ๋Œ€ํ•œ ์—ฐ๋™ ์ •๋ณด๋Š” RFC 5424(The Syslog Protocol
), 6587 (Transmission of Syslog Messages over TCP
) ๊ทœ์•ฝ์„ ๋”ฐ๋ฅด๊ณ  ์žˆ์œผ๋ฉฐ, ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์„ธ ๊ฐ€์ง€ ์ „์†ก ๋ฐฉ๋ฒ•์„ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.

  • syslog ํ˜ธ์ŠคํŠธ
  • syslog-tls ํ˜ธ์ŠคํŠธ
  • https post ํ˜ธ์ŠคํŠธ

๊ฐ ๋ฐฉ๋ฒ•์— ๋”ฐ๋ฅธ Endpoint ์ •๋ณด๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

๋กœ๊น… endpoint ๋ช…๋ น ์„ค๋ช…
syslog host cf cups my-logs -l syslog://HOST:PORT ์˜ˆ๋ฅผ ๋“ค์–ด, Papertrail๋กœ ๋กœ๊ทธ๋ฅผ ๋ณด๋‚ด๋ ค๊ณ  ํ•œ๋‹ค๋ฉด, type cf cups my-logs -l syslog://<papertrail-url>์„ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค. <papertrail-url>๋Š” ์‚ฌ์šฉํ•˜๊ณ ์ž ํ•˜๋Š” Papertrail์˜ ๋กœ๊น… endpoint URL๋กœ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค.
syslog-tls hos cf cups my-logs -l syslog-tls://HOST:PORT TLS ๋ฐฉ์‹์œผ๋กœ ์•”ํ˜ธํ™”๋œ ์ •๋ณด๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๋ฐ˜๋“œ์‹œ ๊ณต์ธ CA๋กœ ๋ถ€ํ„ฐ ๋ฐœ๊ธ‰๋ฐ›์€ ์ธ์ฆ์„œ๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•˜๋ฉฐ, self-signed ์ธ์ฆ์„œ๋Š” ์‚ฌ์šฉ ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.
HTTPS POST cf cups my-logs -l https://HOST:PORT ์ด ๋กœ๊น… endpoint๋Š” ๋ธ”๋ฃจ๋ฏน์Šค์—์„œ ์ ‘๊ทผ๊ฐ€๋Šฅํ•œ public ์ธํ„ฐ๋„ท์— ์—ฐ๊ฒฐ๋˜์–ด ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

๋งŒ์•ฝ ์™ธ๋ถ€ ๋กœ๊ทธ ์‹œ์Šคํ…œ์ด ์œ„ ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ๋ผ๋ฉด ์—ฐ๋™์ด ๋˜์ง€ ์•Š์œผ๋ฏ€๋กœ ์ฐธ๊ณ ํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.

๊ทธ๋Ÿผ. ์ด์ œ ๊ฐ„๋‹จํ•œ ์˜ˆ์ œ๋ฅผ ํ†ตํ•ด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ๋กœ๊ทธ ๋ฉ”์‹œ์ง€๊ฐ€ ์™ธ๋ถ€๋กœ ์ž˜ ์—ฐ๋™๋˜๋Š”์ง€ ํ™•์ธ ํ•ด ๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

๊ธฐ๋ณธ ๊ตฌ์„ฑ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  • ๋กœ๊ทธ ๋ฉ”์‹œ์ง€ ์ƒ์„ฑ์•ฑ
  • ๋กœ๊ทธ ๋ฉ”์‹œ์ง€ ์ˆ˜์‹ ์•ฑ
  • ๋กœ๊ทธ ๋ฉ”์‹œ์ง€ ์—ฐ๊ฒฐ ์‚ฌ์šฉ์ž ์ •์˜ ์„œ๋น„์Šค
  • Slack ์—ฐ๋™ Credential ์‚ฌ์šฉ์ž ์ •์˜ ์„œ๋น„์Šค

๋กœ๊ทธ ๋ฉ”์‹œ์ง€ ์ƒ์„ฑ Bluemix ์•ฑ ์ž‘์„ฑ

๋กœ๊ทธ ๋ฉ”์‹œ์ง€ ์ƒ์„ฑ ์•ฑ์€ Bluemix GitHub์— ์žˆ๋Š” https://github.com/IBM-Bluemix/loggy-node๋ฅผ ์ด์šฉํ•ด ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. loggy-node๋Š” ๋กœ๊ทธ ๋ฉ”์‹œ์ง€๊ฐ€ ๋ฐœ์ƒํ•˜๋Š” ์ƒํ™ฉ์„ ๋‚˜ํƒ€๋‚ด๊ธฐ ์œ„ํ•œ ๊ฒƒ์œผ๋กœ ํ”„๋กœ์„ธ์Šค๊ฐ€ ์—๋Ÿฌ์ฝ”๋“œ 0 ๋˜๋Š” 1๋กœ ์ข…๋ฃŒํ•  ๋•Œ, catch๋˜์ง€ ์•Š๋Š” exception์„ ๋ฐœ์ƒํ•  ๋•Œ out-of-memory ์ƒํ™ฉ์„ ๋ฐœ์ƒํ•˜๋Š” ์ƒํ™ฉ์„ ๊ฐ€์ •ํ•˜๋Š” ์•ฑ์ž…๋‹ˆ๋‹ค.

์‹คํ–‰ ์‹œ ๋‚˜ํƒ€๋‚˜๋Š” ํ™”๋ฉด์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

loggy-node

๊ฐ ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ ์‹คํ–‰ํ•ด ๋ณด๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์ข…๋ฃŒ๋˜๋ฉฐ ์˜ค๋ฅ˜ ๋ฉ”์‹œ์ง€์™€ ํ•จ๊ป˜ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์€ ์ž๋™์œผ๋กœ ์žฌ์‹œ์ž‘ ํ•ฉ๋‹ˆ๋‹ค.

์šฐ์„  local ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์—์„œ ํ…Œ์ŠคํŠธ ํ•ด ๋ณด๊ธฐ ์œ„ํ•ด ๋‹ค์Œ ๋ช…๋ น์œผ๋กœ ์ฝ”๋“œ๋ฅผ ๋ฐ›๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.

git clone https://github.com/IBM-Bluemix/loggy-node.git

์ฐธ๊ณ ๋กœ loggy-node๋Š” build ๋„๊ตฌ๋กœ Coffee script์˜ cake ๋ฅผ ์ด์šฉํ•˜๊ณ  ์žˆ์œผ๋ฉฐ package.json์˜ devDependencies ํ•ญ๋ชฉ์— bower, cakex, coffee-script๊ฐ€ ์žˆ์œผ๋ฏ€๋กœ local ๊ฐœ๋ฐœํ™˜๊ฒฝ์—์„œ๋Š” ์ด๋ฅผ ์ด์šฉํ•˜์—ฌ ๋‹ค์‹œ build ํ•ด ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ฝ”๋“œ๋ฅผ ๋ฐ›์•˜์œผ๋ฉด loggy-node ํด๋”๋กœ ์ด๋™ํ•ด์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์ด npm install ๋ช…๋ น์œผ๋กœ ํ•„์š”ํ•œ ๋ชจ๋“ˆ์„ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.

npm install

์„ค์น˜๊ฐ€ ์™„๋ฃŒ๋˜์—ˆ๋‹ค๋ฉด npm run serve ๋ช…๋ น์œผ๋กœ ๋ฐ”๋กœ ์‹คํ–‰ ํ•ด ๋ณผ ์ˆ˜ ์žˆ์œผ๋ฉฐ, code๊ฐ€ ๋ณ€๊ฒฝ๋œ ๊ฒฝ์šฐ npm run watch๋ฅผ ์ด์šฉํ•˜๋ฉด ๋ณ€๊ฒฝ๋œ coffee script๋ฅผ ํ™•์ธ ํ›„ ๋‹ค์‹œ ๋นŒ๋“œ, ์žฌ์‹œ์ž‘ ํ•˜๋„๋ก ๋™์ž‘ํ•ฉ๋‹ˆ๋‹ค. ์ด ๋•Œ bower๋ฅผ ํ†ตํ•ด ํ•„์š”ํ•œ ์›น ๋ฆฌ์†Œ์Šค๋ฅผ ๋‹ค์šด๋กœ๋“œ ๋ฐ›๊ฒŒ๋ฉ๋‹ˆ๋‹ค.

์ด์ œ ์ด ์•ฑ์„ cf push ๋ช…๋ น์„ ์ด์šฉํ•˜์—ฌ Bluemix๋กœ ๋ฐฐํฌํ•ด ๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ๋‹ค๋ฅธ ์˜ต์…˜ ์—†์ด cf push ๋ช…๋ น์„ ์‹คํ–‰ํ•˜๋Š” ๊ฒฝ์šฐ manifest.yml์— ๋“ฑ๋ก๋˜์–ด ์žˆ๋Š” ์ •๋ณด๋กœ ๋ฐฐํฌ๋˜๋ฏ€๋กœ hostname์ด ์ด๋ฏธ ์‚ฌ์šฉ ์ค‘ ์ด๋ผ๋ฉฐ ๋ฐฐํฌ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ manifest.yml์˜ ๋‚ด์šฉ์„ ์ˆ˜์ •ํ•˜์—ฌ hostname์„ ๋ณ€๊ฒฝํ•˜๊ฑฐ๋‚˜, ๋‹ค์Œ๊ณผ ๊ฐ™์ด cf ๋ช…๋ น์— --hostname ์˜ต์…˜์„ ์ด์šฉํ•˜์—ฌ ๋ฐฐํฌํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ด์šฉํ•ด ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

cf push loggy-node-hongjs --hostname loggy-node-hongjs

loggy-node-hongjs-deployed

์ •์ƒ ๋ฐฐํฌ๊ฐ€ ๋˜์—ˆ๋‹ค๋ฉด cf logs ๋ช…๋ น์„ ์ด์šฉํ•˜์—ฌ ์–ด๋–ค ๋ฉ”์‹œ์ง€๊ฐ€ ๋‚˜ํƒ€๋‚˜๋Š”์ง€ ํ™•์ธ ํ•ด ๋ณผ ์ˆ˜ ์žˆ๋„๋ก ํ•ด ๋†“๊ณ  ์›น ๋ธŒ๋ผ์šฐ์ €๋ฅผ ํ†ตํ•ด loggy-node-hongjs url์— ์ ‘๊ทผํ•ด ๋ณด๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.

cf logs loggy-node-hongjs

https://loggy-node-hongjs.mybluemix.net์— ์ ‘๊ทผํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ํ™”๋ฉด๊ณผ ํ•จ๊ป˜ ๊ธฐ๋ณธ ๋กœ๊ทธ ๋ฉ”์‹œ์ง€๊ฐ€ ์ถœ๋ ฅ๋ฉ๋‹ˆ๋‹ค.

loggy-node

loggy-node

์ฒซ ๋ฒˆ์งธ have the process exit with status 0 ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฉ”์‹œ์ง€์™€ ํ•จ๊ป˜ loggy-node-hongjs ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์žฌ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

loggy-node

๋กœ๊ทธ๋ฅผ ๋ฐœ์ƒํ•˜๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์ค€๋น„๋˜์—ˆ์œผ๋‹ˆ ์ด์ œ ๋กœ๊ทธ๋ฅผ ์ˆ˜์ง‘ํ•˜๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋งŒ๋“ค์–ด ๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

๋กœ๊ทธ ๋ฉ”์‹œ์ง€ ์ˆ˜์ง‘์„ ์œ„ํ•œ Bluemix ์•ฑ ์ƒ์„ฑ

๋กœ๊ทธ ๋ฉ”์‹œ์ง€ ์ˆ˜์ง‘ ์•ฑ์€ Bluemix GitHub์— ์žˆ๋Š” cf-log-slack๋ฅผ ์ด์šฉํ•ด ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. cf-log-slack๋Š” HTTPS/POST๋กœ ์ˆ˜์ง‘ํ•œ ๋ฉ”์‹œ์ง€๋ฅผ Slack Web hook์„ ์ด์šฉํ•˜์—ฌ Slack ์ฑ„๋„๋กœ ์ „๋‹ฌํ•˜๋Š” Log drain ์•ฑ์ž…๋‹ˆ๋‹ค. ๋‹ค๋งŒ, ๋กœ๊ทธ ๋ฉ”์‹œ์ง€๋ฅผ ๊ฐ€๊ณตํ•˜์—ฌ ์ฒ˜๋ฆฌํ•  ๋•Œ ๋ชจ๋“  ๋ฉ”์‹œ์ง€๊ฐ€ ์•„๋‹Œ ์ผ์ •ํ•œ ํ˜•์‹์„ ๊ฐ€์ง„ ๋ฉ”์‹œ์ง€๋งŒ ์ฒ˜๋ฆฌํ•˜๋„๋ก ๋˜์–ด ์žˆ์–ด์„œ ๋ฐ”๋กœ ์—ฐ๊ฒฐ์‹œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ๋ณธ ์˜ˆ์ œ์— ๋งž์ถฐ ์•ฝ๊ฐ„ ์ˆ˜์ •ํ•œ ์ฝ”๋“œ https://github.com/mc500/cf-log-slack๋ฅผ ์ด์šฉํ•ด ๋ณด๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.

์šฐ์„  local ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์—์„œ ๋‹ค์Œ ๋ช…๋ น์œผ๋กœ ์ฝ”๋“œ๋ฅผ ๋ฐ›๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.

git clone https://github.com/mc500/cf-log-slack.git

์ฝ”๋“œ๋ฅผ ๋ฐ›์•˜์œผ๋ฉด cf-log-slack ํด๋”๋กœ ์ด๋™ํ•ด์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์ด npm install ๋ช…๋ น์œผ๋กœ ํ•„์š”ํ•œ ๋ชจ๋“ˆ์„ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.

npm install

์„ค์น˜๊ฐ€ ์™„๋ฃŒ๋˜์—ˆ๋‹ค๋ฉด npm run serve ๋ช…๋ น์œผ๋กœ ๋ฐ”๋กœ ์‹คํ–‰ ํ•ด ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  loggy-node์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ code๊ฐ€ ๋ณ€๊ฒฝ๋œ ๊ฒฝ์šฐ npm run watch๋ฅผ ์ด์šฉํ•˜๋ฉด ๋ณ€๊ฒฝ๋œ coffee script๋ฅผ ํ™•์ธ ํ›„ ๋‹ค์‹œ ๋นŒ๋“œ, ์žฌ์‹œ์ž‘ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด์ œ ์ด ์•ฑ์„ cf push ๋ช…๋ น์œผ๋กœ Bluemix์— ๋ฐฐํฌํ•ด ๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

cf push cf-log-slack-hongjs --hostname cf-log-slack-hongjs

cf-log-slack-hongjs-deployed

์ •์ƒ ๋ฐฐํฌ๊ฐ€ ๋˜์—ˆ๋‹ค๋ฉด ์ด์ œ ์ด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜๊ณผ Slack์™€ ์—ฐ๋™์„ ์œ„ํ•œ ์„œ๋น„์Šค๋ฅผ ๋งŒ๋“ค์–ด ๋ด…๋‹ˆ๋‹ค.

Slack ์—ฐ๋™ Credential ์‚ฌ์šฉ์ž ์ •์˜ ์„œ๋น„์Šค

Slack์˜ ์•Œ๋ฆผ์„ ๋ฐ›์œผ๋ ค๋ฉด ์Šฌ๋ž™ ๊ณ„์ •๊ณผ ํŒ€์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ์šฐ์„  Slack์— ๊ฐ€์ž…ํ•˜๊ณ  ํŒ€์„ ํ•˜๋‚˜ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ , ์Šฌ๋ž™ ์„ค์ • ๋ฉ”๋‰ด ์ค‘ Apps & Integration ํ•ญ๋ชฉ๋ฅผ ์„ ํƒํ•˜๋ฉด App Directory๋ผ๋Š” ํ™”๋ฉด์ด ๋‚˜ํƒ€๋‚ฉ๋‹ˆ๋‹ค. ์ด ํ™”๋ฉด์˜ ๊ฒ€์ƒ‰ ๊ธฐ๋Šฅ์„ ์ด์šฉํ•˜์—ฌ Incoming Webhooks ์„ ์ฐพ๊ณ  ์ด๋ฅผ ์„ ํƒํ•˜๋ฉด ํ˜„์žฌ ์Šฌ๋ž™์— ์ถ”๊ฐ€ ๋ฐ ์„ค์ • ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Incoming Webhook์„ ์œ„ํ•œ ์ƒ์„ธ ์„ค์ • ์ •๋ณด๋Š” Slack Incoming Webhooks๋ฅผ ์ฐธ๊ณ  ๋ฐ”๋ž๋‹ˆ๋‹ค.

์ €์˜ ๊ฒฝ์šฐ๋Š” #general ์ฑ„๋„๋กœ ๋ฉ”์‹œ์ง€๋ฅผ ๋ฐ›์„ ์ˆ˜ ์žˆ๋„๋ก ์•„๋ž˜์™€ ๊ฐ™์ด ์„ค์ • ํ–ˆ์Šต๋‹ˆ๋‹ค.

slack-incoming-webhook-settings

์ด์ œ Bluemix ์‚ฌ์šฉ์ž ์ •์˜ ์„œ๋น„์Šค๋ฅผ ์ƒ์„ฑํ•ด ๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ์‚ฌ์šฉ์ž ์ •์˜ ์„œ๋น„์Šค ์ƒ์„ฑ์€ cf create-user-provided-service ๋ช…๋ น (๋˜๋Š” cups) ๋ฅผ ์ด์šฉํ•ฉ๋‹ˆ๋‹ค. ์ด ๋ช…๋ น์˜ ์˜ต์…˜ ์ค‘ -p ์˜ต์…˜์€ ์„œ๋น„์Šค๋ฅผ ์—ฐ๊ฒฐ(bind) ํ•  ๋•Œ credential ์ •๋ณด๋กœ ํŠน์ • property๋ฅผ ์ œ๊ณตํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์œผ๋กœ ์ด ์„œ๋น„์Šค์™€ ์—ฐ๊ฒฐํ•  ์•ฑ์ธ cf-log-slack์—์„œ ํ•„์š”๋ฃŒ ํ•˜๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ •๋ณด๋ฅผ ์ž…๋ ฅ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • url (ํ•„์ˆ˜)
  • username (์˜ต์…˜, slack payload property์™€ ๋™์ผ)
  • icon_url (์˜ต์…˜, slack payload property์™€ ๋™์ผ)
  • icon_emoji (์˜ต์…˜, slack payload property์™€ ๋™์ผ)
  • channel (์˜ต์…˜, slack payload property์™€ ๋™์ผ)

์ด๋ฒˆ ์˜ˆ์ œ์—์„œ๋Š” Webhook URL ํ•˜๋‚˜๋งŒ์œผ๋กœ๋„ ์ถฉ๋ถ„ํ•˜๋ฏ€๋กœ ๋‹ค๋ฅธ ์ •๋ณด๋Š” ์ž…๋ ฅํ•˜์ง€ ์•Š๊ณ  url ๊ฐ’๋งŒ ์„ค์ •ํ•˜๋„๋ก ํ•ฉ๋‹ˆ๋‹ค. Webhook URL์ด ํ™•๋ณด ๋˜์—ˆ๋‹ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ช…๋ น์œผ๋กœ ์‚ฌ์šฉ์ž ์ •์˜ ์„œ๋น„์Šค๋ฅผ ์ƒ์„ฑํ•˜๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.

cf cups -p url

create-cups-slack-general

์„œ๋น„์Šค๊ฐ€ ๋งŒ๋“ค์–ด ์กŒ๋‹ค๋ฉด ์ด์ œ ์•ž์„œ ๋งŒ๋“ค์—ˆ๋˜ cf-log-slack-hongjs ์™€ ์—ฐ๊ฒฐํ•˜๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.

cf bind-service cf-log-slack-hongjs slack-general

bind-service-slack-general

์„œ๋น„์Šค๊ฐ€ ์—ฐ๊ฒฐ๋˜์—ˆ๋‹ค๋ฉด ๋‹ค์Œ ๋ช…๋ น์œผ๋กœ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์žฌ์‹œ๋™ ํ•ฉ๋‹ˆ๋‹ค.

cf restage cf-log-slack-hongjs

restage-cf-log-slack-hongjs

์—ฐ๊ฒฐ๋œ ์„œ๋น„์Šค์— ๋Œ€ํ•œ ์ •๋ณด๋Š” Dashboard UI์—์„œ Slack Webhook URL์ด VCAPS_SERVICES์— ์žˆ๋Š” ๋‚ด์šฉ์„ ํ™•์ธ ํ•ด ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

vcap-services-slack-general

์‚ฌ์šฉ์ž ์ •์˜ ๋กœ๊ทธ ์„œ๋น„์Šค ์ƒ์„ฑ

๋กœ๊ทธ ์„œ๋น„์Šค๋ฅผ ์œ„ํ•œ ์‚ฌ์šฉ์ž ์ •์˜ ์„œ๋น„์Šค๋„ ์—ญ์‹œ cf create-user-provided-service ๋ช…๋ น (๋˜๋Š” cups) ๋ฅผ ์ด์šฉํ•ฉ๋‹ˆ๋‹ค. ์ด ๋ช…๋ น์˜ ์˜ต์…˜ ์ค‘ ํ•˜๋‚˜์ธ -l ์˜ต์…˜์„ ์ด์šฉํ•˜์—ฌ ์™ธ๋ถ€ ๋กœ๊ทธ ์„œ๋น„์Šค URL์„ ์ง€์ •ํ•˜๋ฉด, ์ด ์„œ๋น„์Šค์™€ ์—ฐ๊ฒฐ๋˜๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ๋กœ๊ทธ ๋ฉ”์‹œ์ง€๊ฐ€ ์ง€์ •๋œ URL์„ ํ†ตํ•ด ์ „๋‹ฌ ๋ฉ๋‹ˆ๋‹ค. ๋‹ค์Œ๊ณผ ๊ฐ™์ด slack-logger-hongjs๋ž€ ์ด๋ฆ„์œผ๋กœ ์„œ๋น„์Šค๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

cf cups slack-logger-hongjs -l https://cf-log-slack-hongjs.mybluemix.net/slack-general

create-cups-slack-logger-hongjs

์ด๋ ‡๊ฒŒ ์ƒ์„ฑํ•œ ์„œ๋น„์Šค๋ฅผ ์•ž์„œ ๋งŒ๋“ค์–ด ๋†“์€ loggy-node-hongjs ์•ฑ๊ณผ ์—ฐ๊ฒฐํ•ด ๋ด…๋‹ˆ๋‹ค.

cf bind-service loggy-node-hongjs slack-logger-hongjs

bind-cups-slack-logger-hongjs

Command Line๋ฅผ ํ†ตํ•ด ์„œ๋น„์Šค๋ฅผ ์—ฐ๊ฒฐํ•˜์˜€์œผ๋ฏ€๋กœ ์ˆ˜๋™์œผ๋กœ ์žฌ์‹œ์ž‘ ํ•ด ์ค๋‹ˆ๋‹ค.

cf restage loggy-node-hongjs

๋งŒ์•ฝ Dashboard UI์—์„œ ํ™•์ธํ•ด ๋ณธ๋‹ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ •๋ณด๊ฐ€ VCAP_SERVICES์— ๋“ฑ๋ก๋œ ์ •๋ณด๋ฅผ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

vcap-services-slack-logger-hongjs

์žฌ์‹œ์ž‘๊ณผ ๋™์‹œ์— ๋กœ๊ทธ ๋ฉ”์‹œ์ง€๊ฐ€ cf-log-slack-hongjs๋กœ ์ „์†ก๋˜์ง€๋งŒ, ํ™•์‹คํ•˜๊ฒŒ ํ™•์ธ ํ•˜๊ธฐ ์œ„ํ•ด loggy-node-hongjs์˜ throw an uncatched exception ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ์„œ ํ™•์ธ ํ•ด ๋ด…๋‹ˆ๋‹ค.

loggy-node

์ •์ƒ์ ์œผ๋กœ ์„ค์ •๋˜์—ˆ๋‹ค๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด slack์œผ๋กœ ๋ฉ”์‹œ์ง€๊ฐ€ ์ „๋‹ฌ๋ฉ๋‹ˆ๋‹ค.

slack-logs

์ฐธ๊ณ 

ํ† ๋ก  ์ฐธ๊ฐ€

์ด๋ฉ”์ผ์€ ๊ณต๊ฐœ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ํ•„์ˆ˜ ์ž…๋ ฅ์ฐฝ์€ * ๋กœ ํ‘œ์‹œ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.