Defined Type: prometheus::mysqld_exporter

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

Overview

Parameters:

  • client_socket (Any) (defaults to: '/tmp/mysql.sock')
  • client_user (Any) (defaults to: 'prometheus')
  • client_password (Any) (defaults to: '')
  • arguments (Any) (defaults to: '')


21
22
23
24
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
# File 'modules/prometheus/manifests/mysqld_exporter.pp', line 21

define prometheus::mysqld_exporter (
    $client_socket = '/tmp/mysql.sock',
    $client_user = 'prometheus',
    $client_password = '',
    $arguments = '',
) {
    require_package('prometheus-mysqld-exporter')

    file { '/var/lib/prometheus':
        ensure => directory,
        mode   => '0550',
        owner  => 'prometheus',
        group  => 'prometheus',
    }

    # default .my.cnf location (i.e. $HOME/.my.cnf)
    file { '/var/lib/prometheus/.my.cnf':
        ensure  => present,
        mode    => '0400',
        owner   => 'prometheus',
        group   => 'prometheus',
        content => template('prometheus/mysqld_exporter.cnf.erb'),
        require => [
          Package['prometheus-mysqld-exporter'],
          File['/var/lib/prometheus'],
        ],
        notify  => Service['prometheus-mysqld-exporter'],
    }

    # Set default arguments
    if $arguments == '' {
        if os_version('debian >= buster') {
            $options = "--collect.global_status \
--collect.global_variables \
--collect.info_schema.processlist \
--collect.slave_status \
--no-collect.info_schema.tables"
        } else {
            $options = "-collect.global_status \
-collect.global_variables \
-collect.info_schema.processlist \
-collect.info_schema.processlist.min_time 0 \
-collect.slave_status \
-collect.info_schema.tables false"
        }
    } else {
        $options = $arguments
    }

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

    service { 'prometheus-mysqld-exporter':
        ensure  => running,
        require => [Package['prometheus-mysqld-exporter'],
                    File['/var/lib/prometheus/.my.cnf']],
    }

    base::service_auto_restart { 'prometheus-mysqld-exporter': }
}