influxdata / telegraf

Agent for collecting, processing, aggregating, and writing metrics, logs, and other arbitrary data.
https://influxdata.com/telegraf
MIT License
14.63k stars 5.58k forks source link

input.http allow dialing a unix socket #11038

Closed sarim closed 1 year ago

sarim commented 2 years ago

Feature Request

Basically curl --unix-socket /run/something.sock http://magic/url/something

Proposal:

add unix-socket option to http input plugin.

Current behavior:

No option to specify unix-socket option.

Desired behavior:

Ability to use unix-socket to make the http request.

Use case:

As the goal of telegraf is collecting data, and many services listen to sockets. For example podman.

curl --unix-socket /run/user/1000/podman/podman.sock http://d/v1/libpod/containers/stats

There are many endpoints in libpod api returning various data, easily parseable with json in telegraf. But it needs to dial the unix socket.

powersj commented 2 years ago

Hi,

Interesting request. My initial thought is to write a script and use an exec input plugin to do this. Although I can see adding these to HTTP might be helpful as well.

Next steps: look into what would be required to add this to the existing HTTP input plugin and if it s feasible versus using the exec plugin.

Thanks

sarim commented 2 years ago

Interesting request. My initial thought is to write a script and use an exec input plugin to do this.

That's an interesting idea, This should work for now. Thanks a lot.

Next steps: look into what would be required to add this to the existing HTTP input plugin and if it s feasible versus using the exec plugin.

This should be relatively easy. Need to set DialContext here. If unix socket is set, dial to socket path, if not dial using net. Maybe I can work on this, should I start a PR?

https://github.com/influxdata/telegraf/blob/f97e50a73db8e54c88e09869da11741238088f2c/plugins/common/http/config.go#L39-L43

powersj commented 2 years ago

Maybe I can work on this, should I start a PR?

Always happy to see a PR