Need help specifying args in rc.conf for node_exporter

Hi all,

I've been struggling for an hour to pass additional arguments to the Prometheus node_exporter daemon in /etc/rc.conf.

The help for node_exporter provides an example argument (mount points to ignore) as:
Code:
--collector.filesystem.ignored-mount-points="^/(dev)($|/)"
                                Regexp of mount points to ignore for filesystem collector.
The rc script says to use the _args variable to specify arguments to node_exporter:
Code:
# node_exporter_args (string):          Set extra arguments to pass to node_exporter
#               Default is "".

Adding the line:
Code:
node_exporter_args="--collector.filesystem.ignored-mount-points=\"^/(dev)($|/)\""
to /etc/rc.conf and running sh -x /usr/local/etc/rc.d/node_exporter start results in:
Code:
+ limits -C daemon su -m nobody -c 'sh -c "/usr/sbin/daemon  -f -p /var/run/node_exporter.pid -T node_exporter     /usr/bin/env /usr/local/bin/node_exporter     --web.listen-address=:9100     --collector.textfile.directory=/var/tmp/node_exporter     --collector.filesystem.ignored-mount-points="^/(dev)($|/)""'
Illegal variable name.

Can someone please help me format the line in /etc/rc.conf so that I can start the daemon?

Thanks,
Scott
 
The node_exporter_args string is in double quotes, that gives special meaning to the $ character as the start of a variable to interpret. Escape it, you want a literal $, not as a variable. That's what the error is telling you, the $| is an illegal variable.

You can also use single quotes ' instead of double quotes ": Strong versus weak quoting, so you don't need to escape the double quotes.

Code:
node_exporter_args='--collector.filesystem.ignored-mount-points="^/(dev)(\$|/)"'
# OR
node_exporter_args="--collector.filesystem.ignored-mount-points='^/(dev)($|/)'"

NB. rc.conf is in essence a shell script that only contains variables. It gets sourced multiple times by the various rc(8) scripts.
 
The node_exporter_args string is in double quotes, that gives special meaning to the $ character as the start of a variable to interpret. Escape it, you want a literal $, not as a variable. That's what the error is telling you, the $| is an illegal variable.

You can also use single quotes ' instead of double quotes ": Strong versus weak quoting, so you don't need to escape the double quotes.

Code:
node_exporter_args='--collector.filesystem.ignored-mount-points="^/(dev)(\$|/)"'
# OR
node_exporter_args="--collector.filesystem.ignored-mount-points='^/(dev)($|/)'"

NB. rc.conf is in essence a shell script that only contains variables. It gets sourced multiple times by the various rc(8) scripts.

Thanks SirDice

With node_exporter_args='--collector.filesystem.ignored-mount-points="^/(dev)(\$|/)"' I get:
Code:
limits -C daemon su -m nobody -c 'sh -c "/usr/sbin/daemon  -f -p /var/run/node_exporter.pid -T node_exporter     /usr/bin/env /usr/local/bin/node_exporter     --web.listen-address=:9100     --collector.textfile.directory=/var/tmp/node_exporter     --collector.filesystem.ignored-mount-points="^/(dev)(\$|/)""'
Badly placed (.

And with node_exporter_args="--collector.filesystem.ignored-mount-points='^/(dev)($|/)'" I get:
Code:
eval $' limits -C daemon su -m nobody -c \'sh -c "/usr/sbin/daemon  -f -p /var/run/node_exporter.pid -T node_exporter     /usr/bin/env /usr/local/bin/node_exporter     --web.listen-address=:9100     --collector.textfile.directory=/var/tmp/node_exporter     --collector.filesystem.ignored-mount-points=\'^/(dev)($|/)\'"\''
eval: 1: Syntax error: "(" unexpected

Thanks
 
And with node_exporter_args="--collector.filesystem.ignored-mount-points='^/(dev)($|/)'" I get:
Code:
eval $' limits -C daemon su -m nobody -c \'sh -c "/usr/sbin/daemon  -f -p /var/run/node_exporter.pid -T node_exporter     /usr/bin/env /usr/local/bin/node_exporter     --web.listen-address=:9100     --collector.textfile.directory=/var/tmp/node_exporter     --collector.filesystem.ignored-mount-points=\'^/(dev)($|/)\'"\''
eval: 1: Syntax error: "(" unexpected
Unfortunately, the rc framework is running eval on the list of arguments which makes sh(1) explode. You'll need to escape those special characters like ( or $.
 
Back
Top