When you monitor multiple hosts by directly pulling data from them, typical scrapper config looks like bellow

- job_name: 'my_job'
  static_configs:
    - targets:
        - node1.example.com:1234
        - node2.example.com:1234
        - node3.example.com:1234

  relabel_configs:
    - source_labels: [__address__]
      target_label: __param_target
    - source_labels: [__param_target]
      target_label: instance

Main problem with it that “instance” dimension of collected metrics will looks like node1.example.com:1234. As example: example_series_total{instance="node1.example.com:1234", job="my_job"}

And port number is not something you need when you are trying to create nice Grafana dashboard.

If all targets are using same port there is a better way to do it.

- job_name: 'my_job'
  static_configs:
    - targets:
        - node1.example.com
        - node2.example.com
        - node3.example.com

  relabel_configs:
    - source_labels: [__address__]
      target_label: __param_target
    - source_labels: [__param_target]
      target_label: instance
    - target_label: __address__
      source_labels: [__param_target]
      replacement: $1:1234

In this case series will look like bellow. No more pesky port number

example_series_total{instance="node1.example.com", job="my_job"}

If you need to use different ports on different hosts, than you can just use “regex:” to extract hostname from target and assign it to instance label

- job_name: 'my_job'
  static_configs:
    - targets:
        - node1.example.com:12
        - node2.example.com:123
        - node3.example.com:1234

  relabel_configs:
    - source_labels: [__address__]
      target_label: __param_target
    - source_labels: [__param_target]
      regex: (.*)\:.+
      replacement: $1
      target_label: instance

I did not test last config myself, but I hope it should work.

Two first configs was tested on prometheus 2.26

Updated: