Consul, Discovery Server
Consul HealthCheck 어떻게 작동되는가?
- consul HelathCheck는 말그대로 consul cluster로 구성된 서비스에 HealthCheck를 의미한다.
- 특정 노드, 서비스 등의 status를 관리하는 용도로 사용됩니다.
service register와 비슷하게 check definition을 이용하여 helth check 를 붙입니다. 물론 http 통신으로도 붙일 수 있구요.
여기선 bash를 통해서 보낼겁니다. 당연 enable_script_checks
가 true로 설정되어 돌아가있어야합니다.
n2에 접속하여 config 파일을 추가해줍시다.
echo '{"check": {"name": "ping",
"args": ["ping", "-c1", "google.com"], "interval": "30s"}}' \
> /etc/consul.d/ping.json
echo '{"service": {"name": "web", "tags": ["rails"], "port": 80,
"check": {"args": ["curl", "localhost"], "interval": "10s"}}}' \
> /etc/consul.d/web.json
첫 번쨰 check는 host-level의 check입니다.
두 번째 check는 서비스에 달린 check입니다.
다됬네요. 리로드합시다.
consul reload
curl http://localhost:8500/v1/health/state/critical
[
{
"Node": "agent-two",
"CheckID": "service:web",
"Name": "Service 'web' check",
"Status": "critical",
"Notes": "",
"Output": "",
"ServiceID": "web",
"ServiceName": "web",
"ServiceTags": [
"rails"
],
"Definition": {},
"CreateIndex": 218,
"ModifyIndex": 218
}
]
위와 같이 critical한 status만 받아볼 수 있습니다.
실제 달린 서비스의 좀더 자세한 status를 보고 싶다면..
curl http://127.0.0.1:8500/v1/agent/checks
{
"ping": {
"Node": "agent-two",
"CheckID": "ping",
"Name": "ping",
"Status": "passing",
"Notes": "",
"Output": "google.com\n",
"ServiceID": "",
"ServiceName": "",
"ServiceTags": [],
"Definition": {},
"CreateIndex": 0,
"ModifyIndex": 0
},
"service:web": {
"Node": "agent-two",
"CheckID": "service:web",
"Name": "Service 'web' check",
"Status": "critical",
"Notes": "",
"Output": " % Total % Received % Xferd Average Speed Time Time Time Current\n Dload Upload Total Spent Left Speed\n\r 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (7) Failed to connect to localhost port 80: Connection refused\n",
"ServiceID": "web",
"ServiceName": "web",
"ServiceTags": [
"rails"
],
"Definition": {},
"CreateIndex": 0,
"ModifyIndex": 0
}
}