modbus_exporter icon indicating copy to clipboard operation
modbus_exporter copied to clipboard

Using multiple devices

Open rfc1036 opened this issue 5 years ago • 7 comments

I do not understand how I can query multiple modbus devices in Prometheus in the best idiomatic way: it would be very helpful to distribute examples of more complex configurations.

I have defined multiple modules in the modbus_exporter configuration, each one detailing the registers of a specific meter that I want to query. In Prometheus now I need to configure multiple RTU gateways, each one containing multiple slave devices from different brands.

What is the correct mix of jobs, targets and sub_targets to do this?

rfc1036 avatar Jan 29 '20 15:01 rfc1036

While not a direct answer, this modbus_exporter is modeled after https://github.com/prometheus/blackbox_exporter and https://github.com/prometheus/snmp_exporter .

You would usually have one job with multiple targets and sub_targets which have the same configuration in modbus_exporter. A different config would mean a new job.

RichiH avatar Jan 29 '20 22:01 RichiH

I have not been able to configure a job with multiple sub_targets because then multiple sub_targets parameters are passed on the modbus_exporter URL and the last one overrides the others.

rfc1036 avatar Nov 08 '20 13:11 rfc1036

I don't have access to the ModBus environment any more. Maybe @bastischubert can share his config and we can build a reference from that?

Learning by stealing would work best, here.

RichiH avatar Nov 18 '20 10:11 RichiH

@rfc1036 currently we are generating a huge pile of yaml within prometheus and the modbus config file. I will share some config examples in the next days

bastischubert avatar Dec 07 '20 21:12 bastischubert

Any news on this issue? I have the same problem as @rfc1036. I have a Modbus TCP/RTU converter, and two sensors connected. They are both the same brand and model. How can I get those two into Prometheus as two targets? I tried with sub_targets. But when I list two ['xy', 'xz'], Prometheus just shows two sub_targets as one target. And then writes two sub_targets in one query string. Which, of course, wont work.

balzreber avatar Feb 15 '21 11:02 balzreber

How about using two prometheus jobs, one with xy and one with yz as sub_target? prometheus iterates over targets, but it can't iterate over other parameters AFAIK

fschlich avatar Oct 08 '22 14:10 fschlich

My boss came up with following workarround in prometheus.yml and it works well.

      - job_name: "inepro-pro1"
        metrics_path: /modbus
        static_configs:
        - targets: ["10.10.2.23:502"]
          labels:
            sub_target: 1
        - targets: ["10.10.2.23:502"]
          labels:
            sub_target: 2
        params:
          module: ["inepro-pro1"]
        relabel_configs:
          - source_labels: [__address__]
            target_label: __param_target
          - source_labels: [sub_target]
            target_label: __param_sub_target
          - target_label: __address__
            replacement: modbus-exporter:9602

dostalradim avatar Nov 23 '22 11:11 dostalradim