Filippo Giunchedi has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/391024 )
Change subject: prometheus: add redis jobs ...................................................................... prometheus: add redis jobs Similar to jmx_exporter_config, but for redis. Bug: T148637 Change-Id: Ief238c9623308a1ab96bc6cf09d8b9d4aed9d4ad --- M modules/prometheus/manifests/redis_exporter.pp A modules/prometheus/manifests/redis_exporter_config.pp A modules/prometheus/templates/redis_exporter_config.erb M modules/role/manifests/prometheus/ops.pp 4 files changed, 92 insertions(+), 3 deletions(-) Approvals: jenkins-bot: Verified Filippo Giunchedi: Looks good to me, approved diff --git a/modules/prometheus/manifests/redis_exporter.pp b/modules/prometheus/manifests/redis_exporter.pp index 987f2c5..482a1f0 100644 --- a/modules/prometheus/manifests/redis_exporter.pp +++ b/modules/prometheus/manifests/redis_exporter.pp @@ -11,7 +11,7 @@ # [*$password*] # The Redis instance password. # -# [*$host*] +# [*$hostname*] # The host to listen on. The host/port combination will also be used to generate Prometheus # targets. # @@ -22,13 +22,13 @@ $instance = $title, $arguments = '', $password = '', - $host = $::fqdn, + $hostname = $::fqdn, $port = '9121' ) { require_package('prometheus-redis-exporter') $service_name = "prometheus-redis-exporter@${instance}" - $listen_address = "${host}:${port}" + $listen_address = "${hostname}:${port}" # We're going with multiple prometheus-redis-exporter, mask and stop the default single-instance one. exec { "mask_default_redis_exporter_${instance}": diff --git a/modules/prometheus/manifests/redis_exporter_config.pp b/modules/prometheus/manifests/redis_exporter_config.pp new file mode 100644 index 0000000..966dc41 --- /dev/null +++ b/modules/prometheus/manifests/redis_exporter_config.pp @@ -0,0 +1,36 @@ +# == Define: prometheus::redis_exporter_config +# +# Generate prometheus targets configuration for all nodes belonging to $class +# and are defining prometheus::redis_exporter. +# Data is gathered using the puppetdb querying functions + +# == Parameters +# $dest: The output file where to write the result. +# $class_name: Class name to search. +# $site: The site to use. +# $labels: Labels to attach to every host. 'Cluster' will be added automagically as well + +define prometheus::redis_exporter_config( + $dest, + $class_name, + $site, + $labels = {}, +) { + validate_string($dest) + validate_string($site) + validate_hash($labels) + + $resources = query_resources( + "Class[\"${class_name}\"]", + 'Prometheus::Redis_exporter', + true) + $site_clusters = get_clusters({'site' => $site}) + + file { $dest: + ensure => present, + owner => 'root', + group => 'root', + mode => '0444', + content => template('prometheus/redis_exporter_config.erb'), + } +} diff --git a/modules/prometheus/templates/redis_exporter_config.erb b/modules/prometheus/templates/redis_exporter_config.erb new file mode 100644 index 0000000..ecb84f5 --- /dev/null +++ b/modules/prometheus/templates/redis_exporter_config.erb @@ -0,0 +1,29 @@ +<%- +# All labels / targets list +all = [] + + +# Find all hosts in the current site, grouped by cluster +@site_clusters.each do |cluster, val| + cluster_hosts = val[@site].select { |host| @resources.include?(host) } + if cluster_hosts.length > 0 + # For each host found, accumulate the resources we found for it into + # targets in the title:port form. + targets = [] + cluster_hosts.each{ |host| + @resources[host].each{ |instance| + targets.push("#{instance['parameters']['hostname']}:#{instance['parameters']['port']}") + } + } + + all.push( + { + 'labels' => @labels.merge({'cluster' => cluster}), + 'targets' => targets, + } + ) + end +end +-%> +# This file is managed by puppet +<%= scope.function_ordered_yaml([all]) %> diff --git a/modules/role/manifests/prometheus/ops.pp b/modules/role/manifests/prometheus/ops.pp index c6a761d..c323f3f 100644 --- a/modules/role/manifests/prometheus/ops.pp +++ b/modules/role/manifests/prometheus/ops.pp @@ -516,6 +516,29 @@ site => $::site, } + + $redis_jobs = [ + { + 'job_name' => 'redis', + 'scheme' => 'http', + 'file_sd_configs' => [ + { 'files' => [ "${targets_path}/redis_*.yaml" ]} + ], + }, + ] + + prometheus::redis_exporter_config{ "redis_master_${::site}": + dest => "${targets_path}/redis_master_${::site}.yaml", + class_name => 'profile::redis::master', + site => $::site, + } + + prometheus::redis_exporter_config{ "redis_slave_${::site}": + dest => "${targets_path}/redis_slave_${::site}.yaml", + class_name => 'profile::redis::slave', + site => $::site, + } + prometheus::server { 'ops': storage_encoding => '2', listen_address => '127.0.0.1:9900', @@ -526,6 +549,7 @@ $mysql_jobs, $varnish_jobs, $memcached_jobs, $hhvm_jobs, $apache_jobs, $etcd_jobs, $etcdmirror_jobs, $pdu_jobs, $nginx_jobs, $pybal_jobs, $blackbox_jobs, $jmx_exporter_jobs, + $redis_jobs, ), global_config_extra => $config_extra, } -- To view, visit https://gerrit.wikimedia.org/r/391024 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ief238c9623308a1ab96bc6cf09d8b9d4aed9d4ad Gerrit-PatchSet: 2 Gerrit-Project: operations/puppet Gerrit-Branch: production Gerrit-Owner: Filippo Giunchedi <fgiunch...@wikimedia.org> Gerrit-Reviewer: Filippo Giunchedi <fgiunch...@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