2017 © Pedro Peláez
 

library haproxy-api

API for HAProxy

image

bigwhoop/haproxy-api

API for HAProxy

  • Wednesday, November 28, 2012
  • by bigwhoop
  • Repository
  • 2 Watchers
  • 6 Stars
  • 24 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Installation

Use composer., (*1)

{
    ...
    "require": {
        ...
        "bigwhoop/haproxy-api" : "dev-master",
        ...
    }
    ...
}

Configuration

<?php
use \BigWhoop\HAProxyAPI;

$api = new HAProxyAPI\API('http://example.com');
$api = new HAProxyAPI\API('http://example.com:22002');
$api = new HAProxyAPI\API('http://example.com:22002/status');
$api = new HAProxyAPI\API('http://10.0.0.1/monitor');
$api = new HAProxyAPI\API('http://example.com', 'username');
$api = new HAProxyAPI\API('http://example.com', 'username', 'password');
...

Commands

Enable server

try {
    $status = $api->execute('enableServer', array('backend' => 'webapp', 'server' => 'web-01'));
    if ($status) {
        // Action had an effect
    } else {
        // Action had no effect
    }
}  catch (HAProxyAPI\Client\Exception $e) {
   // Server error
} catch (HAProxyAPI\Command\Exception $e) {
   // Data error
}

Disable server

Same as above, just use disableServer as the first argument to $api->execute()., (*2)

Stats

try {
    $stats = $api->execute('stats');
} catch (HAProxyAPI\Client\Exception $e) {
    // Server error
} catch (HAProxyAPI\Command\Exception $e) {
    // Data error
}

An array with plain objects with the following properties is returned:, (*3)

 pxname, svname, qcur, qmax, scur, smax, slim, stot, bin, bout, dreq, dresp, ereq, econ, eresp,
 wretr, wredis, status, weight, act, bck, chkfail, chkdown, lastchg, downtime, qlimit, pid, iid,
 sid, throttle, lbtot, tracked, type, rate, ratelim, ratemax, checkstatus, checkcode, checkduration,
 hrspxx, hrspother, hanafail, reqrate, reqratemax, reqtot, cliabrt, srvabrt

I'm pretty sure you'll find out what the mean. They're coming from HAProxy in this format., (*4)

Grouping

You can also get a stats array grouped by the backend., (*5)

try {
    $stats = $api->execute('stats', array('grouping' => HAProxyAPI\Command\StatsCommand::GROUPING_BACKEND));
} catch (HAProxyAPI\Client\Exception $e) {
    // Server error
} catch (HAProxyAPI\Command\Exception $e) {
    // Data error
}

The array is now in the following format:, (*6)

[
    'backend1' => [{ ... }, { ... }],
    'backend2' => [{ ... }, ...],
    ...
]

License

See LICENSE file., (*7)

The Versions

28/11 2012

dev-master

9999999-dev http://github.com/bigwhoop/haproxy-api

API for HAProxy

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

api haproxy