zulip/puppet/kandra/manifests/prometheus/postgresql.pp

83 lines
3.0 KiB
ObjectPascal
Raw Normal View History

2023-03-30 19:50:28 +02:00
# @summary Prometheus monitoring of postgresql servers
#
class kandra::prometheus::postgresql {
include kandra::prometheus::base
2023-03-30 19:50:28 +02:00
include zulip::supervisor
include zulip::golang
2023-03-30 19:50:28 +02:00
$version = $zulip::common::versions['postgres_exporter-src']['version']
$dir = "/srv/zulip-postgres_exporter-src-${version}"
$bin = "/usr/local/bin/postgres_exporter-${version}-go-${zulip::golang::version}"
2023-03-30 19:50:28 +02:00
# Binary builds: https://github.com/prometheus-community/postgres_exporter/releases/download/v${version}/postgres_exporter-${version}.linux-${zulip::common::goarch}.tar.gz
zulip::external_dep { 'postgres_exporter-src':
2023-03-30 19:50:28 +02:00
version => $version,
url => "https://github.com/alexmv/postgres_exporter/archive/${version}.tar.gz",
tarball_prefix => "postgres_exporter-${version}",
}
exec { 'compile postgres_exporter':
command => "make build && cp ./postgres_exporter ${bin}",
cwd => $dir,
# GOCACHE is required; nothing is written to GOPATH, but it is required to be set
environment => ['GOCACHE=/tmp/gocache', 'GOPATH=/root/go'],
path => [
"${zulip::golang::dir}/bin",
'/usr/local/bin',
'/usr/bin',
'/bin',
],
creates => $bin,
require => [
Zulip::External_Dep['golang'],
Zulip::External_Dep['postgres_exporter-src'],
]
}
# This resource exists purely so it doesn't get tidied; it is
# created by the 'compile postgres_exporter' step.
file { $bin:
ensure => file,
require => Exec['compile postgres_exporter'],
}
tidy { '/usr/local/bin/postgres_exporter-*':
path => '/usr/local/bin',
recurse => 1,
matches => 'postgres_exporter-*',
require => Exec['compile postgres_exporter'],
2023-03-30 19:50:28 +02:00
}
if false {
# This is left commented out, since it only makes sense to run
# against a server where the database exists and is writable --
# the former of which happens outside th scope of puppet right
# now, and the latter of which can only be determined after the
# database is in place. Given that it has been run once, we do
# not expect to ever need it to run again; it is left here for
# completeness.
include zulip::postgresql_client
exec { 'create prometheus postgres user':
require => Class['zulip::postgresql_client'],
command => '/usr/bin/createuser -g pg_monitor prometheus',
unless => 'test -f /usr/bin/psql && /usr/bin/psql -tAc "select usename from pg_user" | /bin/grep -xq prometheus)',
user => 'postgres',
before => File["${zulip::common::supervisor_conf_dir}/prometheus_postgres_exporter.conf"],
}
2023-03-30 19:50:28 +02:00
}
kandra::firewall_allow { 'postgres_exporter': port => '9187' }
2023-03-30 19:50:28 +02:00
file { "${zulip::common::supervisor_conf_dir}/prometheus_postgres_exporter.conf":
ensure => file,
require => [
User[prometheus],
Package[supervisor],
File[$bin],
2023-03-30 19:50:28 +02:00
],
owner => 'root',
group => 'root',
mode => '0644',
content => template('kandra/supervisor/conf.d/prometheus_postgres_exporter.conf.template.erb'),
2023-03-30 19:50:28 +02:00
notify => Service[supervisor],
}
}