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
87
88
89
90
91
92
93
94
95
|
# File 'modules/prometheus/manifests/mysqld_exporter.pp', line 21
define prometheus::mysqld_exporter (
$client_socket = '/tmp/mysql.sock',
$client_user = 'prometheus',
$client_password = '',
$arguments = '',
) {
#We only want to restart if the service is running
#(which it won't be if mariadb isn't)
exec { 'systemctl try-restart prometheus-mysqld-exporter':
refreshonly => true,
path => '/usr/bin',
}
ensure_packages('prometheus-mysqld-exporter', {'notify' => Exec['systemctl try-restart prometheus-mysqld-exporter']})
file { '/var/lib/prometheus':
ensure => directory,
mode => '0550',
require => Package['prometheus-mysqld-exporter'],
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 => Exec['systemctl try-restart prometheus-mysqld-exporter'],
}
# Set default arguments
if $arguments == '' {
$options = "--collect.global_status \
--collect.global_variables \
--collect.info_schema.processlist \
--collect.slave_status \
--no-collect.info_schema.tables"
}
else {
$options = $arguments
}
file { '/etc/default/prometheus-mysqld-exporter':
ensure => present,
mode => '0444',
owner => 'root',
group => 'root',
content => "ARGS=\"${options}\"",
notify => Exec['systemctl try-restart prometheus-mysqld-exporter'],
}
systemd::unit { 'prometheus-mysqld-exporter':
ensure => present,
override => true,
restart => false,
content => @(EOT)
#Ensure the prometheus exporter is (re-)started and stopped
#with the mariadb service
[Unit]
After=mariadb.service
Requisite=mariadb.service
| EOT
,
}
profile::auto_restarts::service { 'prometheus-mysqld-exporter': }
}
|