[MediaWiki-commits] [Gerrit] operations/puppet[production]: prometheus: add redis_exporter class and profile

2017-11-09 Thread Filippo Giunchedi (Code Review)
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}

[MediaWiki-commits] [Gerrit] operations/puppet[production]: prometheus: add redis_exporter class

2016-12-05 Thread Filippo Giunchedi (Code Review)
Filippo Giunchedi has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/325466

Change subject: prometheus: add redis_exporter class
..

prometheus: add redis_exporter class

Monitor a single redis instance given its address and password.

Bug: T148637
Change-Id: Iba79dd8a3afcefba776934caa17291322df8809a
---
A modules/prometheus/manifests/redis_exporter.pp
A 
modules/prometheus/templates/initscripts/prometheus-redis-expor...@.systemd.erb
2 files changed, 60 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/66/325466/1

diff --git a/modules/prometheus/manifests/redis_exporter.pp 
b/modules/prometheus/manifests/redis_exporter.pp
new file mode 100644
index 000..66152e8
--- /dev/null
+++ b/modules/prometheus/manifests/redis_exporter.pp
@@ -0,0 +1,47 @@
+# 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
+#
+# [*$redis_password*]
+#  The Redis instance password
+#
+# [*$listen_address*]
+#  The host:port tuple to listen on, host can be omitted.
+
+define prometheus::redis_exporter (
+$instance = $title,
+$arguments = '',
+$redis_password = '',
+$listen_address = ':9121',
+) {
+require_package('prometheus-redis-exporter')
+$service_name = "prometheus-redis-exporter@${instance}"
+
+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=\"${redis_password}\"",
+notify  => Service[$service_name],
+}
+
+base::service_unit { $service_name:
+ensure=> present,
+refresh   => true,
+systemd   => true,
+template_name => 'prometheus-redis-exporter@',
+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 000..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: newchange
Gerrit-Change-Id: Iba79dd8a3afcefba776934caa17291322df8809a
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Filippo Giunchedi 

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