Reference

set var

Available since

  • HAProxy 2.4
  • HAProxy Enterprise 2.4r1

Set or overwrite a process-wide variable with the result of an expression or format string.

Description Jump to heading

Set or overwrite a process-wide variable with the result of an expression or format string. Only process-wide variables may be used, so the name must begin with proc.. Other names fail. This command requires a CLI level of operator or admin. This operation is supported only on a CLI connection running in experimental mode (experimental-mode on). This operation is still in development and may change in the future.

An expression may consist only of internal sample fetch keywords and converters. The command line parser does not recognize quotes, so any space in the expression must be preceded by a backslash. For versions 2.5r1 and greater, you must precede an expression with the expr argument.

See set-var-fmt. Precede a string format with the fmt argument.

Examples Jump to heading

Below, we create a process-wide variable called proc.arch and set it to the expression str(arch1):

nix
echo "experimental-mode on; set var proc.arch expr str(arch1)" | \
sudo socat stdio tcp4-connect:127.0.0.1:9999
nix
echo "experimental-mode on; set var proc.arch expr str(arch1)" | \
sudo socat stdio tcp4-connect:127.0.0.1:9999

For version 2.4r1, remove the expr argument.

Confirm the operation:

nix
echo "experimental-mode on; get var proc.arch" | \
sudo socat stdio tcp4-connect:127.0.0.1:9999
nix
echo "experimental-mode on; get var proc.arch" | \
sudo socat stdio tcp4-connect:127.0.0.1:9999
output
text
proc.arch: type=str value=<arch1>
output
text
proc.arch: type=str value=<arch1>

Create a process-wide variable called proc.bootid and set it to the string format %pid|%t:

nix
echo "experimental-mode on; set var proc.bootid fmt '%pid|%t'" | \
sudo socat stdio tcp4-connect:127.0.0.1:9999
nix
echo "experimental-mode on; set var proc.bootid fmt '%pid|%t'" | \
sudo socat stdio tcp4-connect:127.0.0.1:9999

Confirm the operation:

nix
echo "experimental-mode on; get var proc.bootid" | \
sudo socat stdio tcp4-connect:127.0.0.1:9999
nix
echo "experimental-mode on; get var proc.bootid" | \
sudo socat stdio tcp4-connect:127.0.0.1:9999
output
text
proc.bootid: type=str value=<'403|05/Apr/2023:08:15:28.629'>
output
text
proc.bootid: type=str value=<'403|05/Apr/2023:08:15:28.629'>

See also Jump to heading

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