Filippo Giunchedi has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/325466 )
Change subject: prometheus: add redis_exporter class and profile
..
prometheus: add redis_exporter class and profile
Monitor a single redis instance given its address and password.
Bug: T148637
Change-Id: Iba79dd8a3afcefba776934caa17291322df8809a
---
A modules/profile/manifests/prometheus/redis_exporter.pp
M modules/profile/manifests/redis/master.pp
M modules/profile/manifests/redis/slave.pp
A modules/prometheus/manifests/redis_exporter.pp
A
modules/prometheus/templates/initscripts/prometheus-redis-expor...@.systemd.erb
5 files changed, 119 insertions(+), 1 deletion(-)
Approvals:
jenkins-bot: Verified
Filippo Giunchedi: Looks good to me, approved
diff --git a/modules/profile/manifests/prometheus/redis_exporter.pp
b/modules/profile/manifests/prometheus/redis_exporter.pp
new file mode 100644
index 000..6a8ebc8
--- /dev/null
+++ b/modules/profile/manifests/prometheus/redis_exporter.pp
@@ -0,0 +1,38 @@
+# == Define profile::prometheus::redis_exporter
+#
+# Install an instance of prometheus-redis-exporter.
+#
+# [*title*]
+# The port redis server is listening on
+#
+# [*password*]
+# The password to be used to access redis.
+#
+# [*host*]
+# The hostname for redis-exporter to listen on.
+#
+# [*port*]
+# The port for redis-exporter to listen on.
+#
+# [*prometheus_nodes*]
+# A list of hosts to allow access to redis-exporter
+#
+define profile::prometheus::redis_exporter (
+$password,
+$prometheus_nodes,
+$host = $::fqdn,
+$port = $title + 1,
+) {
+::prometheus::redis_exporter { $title:
+host => $host,
+port => $port,
+password => $password,
+}
+
+$prometheus_nodes_ferm = join($prometheus_nodes, ' ')
+ferm::service { "redis_exporter_${title}":
+proto => 'tcp',
+port => $port,
+srange => "(@resolve((${prometheus_nodes_ferm}))
@resolve((${prometheus_nodes_ferm}), ))",
+}
+}
diff --git a/modules/profile/manifests/redis/master.pp
b/modules/profile/manifests/redis/master.pp
index 6ee6ec9..fe40b77 100644
--- a/modules/profile/manifests/redis/master.pp
+++ b/modules/profile/manifests/redis/master.pp
@@ -3,7 +3,8 @@
$settings = hiera('profile::redis::master::settings'),
$password = hiera('profile::redis::master::password'),
$aof = hiera('profile::redis::master::aof', false),
-$clients = hiera('profile::redis::master::clients', [])
+$clients = hiera('profile::redis::master::clients', []),
+$prometheus_nodes = hiera('prometheus_nodes'),
){
$uris = apply_format("localhost:%s/${password}", $instances)
$redis_ports = join($instances, ' ')
@@ -33,6 +34,11 @@
settings => { instances => join($uris, ', ') }
}
+::profile::prometheus::redis_exporter{ $instances:
+password => $password,
+prometheus_nodes => $prometheus_nodes,
+}
+
::ferm::service { 'redis_master_role':
proto => 'tcp',
notrack => true,
diff --git a/modules/profile/manifests/redis/slave.pp
b/modules/profile/manifests/redis/slave.pp
index da043ad..79bae8b 100644
--- a/modules/profile/manifests/redis/slave.pp
+++ b/modules/profile/manifests/redis/slave.pp
@@ -2,6 +2,7 @@
$settings = hiera('profile::redis::slave::settings'),
$master = hiera('profile::redis::slave::master'),
$aof = hiera('profile::redis::slave::aof', false),
+$prometheus_nodes = hiera('prometheus_nodes'),
){
# Figure out the redis instances running on the master from Puppetdb
$resources = query_resources(
@@ -32,6 +33,11 @@
settings => { instances => join($uris, ', ') }
}
+profile::prometheus::redis_exporter{ $instances:
+password => $password,
+prometheus_nodes => $prometheus_nodes,
+}
+
ferm::service { 'redis_slave_role':
proto => 'tcp',
notrack => true,
diff --git a/modules/prometheus/manifests/redis_exporter.pp
b/modules/prometheus/manifests/redis_exporter.pp
new file mode 100644
index 000..bfca7c0
--- /dev/null
+++ b/modules/prometheus/manifests/redis_exporter.pp
@@ -0,0 +1,55 @@
+# Prometheus Redis server metrics exporter.
+#
+# === Parameters
+#
+# [*$instance*]
+# The instance name to use, e.g. as the service suffix.
+#
+# [*$arguments*]
+# The command line arguments to run prometheus-redis-exporter.
+#
+# [*$password*]
+# The Redis instance password.
+#
+# [*$host*]
+# The host to listen on. The host/port combination will also be used to
generate Prometheus
+# targets.
+#
+# [*$port*]
+# The port to listen on.
+
+define prometheus::redis_exporter (
+$instance = $title,
+$arguments = '',
+$password = '',
+$host = $::fqdn,
+$port = '9121'
+) {
+require_package('prometheus-redis-exporter')
+
+$service_name = "prometheus-redis-exporter@${instance}