Defined Type: prometheus::mysqld_exporter::instance

Defined in:
modules/prometheus/manifests/mysqld_exporter/instance.pp

Overview

Parameters:

  • client_socket (Any) (defaults to: '/run/mysqld/mysqld.sock')
  • client_user (Any) (defaults to: 'prometheus')
  • client_password (Any) (defaults to: 'This is a fake passsword, but cannot be empty due to Debian #953040')
  • listen_address (Any) (defaults to: ':9104')
  • arguments (Any) (defaults to: '')


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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
# File 'modules/prometheus/manifests/mysqld_exporter/instance.pp', line 25

define prometheus::mysqld_exporter::instance (
    $client_socket = '/run/mysqld/mysqld.sock',
    $client_user = 'prometheus',
    $client_password = 'This is a fake passsword, but cannot be empty due to Debian #953040',
    $listen_address = ':9104',
    $arguments = '',
) {
    include prometheus::mysqld_exporter::common

    $my_cnf = "/var/lib/prometheus/.my.${title}.cnf"
    $service = "prometheus-mysqld-exporter@${title}"

    # prometheus collector option formatting changed since buster
    if os_version('debian >= buster') {
        $option_string = '--'
    } else {
        $option_string = '-'
    }
    $instance_options = "${option_string}web.listen-address \"${listen_address}\" \
${option_string}config.my-cnf \"${my_cnf}\""

    # Add sane default arguments if none provided
    if $arguments == '' {
        $common_options = "${option_string}collect.global_status \
${option_string}collect.global_variables \
${option_string}collect.info_schema.processlist \
${option_string}collect.slave_status"
        if os_version('debian >= buster') {
            $general_options = "${common_options} ${option_string}no-collect.info_schema.tables"
        } else {
            $general_options = "${common_options} ${option_string}collect.info_schema.processlist.min_time 0 \
${option_string}collect.info_schema.tables false"
        }
    } else {
        $general_options = $arguments
    }

    file { "/etc/default/prometheus-mysqld-exporter@${title}":
        ensure  => present,
        mode    => '0444',
        owner   => 'root',
        group   => 'root',
        content => "ARGS='${instance_options} ${general_options}'",
        notify  => Service[$service],
    }

    # a separate database config (.my.<instance_name>cnf) for each instance monitored
    # change the systemd unit if the patch changes here, as it depends on it
    file { $my_cnf:
        ensure  => present,
        mode    => '0400',
        owner   => 'prometheus',
        group   => 'prometheus',
        content => template('prometheus/mysqld_exporter.cnf.erb'),
        notify  => Service[$service],
    }

    service { $service:
        ensure  => running,
        require => File['/lib/systemd/system/prometheus-mysqld-exporter@.service'],
    }

    base::service_auto_restart { $service: }
}