Browse Source

prometheus-statsd-exporter: switch config to openwrt interface names

Drop the config knobs '*_address' and introduce '*_interface'
and '*_ipv6' instead.

'*_interface' takes an openwrt interface name ('loopback', 'lan',
'wan' etc), from which the primary IP is used to listen on. If
the matching '*_ipv6' is set to '1', the IPv6 adress will be used,
IPv4 elsewise.

procd interface triggers are now combined with this, so if a listen
interface is not yet configured when the init script is executed, the
process start is defered, and the trigger takes care of that once
the interfaces are ready.

Signed-off-by: Andre Heider <a.heider@gmail.com>
lilik-openwrt-22.03
Andre Heider 6 years ago
parent
commit
b53fcc98b9
2 changed files with 80 additions and 12 deletions
  1. +9
    -3
      utils/prometheus-statsd-exporter/files/etc/config/prometheus-statsd-exporter
  2. +71
    -9
      utils/prometheus-statsd-exporter/files/etc/init.d/prometheus-statsd-exporter

+ 9
- 3
utils/prometheus-statsd-exporter/files/etc/config/prometheus-statsd-exporter View File

@ -1,6 +1,12 @@
config prometheus-statsd-exporter 'main'
option web_listen_address '127.0.0.1:9102'
option web_interface 'loopback'
option web_port '9102'
option web_ipv6 '0'
option web_telemetry_path '/metrics'
option statsd_listen_udp '127.0.0.1:9125'
option statsd_listen_tcp '127.0.0.1:9125'
option statsd_udp_interface 'loopback'
option statsd_udp_port '9125'
option statsd_udp_ipv6 '0'
option statsd_tcp_interface 'loopback'
option statsd_tcp_port '9125'
option statsd_tcp_ipv6 '0'
option statsd_mapping_config '/etc/prometheus-statsd-exporter.yml'

+ 71
- 9
utils/prometheus-statsd-exporter/files/etc/init.d/prometheus-statsd-exporter View File

@ -6,30 +6,92 @@ USE_PROCD=1
PROG=/usr/bin/statsd_exporter
CONFFILE=/etc/prometheus-statsd-exporter.yml
. /lib/functions/network.sh
_log() {
logger -p daemon.info -t prometheus-statsd-exporter "$@"
}
start_service() {
local web_listen_address
local web_interface web_port web_ipv6
local web_telemetry_path
local statsd_listen_udp
local statsd_listen_tcp
local statsd_udp_interface statsd_udp_port statsd_udp_ipv6
local statsd_tcp_interface statsd_tcp_port statsd_tcp_ipv6
local statsd_mapping_config
local web_ip statsd_udp_ip statsd_tcp_ip
config_load "prometheus-statsd-exporter"
config_get web_listen_address main web_listen_address "127.0.0.1:9102"
config_get web_interface main web_interface "loopback"
config_get web_port main web_port "9102"
config_get web_ipv6 main web_ipv6 "0"
config_get web_telemetry_path main web_telemetry_path "/metrics"
config_get statsd_listen_udp main statsd_listen_udp "127.0.0.1:9125"
config_get statsd_listen_tcp main statsd_listen_tcp "127.0.0.1:9125"
config_get statsd_udp_interface main statsd_udp_interface "loopback"
config_get statsd_udp_port main statsd_udp_port "9125"
config_get statsd_udp_ipv6 main statsd_udp_ipv6 "0"
config_get statsd_tcp_interface main statsd_tcp_interface "loopback"
config_get statsd_tcp_port main statsd_tcp_port "9125"
config_get statsd_tcp_ipv6 main statsd_tcp_ipv6 "0"
config_get statsd_mapping_config main statsd_mapping_config "$CONFFILE"
if [ "$web_ipv6" = 1 ]; then
network_get_ipaddr6 web_ip "$web_interface"
else
network_get_ipaddr web_ip "$web_interface"
fi
network_is_up "$web_interface" && [ -n "$web_ip" ] || {
_log "defering start until web interface $web_interface becomes ready"
return 0
}
if [ "$statsd_udp_ipv6" = 1 ]; then
network_get_ipaddr6 statsd_udp_ip "$statsd_udp_interface"
else
network_get_ipaddr statsd_udp_ip "$statsd_udp_interface"
fi
network_is_up "$statsd_udp_interface" && [ -n "$statsd_udp_ip" ] || {
_log "defering start until statsd udp interface $statsd_udp_interface becomes ready"
return 0
}
if [ "$statsd_tcp_ipv6" = 1 ]; then
network_get_ipaddr6 statsd_tcp_ip "$statsd_tcp_interface"
else
network_get_ipaddr statsd_tcp_ip "$statsd_tcp_interface"
fi
network_is_up "$statsd_tcp_interface" && [ -n "$statsd_tcp_ip" ] || {
_log "defering start until statsd tcp interface $statsd_tcp_interface becomes ready"
return 0
}
procd_open_instance
procd_set_param command "$PROG"
procd_append_param command --web.listen-address="$web_listen_address"
procd_append_param command --web.listen-address="${web_ip}:${web_port}"
procd_append_param command --web.telemetry-path="$web_telemetry_path"
procd_append_param command --statsd.listen-udp="$statsd_listen_udp"
procd_append_param command --statsd.listen-tcp="$statsd_listen_tcp"
procd_append_param command --statsd.listen-udp="${statsd_udp_ip}:${statsd_udp_port}"
procd_append_param command --statsd.listen-tcp="${statsd_tcp_ip}:${statsd_tcp_port}"
procd_append_param command --statsd.mapping-config="$statsd_mapping_config"
procd_append_param command --log.level="warn"
procd_set_param file "$config_file"
procd_set_param stdout 1
procd_set_param stderr 1
procd_set_param respawn
procd_close_instance
}
service_triggers()
{
local web_interface statsd_udp_interface statsd_tcp_interface
config_load "prometheus-statsd-exporter"
config_get web_interface main web_interface "loopback"
config_get statsd_udp_interface main statsd_udp_interface "loopback"
config_get statsd_tcp_interface main statsd_tcp_interface "loopback"
procd_add_reload_interface_trigger "$web_interface"
procd_add_reload_interface_trigger "$statsd_udp_interface"
procd_add_reload_interface_trigger "$statsd_tcp_interface"
}

Loading…
Cancel
Save