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):

bash
echo "experimental-mode on; set var proc.arch expr str(arch1)" | \
sudo socat stdio tcp4-connect:127.0.0.1:9999
bash
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:

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

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

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

Confirm the operation:

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

See also Jump to heading

If this page was useful, please, Leave the feedback.