0
votes

I'm trying to create rule logic for Prometheus to retrieve HAProxy metrics via Openstack Service Discovery. HAProxy has nbproc = 8, which means I need to fetch metrics from eight different ports. At the moment it looks like I need to make eight separate openstack_sd_configs (and job_names?) along with repeating all the label changes.
Is there a more clever way to do this?

haproxy:

listen 0_stats
    bind 0.0.0.0:1941 process 1
    bind 0.0.0.0:1942 process 2
    bind 0.0.0.0:1943 process 3
    bind 0.0.0.0:1944 process 4
    bind 0.0.0.0:1945 process 5
    bind 0.0.0.0:1946 process 6
    bind 0.0.0.0:1947 process 7
    bind 0.0.0.0:1948 process 8
    mode http
    option httpclose
    #option http-use-htx
    http-request use-service prometheus-exporter if { path /metrics }
    stats auth XXX:YYY
    stats enable
    stats uri /

prometheus (for only one port):

  - job_name: openstack_haproxy
    openstack_sd_configs:
      - role: 'instance'
        region: 'region1'
        identity_endpoint: 'https://some.domain:5000/v3/'
        domain_name: 'Default'
        application_credential_id: YYY
        application_credential_secret: XXX
        all_tenants: true
        port: 1941

    relabel_configs:
      # Keep only active instances
      - source_labels: [__meta_openstack_instance_status]
        action: keep
        regex: ACTIVE

        #Keep only instances which are flagged for haproxy scraping
      - source_labels: [__meta_openstack_tag_prometheus_scrape_haproxy]
        action: keep
        regex: 'true'

      # Replace the default instance by the OpenStack instance name
      - source_labels: [__meta_openstack_instance_name]
        target_label: instance

openstack metadata for each haproxy instance:

prometheus_scrape_haproxy = true
Maybe just use nbthread instead of nbproc and save yourself a LOT of trouble? nbthread is available since haproxy 1.8 and nbproc got removed in 2.5, so nbthread is your future anyway.tbielaszewski