Formatting of a DS file to include params and labels

22 views
Skip to first unread message

Kevin Cameron

unread,
Sep 23, 2020, 4:56:54 PM9/23/20
to Prometheus Users
I have a job formatted like this:
- job_name: 'test_job' 
  metrics_path: /export
  scrape_interval: 5m
  scrape_timeout: 15s
  params:
    command: [script_X]
    argument: ['ip address']
  static_configs:
  - targets: ['127.0.0.1:5666']
    labels:
      field1: 'text'
      field2: 'text'
      field3: 'text'
  relabel_configs:
  - source_labels: [__address__]
    target_label: __param_target
  - source_labels: [__param_target]
    target_label: instance
  - target_label: __address__
    replacement: ip:port

The parms and labels are what vary by instance so I want to have an external sd file with these fields in it for better management but I am having a hard time reworking the job and formatting the content of the SD file:

- job_name: 'test_job' 
  metrics_path: /export
  scrape_interval: 5m
  scrape_timeout: 15s
  file_sd_configs:
  - files:
    - my_file.yml
    relabel_configs:
  - source_labels: [__address__]
    target_label: __param_target
  - source_labels: [__param_target]
    target_label: instance
  - target_label: __address__
    replacement: ip:port

But how would the my_file.yml look to keep the parms and the labels related?

Thanks,
Kevin
Message has been deleted

Brian Candler

unread,
Sep 26, 2020, 9:42:37 AM9/26/20
to Kevin Cameron, Prometheus Users
On 26/09/2020 14:01, Kevin Cameron wrote:
Thanks Brian,
  when I sanitized my example I should have put in a fake value rather than ip:port, so 1.1.1.1:1234 just to clarify that part.

The Target and label part we have in place now and is working well, I have been reading over some of the relabeling and that is the part I am struggling with.  I found some documentation on __param_  but most do not go into full examples and the original job definition I am not the original creator.

The end product I want to generate should look like:


original:
- job_name: 'test_job' 
  metrics_path: /export
  scrape_interval: 5m
  scrape_timeout: 15s
  params:
    command: [script_X]
    argument: ['10.20.30.40']
  static_configs:
  - targets: ['127.0.0.1:5666']
    labels:
      field1: 'text'
      field2: 'text'
      field3: 'text'

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

So would the job with the relabel just look like this?
New:
- job_name: 'test_job' 
  metrics_path: /export
  scrape_interval: 5m
  scrape_timeout: 15s
  params:
  static_configs:
  - targets: ['127.0.0.1:5666']
    labels:
      field1: 'text'
      field2: 'text'
      field3: 'text'
      command: 'script_X'
      argument: '10.20.30.40'

  relabel_configs:
  - source_labels: [command]
     target_label: __param_command
   - source_labels: [ipaddress]
     target_label: __param_argument
  - source_labels: [__address__]
    target_label: __param_target
  - source_labels: [__param_target]
    target_label: instance
  - target_label: __address__
    replacement: 1.1.1.1:1234


That looks fine to me, except it should be "source_labels: [argument]" rather than "source_labels: [ipaddress]".

Kevin Cameron

unread,
Sep 29, 2020, 6:44:15 PM9/29/20
to Brian Candler, Prometheus Users
Thanks Brian,
  when I sanitized my example I should have put in a fake value rather than ip:port, so 1.1.1.1:1234 just to clarify that part.

The Target and label part we have in place now and is working well, I have been reading over some of the relabeling and that is the part I am struggling with.  I found some documentation on __param_  but most do not go into full examples and the original job definition I am not the original creator.

The end product I want to generate should look like:


original:
- job_name: 'test_job' 
  metrics_path: /export
  scrape_interval: 5m
  scrape_timeout: 15s
  params:
    command: [script_X]
    argument: ['10.20.30.40']
  static_configs:
  - targets: ['127.0.0.1:5666']
    labels:
      field1: 'text'
      field2: 'text'
      field3: 'text'

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

So would the job with the relabel just look like this?
New:
- job_name: 'test_job' 
  metrics_path: /export
  scrape_interval: 5m
  scrape_timeout: 15s
  params:
  static_configs:
  - targets: ['127.0.0.1:5666']
    labels:
      field1: 'text'
      field2: 'text'
      field3: 'text'
      command: 'script_X'
      argument: '10.20.30.40'

  relabel_configs:
  - source_labels: [command]
     target_label: __param_command
   - source_labels: [ipaddress]
     target_label: __param_argument
  - source_labels: [__address__]
    target_label: __param_target
  - source_labels: [__param_target]
    target_label: instance
  - target_label: __address__
    replacement: 1.1.1.1:1234

Thanks in advance,
Kevin

On Fri, Sep 25, 2020 at 7:00 PM Brian Candler <b.ca...@pobox.com> wrote:
That example can't be right.  What you have shown:

  - target_label: __address__
    replacement: ip:port

would put the literal text "ip:port" in the __address__ label, so it can't possibly work.

However, switching from static_configs to file_sd_configs isn't really related to this. The capabilities of file_sd_configs and static_configs are the same.  If you want different labels per host, you can do this with static_configs:

  static_configs:
  - targets: ['127.0.0.1:5666']
    labels:
      field1: 'text'
      field2: 'text'
      field3: 'text'
  - targets: ['1.2.3.4:5678']
    labels:
      field1: 'text2'
      field2: 'text2'
      field3: 'text2'

Or you can move this into file_sd_configs.  The format of my_file.yml is identical except indented to the left:

- targets: ['127.0.0.1:5666']
  labels:
    field1: 'text'
    field2: 'text'
    field3: 'text'
- targets: ['1.2.3.4:5678']
  labels:
    field1: 'text2'
    field2: 'text2'
    field3: 'text2'


There are more complex options such as making a structured value for the __address__, matching it with a regexp, and pulling out the values you require into specific labels.  Examples of these sorts of relabelling configs have been posted to the list before.

--
You received this message because you are subscribed to a topic in the Google Groups "Prometheus Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/prometheus-users/sGppTk4JSZU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to prometheus-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/60293c82-63f1-49d4-bb7e-012740d52f28o%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages