Reference

dump stats-file

Available since

  • HAProxy 3.0
  • HAProxy Enterprise 3.0r1

Save the current state of the load balancer’s statistics counters to a file that you can use on the next service reload to populate the statistics counters with the existing values.

Description Jump to heading

You can persist your load balancer statistics counters after a reload by dumping the current values to a file. The HAProxy Stats page uses these counters. Once you have saved the state of the counters to a file, the load balancer will initialize its counters to those values so long as you have added the stats-file configuration directive to the global section of your configuration. Only proxy counters are included, that is, counters for frontends, backends, servers, and listeners.

Examples Jump to heading

To save and then to restore the statistics for your load balancer:

  1. Assign GUIDs to each frontend, backend, listen, and server object in your configuration. For example, here is a simple configuration with one frontend that routes to one backend with one server. The frontend, backend, and server each have a globally unique identifier assigned:

    haproxy
    frontend main
    guid 64aeebba-0911-483c-aa39-8f689cf3f657
    bind *:80
    default_backend app
    backend app
    guid 9de9a5de-c3c2-47c4-b945-c4f61b7ece6a
    balance roundrobin
    server app1 127.0.0.1:8080 check guid ae9194cc-f473-43de-ac21-43142340cf9c
    haproxy
    frontend main
    guid 64aeebba-0911-483c-aa39-8f689cf3f657
    bind *:80
    default_backend app
    backend app
    guid 9de9a5de-c3c2-47c4-b945-c4f61b7ece6a
    balance roundrobin
    server app1 127.0.0.1:8080 check guid ae9194cc-f473-43de-ac21-43142340cf9c
  2. Reload the load balancer to apply the configuration changes.

  3. Call dump stats-file to create the stats file, redirecting the output to your desired location:

    nix
    echo "dump stats-file" | \
    sudo socat stdio tcp4-connect:127.0.0.1:9999 > <path/to/stats/file>
    nix
    echo "dump stats-file" | \
    sudo socat stdio tcp4-connect:127.0.0.1:9999 > <path/to/stats/file>

    The data in the file will capture the current state of the objects.

  4. Add the stats-file configuration directive to your global section, specifying the path to your stats file location that the load balancer will reload:

    haproxy
    global
    stats-file <path/to/stats/file>
    haproxy
    global
    stats-file <path/to/stats/file>
  5. Reload the load balancer. It will initialize its statistics counters with the values from the file.

See also Jump to heading

Do you have any suggestions on how we can improve the content of this page?