0

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.

kalidkto
  • 1
  • 1
  • Please include the Docker Compose config. 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). – DazWilkin May 27 '23 at 00:05
  • The string (`module=MODULE&target=IP`) after the query (`?`) after the path (`snmp`) is called the query string. Values in the query string are `key=value` and separated by `&`. This query string has 2 key-value pairs `module=MODULE` and `target=IP`. The ordering of these key-value pairs should be (!) inconsequential. Thus that Prometheus and the SNMP exporter order them differently is interesting but likely not significant. – DazWilkin May 27 '23 at 00:08
  • 1
    @DazWilkin Yes, you're right. Thay was the problem... i didn't define correctly the job_name in prometheus.yml – kalidkto May 29 '23 at 15:26
  • @DazWilkin I had defined as localhost, instead of putting the name of the service. Thanks for your advaise – kalidkto May 29 '23 at 15:38

1 Answers1

0

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.

kalidkto
  • 1
  • 1