Simple C# library to control HAProxy over TCP port.
https://www.nuget.org/packages/HAProxyApi.Client/
To enable HAproxy stats api you should turn it on in global section of haproxy.conf. Do not forget to limit access to that port from global network.
stats socket ipv4@YOUR_HAPROXY_SERVER_IP:PORT level admin
- ShowErrors (header only)
- ShowBackends
- ShowBackendServers
- SetWeight
- DisableServer
- EnableServer
- ShowInfo (selected fields only)
- ShowStat
- ClearCounters
- ClearAllCounters
var client = new HaProxyClient("SERVER.DOMAIN.TLD", port);
string lastError = client.ShowErrors();
string info = client.ShowInfo();
var servers = cli.ShowBackendServers();
foreach (var backendServer in servers)
{
Console.WriteLine($"{backendServer.BackendName}/{backendServer.Name} is {backendServer.OperationalState}");
}
sample result:
backend1/server1 is SRV_ST_RUNNING
backend1/server2 is SRV_ST_RUNNING
backend2/server1 is SRV_ST_RUNNING
backend2/server2 is SRV_ST_RUNNING