Healthcheck for TCP mode

Have to make an health check for haproxy running in TCP mode.
For http we can mention the monitor-uri to get 200 response if the service is up and 400 if it is down.
Is there any similar way for TCP mode.

Iam checking only for the service is UP or NOT not the backend servers

Absolutely, use the tcp-check expect keyword.

Thanks for your reply,
Need some more clarification on this

But in http mode my configuration file will be

frontend act
bind *:80
mode http

monitor-uri /haproxy

if i use curl localhost:80/haproxy
my response will be 200 ok if the service is UP

same i need for TCP mode will it be possible

example

frontend act
mode tcp
bind *:80

monitor-uri /haproxy

for this case curl will not be able to get the header response

So if i use tcp-check except can i get the same response if the service is UP
If yes how can i get the response

So you need haproxy to return 200 for a healthcheck on /haproxy that is not on haproxy, but external, like another frontend layer of proxies? Can you please describe your entire configuration?

You definitely cannot insert HTTP responses into a TCP mode frontend, there is simply no way to do that technically. But I’m not sure I got you right here.

The concept is , If my service is down with the port 80 i wanted to be notified.
so if it is of http mode we can get the response
how can we get any notification if the service is down for TCP mode

Configuration:

Proxy incoming traffic as HTTP requests

mode tcp
frontend incoming_act
bind *:80

Create a monitorable URI which returns a 200 if haproxy is up

monitor-uri /haproxy/monitor

You cannot create a monitorable URI when haproxy is configured in tcp mode. This is technically impossible.

Can you explain where you are monitoring this from?

This is for checking the status of the service.
If the service is down we can get alert easily by this.
Or if the process gets idle we will get the false alert that service is UP, But the requests are not received by the haproxy.
Inorder to avoid this circumstances iam trying to monitor this.

Can you please let me know some other way for TCP mode monitoring.

You don’t to that inband. That’s a terrible idea, even for HTTP.
That’s why we have unix domain and admin sockets.

What did you configure for monitor fail? How would you like to decide if haproxy is healthy or not?

We are not using monitor fail here,Only monitor uri,
if my process gets idle or stopped i want to get an alert that my haproxy is unhealthy.

Idle means the haproxy is not accepting any requests
but if we check the status of the service it will be shown up.

but if you try hitting the url it will not give any response for it

I don’t know what you mean by “the status of the service it will be shown up”.

Where, based on what checks? I suggest you enable stats interfaces or the admin socket and query the status that way. Or you make proper checks through haproxy hitting your backend application.

More about stats interface and the admin socket here:
http://cbonte.github.io/haproxy-dconv/1.7/configuration.html#4.2-stats%20enable
http://cbonte.github.io/haproxy-dconv/1.7/management.html