prometheus: Add a postgres exporter.

This commit is contained in:
Alex Vandiver 2023-03-30 17:50:28 +00:00 committed by Tim Abbott
parent c2beb64a79
commit 89e366771a
5 changed files with 58 additions and 0 deletions

View File

@ -112,6 +112,15 @@ class zulip::common {
},
},
# https://github.com/prometheus-community/postgres_exporter/tags
'postgres_exporter' => {
'version' => '0.12.0',
'sha256' => {
'amd64' => 'e3301d4b8b666b870491f520c098cc4c1ce32bb5dc22ee7f40ec1914d27be891',
'aarch64' => '60bde8f9adac2d066ba49c621a25a8d99877e3c2e2ddf9b8ba7c7188085de475',
},
},
# https://github.com/ncabatoff/process-exporter/releases
'process_exporter' => {
'version' => '0.7.10',

View File

@ -6,6 +6,7 @@ class zulip_ops::profile::chat_zulip_org {
include zulip_ops::profile::base
include zulip_ops::app_frontend_monitoring
include zulip_ops::prometheus::redis
include zulip_ops::prometheus::postgresql
zulip_ops::firewall_allow { 'http': }
zulip_ops::firewall_allow { 'https': }
zulip_ops::firewall_allow { 'smtp': }

View File

@ -2,6 +2,7 @@ class zulip_ops::profile::postgresql {
include zulip_ops::profile::base
include zulip::profile::postgresql
include zulip_ops::teleport::db
include zulip_ops::prometheus::postgresql
$common_packages = ['xfsprogs']
package { $common_packages: ensure => installed }

View File

@ -0,0 +1,38 @@
# @summary Prometheus monitoring of postgresql servers
#
class zulip_ops::prometheus::postgresql {
include zulip_ops::prometheus::base
include zulip::supervisor
$version = $zulip::common::versions['postgres_exporter']['version']
$dir = "/srv/zulip-postgres_exporter-${version}"
$bin = "${dir}/postgres_exporter"
zulip::external_dep { 'postgres_exporter':
version => $version,
url => "https://github.com/prometheus-community/postgres_exporter/releases/download/v${version}/postgres_exporter-${version}.linux-${zulip::common::goarch}.tar.gz",
tarball_prefix => "postgres_exporter-${version}.linux-${zulip::common::goarch}",
}
exec { 'create prometheus postgres user':
command => '/usr/bin/createuser -g pg_monitor prometheus',
unless => '/usr/bin/psql -tAc "select usename from pg_user" | /bin/grep -xq prometheus',
user => 'postgres',
}
zulip_ops::firewall_allow { 'postgres_exporter': port => '9187' }
file { "${zulip::common::supervisor_conf_dir}/prometheus_postgres_exporter.conf":
ensure => file,
require => [
Exec['create prometheus postgres user'],
User[prometheus],
Package[supervisor],
Zulip::External_Dep['postgres_exporter'],
],
owner => 'root',
group => 'root',
mode => '0644',
content => template('zulip_ops/supervisor/conf.d/prometheus_postgres_exporter.conf.template.erb'),
notify => Service[supervisor],
}
}

View File

@ -0,0 +1,9 @@
[program:prometheus_postgres_exporter]
command=<%= @bin %> --auto-discover-databases
environment=DATA_SOURCE_NAME="postgresql://prometheus@:5432/postgres?host=/var/run/postgresql"
priority=10
autostart=true
autorestart=true
user=prometheus
redirect_stderr=true
stdout_logfile=/var/log/zulip/postgres_exporter.log