# External health check of backend services

**URL:** https://discourse.haproxy.org/t/external-health-check-of-backend-services/285
**Category:** Help!
**Created:** [May 13, 2016, 11:48am UTC](https://discourse.haproxy.org/t/external-health-check-of-backend-services/285 "2016-05-13T11:48:46Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![bence.takacs](https://avatars.discourse-cdn.com/v4/letter/b/bc8723/32.png) [@bence.takacs](https://discourse.haproxy.org/u/bence.takacs)
#### Post date: [May 13, 2016, 11:48am UTC](https://discourse.haproxy.org/t/external-health-check-of-backend-services/285/1 "2016-05-13T11:48:46Z")

</div>

Hi

I’m hosting different web-based services on the same machine and using haproxy as a reverse proxy, so based on the request hostname I forward the request into different services on different ports.

I want to check all the backends’ availability from external server.  
Haproxy’s check mechanism is totally Ok for me, but I want to expose its result for the outside world.

Now if I check the backend’s availability with ‘nc {hostname} 80’ it always responds with a false ‘succeeded!’ even if the backend is down.

configuration:

> frontend http-in  
> bind \*:80  
> acl is\_bck01 hdr\_end(host) -i bck01.myhost.local  
> use\_backend bck01 if is\_bck01  
> …
> 
> backend bck01  
> balance roundrobin  
> option httpclose  
> option forwardfor  
> server s2 127.0.0.1:8081 maxconn 32 check  
> …

What is the correct way to check the availability of backends, or how can I fix the configuration to support the netcat/telnet based tcp port check?

Regards:  
Bence

---

<div class="post-metadata">

### Author: ![bence.takacs](https://avatars.discourse-cdn.com/v4/letter/b/bc8723/32.png) [@bence.takacs](https://discourse.haproxy.org/u/bence.takacs)
#### Post date: [May 17, 2016, 7:55am UTC](https://discourse.haproxy.org/t/external-health-check-of-backend-services/285/2 "2016-05-17T07:55:17Z")

</div>

So it seems that haproxy won’t close the port access.  
( [Is there a way to close a listener port when all backends went down?](http://discourse.haproxy.org/t/is-there-a-way-to-close-a-listener-port-when-all-backends-went-down/219) )

So what is the proper way of external health check?  
How can I

1. Configure haproxy to expose that information
2. Check that with external application

Could anybody give me some pointers?

I see there is an ‘health\_check’ directive which checks haproxy’s own availability.

> <https://stackoverflow.com/questions/23512029/haproxy-health-check>

…and there is an ‘external-check’ option which runs a command on the server:  
[https://cbonte.github.io/haproxy-dconv/configuration-1.6.html#option%20external-check](https://cbonte.github.io/haproxy-dconv/configuration-1.6.html#option%20external-check)

Regards:  
Bence

---

<div class="post-metadata">

### Author: ![bence.takacs](https://avatars.discourse-cdn.com/v4/letter/b/bc8723/32.png) [@bence.takacs](https://discourse.haproxy.org/u/bence.takacs)
#### Post date: [May 17, 2016, 9:17pm UTC](https://discourse.haproxy.org/t/external-health-check-of-backend-services/285/3 "2016-05-17T21:17:57Z")

</div>

Is it something not supported or so hard to configure?  
I see people checking this and passing by…

---

<div class="post-metadata">

### Author: ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)
#### Post date: [May 18, 2016, 11:58am UTC](https://discourse.haproxy.org/t/external-health-check-of-backend-services/285/4 "2016-05-18T11:58:35Z")

</div>

What are you asking?

Are you asking to close the frontend port when no backends are available?  
–\> Thats not supported. Please use intelligent l7 health checks, not simple layer 4 port checks from additional frontend proxy layers.

Are you asking to use external health checks for the backends?  
–\> Check [external-check](http://cbonte.github.io/haproxy-dconv/configuration-1.6.html#option%20external-check) documentation.

---

<div class="post-metadata">

### Author: ![bence.takacs](https://avatars.discourse-cdn.com/v4/letter/b/bc8723/32.png) [@bence.takacs](https://discourse.haproxy.org/u/bence.takacs)
#### Post date: [May 18, 2016, 2:30pm UTC](https://discourse.haproxy.org/t/external-health-check-of-backend-services/285/5 "2016-05-18T14:30:59Z")

</div>

I just want the emission/exposion of the currently well-known backend status.

> Are you asking to close the frontend port when no backends are available?  
> →   
> Thats not supported. Please use intelligent l7 health checks, not  
> simple layer 4 port checks from additional frontend proxy layers.

Do you mean using layer 7 checks (http request/response checks) from outside or from haproxy config?

> Are you asking to use external health checks for the backends?  
> → Check external-check documentation.

It says I would need to define a script on the server itself. This is something which I definitely need only if I would need to write my own service checks. But this is not the case.

What about ‘http-response set-status’ can I set the http status based on haproxy’s health check status?  
([HAProxy version 1.6.6 - Configuration Manual](http://cbonte.github.io/haproxy-dconv/configuration-1.6.html#4-http-response))

---

<div class="post-metadata">

### Author: ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)
#### Post date: [May 18, 2016, 3:14pm UTC](https://discourse.haproxy.org/t/external-health-check-of-backend-services/285/6 "2016-05-18T15:14:42Z")

</div>

> [@bence.takacs](#):
>
> I just want the emission/exposion of the currently well-known backend status.

To monitor the haproxy backend status? You can monitor haproxies syslog messages, check the unix admin socket or the stats interface.

---

<div class="post-metadata">

### Author: ![bence.takacs](https://avatars.discourse-cdn.com/v4/letter/b/bc8723/32.png) [@bence.takacs](https://discourse.haproxy.org/u/bence.takacs)
#### Post date: [May 18, 2016, 3:21pm UTC](https://discourse.haproxy.org/t/external-health-check-of-backend-services/285/7 "2016-05-18T15:21:33Z")

</div>

Solved! You were right: I needed to check the HTTP protocol (layer7) from outside.

This did the trick:

> curl -Ivs [http://bck01.myhost.local](http://bck01.myhost.local) 2\>&1 | grep “\< HTTP/”| awk ‘{print $3}’
