powerapi-ng / hwpc-sensor

Hardware Performance Counters monitoring agent for containers.
BSD 3-Clause "New" or "Revised" License
14 stars 16 forks source link

No name resolution for socket output #14

Closed PierreRustOrange closed 2 years ago

PierreRustOrange commented 2 years ago

When using the socket output, the cofiguration requires using an IP address, which is not convenient in container environments. For example, when running the sensor and a formula with docker compose, we don't know the address at which the formula (i.e. the socket server the sensor must connect to) runs but we can use the name of the service, which will be resolved by docker to the corresponding ip address. However, as the sensor does not resolve address names, this does not work.

This can easily be tested by running the sensor with a name for the -U parameter :

docker run --privileged --rm --name sensorhwpc --network="host" --pid host \
         -v /sys:/sys  \
         -v /var/lib/docker/containers:/var/lib/docker/containers:ro     \
         powerapi/hwpc-sensor \
           -n sensor \
           -f 2000 \
           -r socket -U localhost -P  12000 \
           -s "rapl" -o -e "RAPL_ENERGY_PKG" \
           -s "msr"     -e "TSC" -e "APERF" -e "MPERF" \
           -c "core"    -e "CPU_CLK_THREAD_UNHALTED:REF_P" \
                        -e "CPU_CLK_THREAD_UNHALTED:THREAD_P" \
                        -e "LLC_MISSES"\
                    -e "INSTRUCTIONS_RETIRED"

Due to another issue (see PR #13) This command currently simply blocks, once the error is fixed it fails even tough a socket server is running at localhost.

A solution would be to use getaddrinfo to resolve the address name when the supplied argument is not a valid IP address.

PierreRust commented 2 years ago

Actually, this issue does not only happen with docker compose but also prevent using the socket interface when using powerapi in k8s, if the sensor and the formula are not running in the same pod (as we were doing until now) : there is not way to get the actual formula ip adress and use it in the configuration, we can only use network names.