Defined Type: prometheus::scrape_job

Defined in:
manifests/scrape_job.pp

Summary

This module manages prometheus scrape jobs.

Overview

Note:

This define is used to export prometheus scrape settings from nodes to be scraped to the node running prometheus itself. This can be used to make prometheus find instances of your running service or application.

Parameters:

  • job_name (String[1])

    The name of the scrape job. This will be used when collecting resources on the prometheus node. Corresponds to the prometheus::collect_scrape_jobs parameter.

  • targets (Array[String[1]])

    Array of hosts and ports in the form “host:port”

  • labels (Hash[String[1], String[1]]) (defaults to: {})

    Labels added to the scraped metrics on the prometheus side, as label:values pairs

  • collect_dir (Stdlib::Absolutepath) (defaults to: undef)

    Directory used for collecting scrape definitions. NOTE: this is a prometheus setting and will be overridden during collection.

  • ensure (Enum['present', 'absent']) (defaults to: 'present')

    Whether the scrape job should be present or absent.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'manifests/scrape_job.pp', line 18

define prometheus::scrape_job (
  String[1] $job_name,
  Array[String[1]] $targets,
  Hash[String[1], String[1]] $labels = {},
  Stdlib::Absolutepath $collect_dir  = undef,
  Enum['present', 'absent'] $ensure = 'present',
) {
  $config = stdlib::to_yaml([
      {
        targets => $targets,
        labels  => $labels,
      },
  ])
  file { "${collect_dir}/${job_name}_${name}.yaml":
    ensure  => stdlib::ensure($ensure, 'file'),
    owner   => 'root',
    group   => $prometheus::group,
    mode    => $prometheus::config_mode,
    content => "# this file is managed by puppet; changes will be overwritten\n${config}",
  }
}