Search code examples
yamlprometheus

Prometheus configuration some hosts with proxy, some without


I have a prometheus.yml and I don't want that my homeserver goes thru proxy. I tried to use proxy_url with the targets but that doesn't work.

Here is my working (except homeserver) prometheus.yml. Is there any way to exclude the proxy on this host?

global:
  scrape_interval: 15s

scrape_configs:

  - job_name: 'node'

    proxy_url: 'http://127.0.0.1:8888' 

    static_configs:
      - targets: ['192.168.178.3:9100']
        labels:
          instance: homeserver
      - targets: ['www.fddfg.de:9100']
        labels:
          instance: 1ahf
      - targets: ['435435346774:9100']
        labels:
          instance: dfgsd
      - targets: ['207.148.107.219:9100']
        labels:
          instance: vultr-1
      - targets: ['198.55.47.29:9100']
        labels:
          instance: vultr-2

    basic_auth:
        username: 'prometheus'

Solution

  • You can define proxies per jobs. This means you can split your targets in jobs and assign proxy per job:

    global:   
      scrape_interval: 15s
    
    scrape_configs:
      - job_name: 'node'
        proxy_url: 'http://127.0.0.1:8888' 
        static_configs:
          - targets: ['www.fddfg.de:9100']
            labels:
              instance: 1ahf
          - targets: ['435435346774:9100']
            labels:
              instance: dfgsd
          - targets: ['207.148.107.219:9100']
            labels:
              instance: vultr-1
          - targets: ['198.55.47.29:9100']
            labels:
              instance: vultr-2
        basic_auth:
            username: 'prometheus'
    
      - job_name: 'node-homeserver'
        static_configs:
          - targets: ['192.168.178.3:9100']
            labels:
              instance: homeserver
        basic_auth:
            username: 'prometheus'
    

    I think the yaml above could be the solution to your issue.