Feature - read metrics from a file

Hello Hector

I'm testing fail2ban-prometheus in a clustering env and it's hard to know which servers collects a ban

image

I have only the instance name

With node-exporter I'm using "collector.textfile.directory=/home/" and the file node-meta.prom contains the needed values

cat /home/node-meta.prom

node_meta{node_id="xw3ryqbbc5cgx8bpjjogfftnh",container_label_com_docker_swarm_node_id="xw3ryqbbc5cgx8bpjjogfftnh", node_name="nostromo"} 1

Generated with this kind of entry point (tested with fail2ban here)

#!/bin/sh -e
NODE_NAME=$(cat /etc/nodename)
echo "node_meta{node_id=\"$NODE_ID\", container_label_com_docker_swarm_node_id=\"$NODE_ID\", node_name=\"$NODE_NAME\"} 1" > /home/node-meta.prom
/app/fail2ban-prometheus-exporter -version

db_path=/app/fail2ban.sqlite3
socket_path=/var/run/fail2ban/fail2ban.sock

# Blank out the file paths if they do not exist - a hacky way to only use these files if they were mounted into the container.
if [ ! -f "$db_path" ]; then
    db_path=""
fi
if [ ! -S "$socket_path" ]; then
    socket_path=""
fi

# Start the exporter (use exec to support graceful shutdown)
# Inspired by: https://akomljen.com/stopping-docker-containers-gracefully/
exec /app/fail2ban-prometheus-exporter \
    -db "$db_path" \
    -socket "$socket_path"

/etc/nodemane = /etc/hostname (from host)

    volumes:
      - /etc/hostname:/etc/nodename:ro
      - /var/run/fail2ban:/var/run/fail2ban:ro

More explanations here: https://github.com/stefanprodan/swarmprom

Maybe something close is possible with fail2ban, add external metrics from file ? or at least just add the hostname ?

Thanks

Edited by Fred