QubitProducts / exporter_exporter

A reverse proxy designed for Prometheus exporters
Apache License 2.0
336 stars 55 forks source link

Support running as a sokcs5 proxy #9

Closed thomasf closed 5 years ago

thomasf commented 6 years ago

I think this is doable when prometheus is compiled with go 1.9 and gets socks5 proxy support for it's proxy_url argument.

something like this could work where node:1 is resolved by the socks proxy to match a module named node in exporter_exporter as the first entry in the node exporter section.

  - job_name: 'node'
    scrape_interval: 1s
    static_configs:
      - targets: ['node:1']
    scheme: https
    proxy_url: "socks5://localhost:3000"
    tls_config:
      ca_file: ca.crt
      key_file: client.key
      cert_file: client.crt
      server_name: localhost

It get's interesting when we suddenly have a process cluster running on a node which exporterexporter needs to pick up.

One could imagine something like this:

modules:
  myapp:
    method: http
    http:
      ports: 7000-7032

which would map to scrapable myqpp-targets 1-16

  - job_name: 'myapp'
    scrape_interval: 1s
    static_configs:
      - targets: ['myapp:1', 'myapp:2', 'myapp:3', 'myapp:4', 'myapp:5', 'myapp:6', ....
    scheme: https
    proxy_url: "socks5://localhost:3000"
    tls_config:
      ca_file: ca.crt
      key_file: client.key
      cert_file: client.crt
      server_name: localhost

As exporterexporter works right now I need one job for each myapp process in that host local application cluster which is the main problem I want to solve.

thomasf commented 6 years ago

I made a very small POC from this using https://github.com/armon/go-socks5 with a minor modification + https://github.com/valyala/fasthttp/blob/master/fasthttputil/inmemory_listener.go to bind the socks Dial to the http servers ServeTLS function. I did not add support for port ranges but other than that the config I used above works exactly like that.

thomasf commented 6 years ago

I pushed my test code here: https://github.com/thomasf/exporter_exporter/commit/fcc25b9de59b5a5b143fc22395238f6dbeaf4505

It's not like it's close to anything resembling a proper solution but it is working.

And you have to compile prometheus with go 1.9 to be able to use a socks5 proxy for http.

tcolgate commented 6 years ago

Sorry for the silence, this will take a bit of reviewing, but sounds like a good move.

thomasf commented 6 years ago

the prometheus 1.8.0 binary release is compiled w. go 1.9.1 thus supporting socks5 proxy..

I will revisit this soon, I might copy the relevant parts from the go-socks5 lib into this project instead of using it as a library, not sure yet but it looks like that might be for the best..

It could maybe be a good idea to split exporter_exporter into a few packages instead of only having one main.. idk.