HTTP API and health check

1,029 views
Skip to first unread message

Antoine Lang-Cavelier

unread,
Nov 25, 2015, 10:56:36 PM11/25/15
to Consul
Hi,

It seems I'm struggling to understand the purpose of the HTTP API for registering nodes. I try to use it in order to have nodes with an agent-less configuration. Basically, I want to check that a process is running on that node or that a specific port is open.

This is what I'm trying to do:
- Register a new node with a specific service (port 111).
- Create a health check - a script one, testing the port

    "Datacenter": "dev",
    "Node": "ServerName1",
    "Address": "192.168.18.46",
    "Service": {
        "Service": "myservice",
        "Address": "192.168.18.46",
        "Port": 111
    },
    "check": {
        "Node": "ServerName1",
        "name": "mycheck",
        "id": "mycheck",
        "script": "/usr/bin/nc -z 192.168.18.46 111",
        "interval": "10s"
    }
}' 


I haven't found a lot of curl examples using the HTTP API. The documentation is great but lack of "curl -X PUT" examples.
If someone could explain how can I use the HTTP API in order to check a process, that will be welcome.

James Phillips

unread,
Nov 26, 2015, 12:42:36 PM11/26/15
to consu...@googlegroups.com
Hi Antoine,

The Catalog API is used by the agents to report the state of their services and checks to the Consul servers. It's very unusual to talk to the Catalog API directly, and Consul doesn't really support running checks without a Consul agent. If you run an agent on a node you can register services and checks for that node using the Agent API by doing a curl -X PUT with a body like this:


It's also possible to define health checks in the agent's configuration files. The agent runs the checks and manages keeping the catalog up to date with the servers as the health status changes using an internal version of the Catalog API.

If you called this Agent API on one of your Consul servers it's possible to have them run checks as well, but that's an unusual configuration to use if it's going to be checking the health of a service on another node. By running an agent on each node you get some basic "node is reachable" checking for free by Consul itself, and you keep the knowledge of the services and checks out at the edges where they are being run (the Catalog API lets the Consul servers answer questions across your whole fleet, but in Consul the agents are the source of truth and keep the catalog up to date to match what's going on).

Hope that helps!

-- James


--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/consul/issues
IRC: #consul on Freenode
---
You received this message because you are subscribed to the Google Groups "Consul" group.
To unsubscribe from this group and stop receiving emails from it, send an email to consul-tool...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/consul-tool/afc96470-5047-4063-9b2c-c602ae06f25e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Antoine Lang-Cavelier

unread,
Nov 26, 2015, 6:24:37 PM11/26/15
to Consul
Hi James!

Thank you for all those details, I have a better understanding of how I can use Consul now. I was expecting an agent-less configuration and was mislead by the possibility of doing a lot of things with the HTTP API and didn't get it is there in support of a very light agent.

Thank you again.

Antoine
Reply all
Reply to author
Forward
0 new messages