Error when conect snmp-exporter and prometheus

1.1k Views Asked by At

I'm new with Prometheus and snmp-exporter and I have been doing tests to monitor a UPS, is a docker-compose with prometheus+grafana+node-exporter+snmp-exporter. snmp-exporter works, shown the snmp mib scraper of the device, but in prometheus, in the status/tragets menu shows the following error message Get "http://localhost:9116/snmp?module=MODULE&target=ip": dial tcp [::1]:9116: connect: connection refused

In the error message we can see that the url is swapped

This is the url shown in connection refused error message in prometheus: -- http://localhost:9116/snmp?module=MODULE&target=IP And this is the acctual url from snmp-exporter: -- http://localhost:9116/snmp?target=IP&module=MODULE

I tried several relabeling settings in the prometheus.yml configuration file, but I couldn't solve this problem.

Any idea what the problem is?

Thanks in advance for your suggestions.

1

There are 1 best solutions below

0
kalidkto On

The problem was... that i didn't define correctly the job_name in prometheus.yml, as @DazWilkin mentioned

The error is that Prometheus is unable to connect to the SNMP exporter on (localhost) port 9116. This is likely because Docker Compose is assigning the SNMP exporter a host name (defined by the Docker Compose config services name). When you define the targets in prometheus.yml (or equivalent), you will need to use the services name (not localhost).

Before:

- job_name: snmp-exporter
  static_configs:
    - targets:
      - ip.ip.ip.ip  # SNMP device.
  metrics_path: /snmp
  params:
    module: [ups]    
  relabel_configs:
    - source_labels: [__address__]
      target_label: __param_target
    - source_labels: [__param_target]
      target_label: instance
    - target_label: __address__
      replacement: localhost:9116

Aftter:

- job_name: snmp-exporter
  static_configs:
    - targets:
      - ip.ip.ip.ip  # SNMP device.
  metrics_path: /snmp
  params:
    module: [ups]    
  relabel_configs:
    - source_labels: [__address__]
      target_label: __param_target
    - source_labels: [__param_target]
      target_label: instance
    - target_label: __address__
      replacement: snmp-exporter:9116 #Container_name defined in docker-compose.yml

And worked as i spected

Once again, Thanks for your suggestions.