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 0000000..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 + 10000,
+) {
+    ::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}), AAAA))",
+    }
+}
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 0000000..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}"
+    $listen_address = "${host}:${port}"
+
+    # We're going with multiple prometheus-redis-exporter, mask the default 
single-instance one.
+    exec { "mask_default_redis_exporter_${instance}":
+        command => '/bin/systemctl mask prometheus-redis-exporter.service',
+        creates => '/etc/systemd/system/prometheus-redis-exporter.service',
+    }
+
+    file { "/etc/default/${service_name}":
+        ensure    => present,
+        mode      => '0400',
+        owner     => 'root',
+        group     => 'root',
+        content   => "ARGS=\"${arguments}\"\nREDIS_PASSWORD=\"${password}\"",
+        show_diff => false,
+        notify    => Service[$service_name],
+    }
+
+    systemd::unit { $service_name:
+        ensure  => present,
+        content => systemd_template('prometheus-redis-exporter@'),
+        restart => true,
+        require => Package['prometheus-redis-exporter'],
+    }
+}
diff --git 
a/modules/prometheus/templates/initscripts/prometheus-redis-expor...@.systemd.erb
 
b/modules/prometheus/templates/initscripts/prometheus-redis-expor...@.systemd.erb
new file mode 100644
index 0000000..739b2a7
--- /dev/null
+++ 
b/modules/prometheus/templates/initscripts/prometheus-redis-expor...@.systemd.erb
@@ -0,0 +1,13 @@
+[Unit]
+Description=Prometheus exporter for Redis server (instance %i)
+Documentation=https://prometheus.io/docs/introduction/overview/
+
+[Service]
+Restart=always
+User=prometheus
+Group=prometheus
+EnvironmentFile=/etc/default/prometheus-redis-exporter@%i
+ExecStart=/usr/bin/prometheus-redis-exporter -web.listen-address <%= 
@listen_address %> $ARGS
+
+[Install]
+WantedBy=multi-user.target

-- 
To view, visit https://gerrit.wikimedia.org/r/325466
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Iba79dd8a3afcefba776934caa17291322df8809a
Gerrit-PatchSet: 12
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Filippo Giunchedi <fgiunch...@wikimedia.org>
Gerrit-Reviewer: Alexandros Kosiaris <akosia...@wikimedia.org>
Gerrit-Reviewer: Elukey <ltosc...@wikimedia.org>
Gerrit-Reviewer: Filippo Giunchedi <fgiunch...@wikimedia.org>
Gerrit-Reviewer: Gehel <guillaume.leder...@wikimedia.org>
Gerrit-Reviewer: Giuseppe Lavagetto <glavage...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to