Skip to content

Commit

Permalink
postgres_exporter: Build from source for per-index stats.
Browse files Browse the repository at this point in the history
This builds prometheus-community/postgres_exporter#843 to track
per-index statistics.
  • Loading branch information
alexmv authored and freshpex committed Sep 14, 2023
1 parent a79704a commit ae25901
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 8 deletions.
6 changes: 6 additions & 0 deletions puppet/zulip/manifests/common.pp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@
},
},

# https://github.com/prometheus-community/postgres_exporter/pull/843
'postgres_exporter-src' => {
'version' => '4881e566207b1675f8b2ceae9bcd71f61800ccd1',
'sha256' => '1b0aaf32e3834f02e5448fb21c0de114a4e42cc0937300e307899efb8438bf16',
},

# https://github.com/ncabatoff/process-exporter/releases
'process_exporter' => {
'version' => '0.7.10',
Expand Down
47 changes: 40 additions & 7 deletions puppet/zulip_ops/manifests/prometheus/postgresql.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,48 @@
class zulip_ops::prometheus::postgresql {
include zulip_ops::prometheus::base
include zulip::supervisor
include zulip::golang

$version = $zulip::common::versions['postgres_exporter']['version']
$dir = "/srv/zulip-postgres_exporter-${version}"
$bin = "${dir}/postgres_exporter"
$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}"

zulip::external_dep { 'postgres_exporter':
# 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':
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}",
url => "https://github.com/Sticksman/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'],
}

exec { 'create prometheus postgres user':
Expand All @@ -27,7 +60,7 @@
Exec['create prometheus postgres user'],
User[prometheus],
Package[supervisor],
Zulip::External_Dep['postgres_exporter'],
File[$bin],
],
owner => 'root',
group => 'root',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[program:prometheus_postgres_exporter]
command=<%= @bin %>
command=<%= @bin %> --collector.stat_user_indexes
environment=DATA_SOURCE_NAME="postgresql://prometheus@:5432/zulip?host=/var/run/postgresql"
priority=10
autostart=true
Expand Down

0 comments on commit ae25901

Please sign in to comment.