Defined Type: profile::prometheus::jmx_exporter

Defined in:
modules/profile/manifests/prometheus/jmx_exporter.pp

Overview

Define profile::prometheus::jmx_exporter

Renders a Prometheus JMX Exporter config file, declares a prometheus::jmx_exporter_instance so that the prometheus server will be configured to pull from this exporter instance, and installs ferm rules to allow it to do so. The hostname:port combination, derived from the define's parameters, will be used as Prometheus target (so metrics will be associated to it). This trick should allow the configuration of multiple Prometheus targets on the same machine, for use cases like Cassandra (multiple JVM instances with different domains on the same host) or Kafka (Kafka/MirrorMaker JVMs on the same host).

Parameters:

[*hostname*]
  Hostname used by the exporter for the listen socket.

[*port*]
  Port used by the exporter for the listen socket.

[*prometheus_nodes*]
  List of Prometheus master nodes.

[*config_file*]
  The full path of the configuration file to create. Check 'config_dir' for
  more info about how its parent directory is handled.
config_dir

The parent directory of the jmx exporter (usually /etc/prometheus). If not undef or already defined, it will be created by this profile. This is only a handy way to avoid code repetition while using this profile, but special care must be taken since: 1) this parameter assumes a string like '/etc/$name', arbitrary nesting is not currently supported 2) the $config_file value needs to be set accordingly. Default: undef

content

Content of the exporter's configuration file. One between content or source must be specified.

source

Source content of the exporter's configuration file. One between content or source must be specified.

labels

Hash of any common labels to be added to all metrics exported from this jmx exporter instance. NOTE: These will take precedence over labels declared in prometheus::jmx_exporter_config on the prometheus server. All jobs there automatically get a 'cluster' label applied, so be careful not to override that one (unless you really mean to!) Default: {}

extra_ferm_allowed_nodes

In addition to $prometheus_nodes, nodes in this list will also be allowed to talk to the prometheus jmx exporter in ferm rules.

Parameters:

  • hostname (Any)
  • port (Any)
  • prometheus_nodes (Any)
  • config_file (Any)
  • config_dir (Any) (defaults to: undef)
  • content (Any) (defaults to: undef)
  • source (Any) (defaults to: undef)
  • labels (Any) (defaults to: {})
  • extra_ferm_allowed_nodes (Array[String]) (defaults to: [])


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'modules/profile/manifests/prometheus/jmx_exporter.pp', line 57

define profile::prometheus::jmx_exporter (
    $hostname,
    $port,
    $prometheus_nodes,
    $config_file,
    $config_dir = undef,
    $content = undef,
    $source  = undef,
    $labels = {},
    Array[String] $extra_ferm_allowed_nodes = [],
) {
    if $source == undef and $content == undef {
        fail('you must provide either "source" or "content"')
    }

    if $source != undef and $content != undef  {
        fail('"source" and "content" are mutually exclusive')
    }

    require_package('prometheus-jmx-exporter')

    if $config_dir and ! defined(File[$config_dir]) {
        # Create the Prometheus JMX Exporter configuration's parent dir
        file { $config_dir:
            ensure => 'directory',
            mode   => '0444',
            owner  => 'root',
            group  => 'root',
        }
    }

    # Create the Prometheus JMX Exporter configuration
    file { $config_file:
        ensure  => 'present',
        mode    => '0444',
        owner   => 'root',
        group   => 'root',
        content => $content,
        source  => $source,
        # If the source is using a symlink, copy the link target, not the symlink.
        links   => 'follow',
    }

    # Allow automatic generation of config on the Prometheus master.
    prometheus::jmx_exporter_instance { $title:
        hostname => $hostname,
        port     => $port,
        labels   => $labels,
    }

    $allowed_nodes_to_prometheus_exporter_ferm = join($prometheus_nodes + $extra_ferm_allowed_nodes, ' ')
    ferm::service { "${title}_jmx_exporter":
        proto  => 'tcp',
        port   => $port,
        srange => "(@resolve((${allowed_nodes_to_prometheus_exporter_ferm})) @resolve((${allowed_nodes_to_prometheus_exporter_ferm}), AAAA))",
    }
}