Santosh M.
Santosh M.

Reputation: 2454

Prometheus: not a valid hostname

My SNMP exporter is hosted somewhere using kubernetes. I can access, and run it through URL like this and get metrics for a specified target: https://some.kube.server.name/api/snmp-exporter/snmp?target=AFACG1

My list of targets is in targets.json file using file_sd_configs in prometheus.yml file to dynamically load targets for prometheus.

My prometheus.yml file looks like, as below:

scrape_configs:
  - job_name: 'snmp'
    scrape_interval: 120s
    file_sd_configs:
        - files :
          - /etc/prometheus/targets.json

    metrics_path: /snmp

    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: https://some.kube.server.name/api/snmp-exporter/  # The SNMP exporter's real hostname:port.

And my targets.json file look like, as below:

[
   {
        "labels": {
            "job": "snmp"
        },
        "targets": [
            "AFACG1",
            "AFACG3",
            "AFACG5",
            "AFACG7",
            "AFACG8",
            "AFACG9"
        ]
    }
]

However, when I run prometheus, I get error \"https://some.kube.server.name/api/snmp-exporter\" is not a valid hostname"

What are the modifications that I need to implement in prometheus.yml in order to get metric for targets in targets.json?

Upvotes: 1

Views: 2534

Answers (1)

Santosh M.
Santosh M.

Reputation: 2454

After reading, I figured out an answer to my question which is working out well. Here, what I came up with my modified scrape_configs:

scrape_configs:
  - job_name: 'snmp'
    scheme: https
    scrape_interval: 120s
    tls_config:
      insecure_skip_verify: true
    file_sd_configs:
        - files :
          - /etc/prometheus/targets.json

    metrics_path: /api/snmp-exporter/snmp

    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: some.kube.server.name

I hope this helps other people who would face similar problem.

Upvotes: 4

Related Questions