Jcrespo has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/364396 )

Change subject: prometheus: Convert mysqld-exporter into multi-instance
......................................................................


prometheus: Convert mysqld-exporter into multi-instance

We need to monitor several independent mysql instances on the same
host. Add an additional resource that actually can be duplicated
so that more than one instance can be run at the same time.

For now this is implemented on a separate module and role manifest,
but it should eventually substitute the real classes.

A bug is corrected at the same time on the arguments, which will
is not yet applied to the generic class.

Bug: T170666
Change-Id: I664f04c7b026aedf32a1ef1ec648fea81dd47436
---
A modules/prometheus/manifests/mysqld_exporter/common.pp
A modules/prometheus/manifests/mysqld_exporter/instance.pp
A 
modules/prometheus/templates/initscripts/[email protected]
M modules/role/files/prometheus/mysql-dbstore_codfw.yaml
M modules/role/manifests/mariadb/dbstore_multiinstance.pp
A modules/role/manifests/prometheus/mysqld_exporter_instance.pp
6 files changed, 154 insertions(+), 2 deletions(-)

Approvals:
  jenkins-bot: Verified
  Jcrespo: Looks good to me, approved



diff --git a/modules/prometheus/manifests/mysqld_exporter/common.pp 
b/modules/prometheus/manifests/mysqld_exporter/common.pp
new file mode 100644
index 0000000..3f18340
--- /dev/null
+++ b/modules/prometheus/manifests/mysqld_exporter/common.pp
@@ -0,0 +1,23 @@
+# Setup the common resources for all mysqld exporter resources:
+# * The package installation
+# * The config dir
+# * The instance service (different from the package one)
+
+class prometheus::mysqld_exporter::common {
+    require_package('prometheus-mysqld-exporter')
+
+    file { '/etc/default/prometheus':
+        ensure => directory,
+        mode   => '0550',
+        owner  => 'prometheus',
+        group  => 'prometheus',
+    }
+
+    base::service_unit { 'prometheus-mysqld-exporter@':
+        ensure        => present,
+        refresh       => true,
+        systemd       => true,
+        template_name => 'prometheus-mysqld-exporter@',
+        require       => Package['prometheus-mysqld-exporter'],
+    }
+}
diff --git a/modules/prometheus/manifests/mysqld_exporter/instance.pp 
b/modules/prometheus/manifests/mysqld_exporter/instance.pp
new file mode 100644
index 0000000..52139bf
--- /dev/null
+++ b/modules/prometheus/manifests/mysqld_exporter/instance.pp
@@ -0,0 +1,60 @@
+# == Define: prometheus::mysqld_exporter::instance
+#
+# Prometheus exporter for MySQL server metrics. The exporter is most effective
+# when ran alongside the MySQL server to be monitored, connecting via a local
+# UNIX socket is supported.
+#
+# = Parameters
+#
+# [*client_socket*]
+#   The socket to connect to.
+#
+# [*client_user*]
+#   MySQL user
+#
+# [*client_password*]
+#   MySQL password
+#
+# [*listen_address*]
+#   ip/host and port, colon separated, where the prometheus exporter will 
listen for
+#   http metrics requests. Host can be omitted.
+#
+# [*arguments*]
+#   Additional command line arguments for prometheus-mysqld-exporter.
+
+define prometheus::mysqld_exporter::instance (
+    $client_socket = '/run/mysqld/mysqld.sock',
+    $client_user = 'prometheus',
+    $client_password = '',
+    $listen_address = ':9104',
+    $arguments = '',
+) {
+    include prometheus::mysqld_exporter::common
+
+    $my_cnf = "/var/lib/prometheus/.my.${title}.cnf"
+    $service = "prometheus-mysqld-exporter@${title}"
+
+    file { "/etc/default/prometheus-mysqld-exporter@${title}":
+        ensure  => present,
+        mode    => '0444',
+        owner   => 'root',
+        group   => 'root',
+        content => "ARGS=\"-web.listen-address=${listen_address} 
-config.my-cnf=${my_cnf} ${arguments}\"",
+        notify  => Service[$service],
+    }
+
+    # a separate database config (.my.<instance_name>cnf) for each instance 
monitored
+    # change the systemd unit if the patch changes here, as it depends on it
+    file { $my_cnf:
+        ensure  => present,
+        mode    => '0400',
+        owner   => 'prometheus',
+        group   => 'prometheus',
+        content => template('prometheus/mysqld_exporter.cnf.erb'),
+        notify  => Service[$service],
+    }
+
+    service { $service:
+        ensure  => running,
+    }
+}
diff --git 
a/modules/prometheus/templates/initscripts/[email protected]
 
b/modules/prometheus/templates/initscripts/[email protected]
new file mode 100644
index 0000000..5585602
--- /dev/null
+++ 
b/modules/prometheus/templates/initscripts/[email protected]
@@ -0,0 +1,14 @@
+[Unit]
+Description=Prometheus exporter for MySQL (instance %i)
+Documentation=https://prometheus.io/docs/introduction/overview/
+ConditionPathExists=/etc/default/prometheus-mysqld-exporter@%i
+
+[Service]
+Restart=always
+User=prometheus
+Group=prometheus
+EnvironmentFile=/etc/default/prometheus-mysqld-exporter@%i
+ExecStart=/usr/bin/prometheus-mysqld-exporter $ARGS
+
+[Install]
+WantedBy=multi-user.target
diff --git a/modules/role/files/prometheus/mysql-dbstore_codfw.yaml 
b/modules/role/files/prometheus/mysql-dbstore_codfw.yaml
index a126c60..88227c6 100644
--- a/modules/role/files/prometheus/mysql-dbstore_codfw.yaml
+++ b/modules/role/files/prometheus/mysql-dbstore_codfw.yaml
@@ -3,5 +3,6 @@
     shard: multi
   targets:
   - dbstore2001:9104
-  - dbstore2002:9104
-
+  - dbstore2002:13311
+  - dbstore2002:13312
+  - dbstore2002:13320
diff --git a/modules/role/manifests/mariadb/dbstore_multiinstance.pp 
b/modules/role/manifests/mariadb/dbstore_multiinstance.pp
index c61195e..60d89d3 100644
--- a/modules/role/manifests/mariadb/dbstore_multiinstance.pp
+++ b/modules/role/manifests/mariadb/dbstore_multiinstance.pp
@@ -51,27 +51,51 @@
     mariadb::instance {'s1':
         port => 3311,
     }
+    role::prometheus::mysqld_exporter_instance {'s1':
+        port => 13311,
+    }
     mariadb::instance {'s2':
         port => 3312,
+    }
+    role::prometheus::mysqld_exporter_instance {'s2':
+        port => 13312,
     }
     #mariadb::instance {'s3':
     #    port => 3313,
     #}
+    #role::prometheus::mysqld_exporter_instance {'s3':
+    #    port => 13313,
+    #}
     #mariadb::instance {'s4':
     #    port => 3314,
+    #}
+    #role::prometheus::mysqld_exporter_instance {'s4':
+    #    port => 13314,
     #}
     #mariadb::instance {'s5':
     #    port => 3315,
     #}
+    #role::prometheus::mysqld_exporter_instance {'s5':
+    #    port => 13315,
+    #}
     #mariadb::instance {'s6':
     #    port => 3316,
+    #}
+    #role::prometheus::mysqld_exporter_instance {'s6':
+    #    port => 13316,
     #}
     #mariadb::instance {'s7':
     #    port => 3317,
     #}
+    #role::prometheus::mysqld_exporter_instance {'s7':
+    #    port => 13317,
+    #}
     mariadb::instance {'x1':
         port => 3320,
     }
+    role::prometheus::mysqld_exporter_instance {'x1':
+        port => 13320,
+    }
 
     class { 'mariadb::monitor_disk':
         is_critical   => false,
diff --git a/modules/role/manifests/prometheus/mysqld_exporter_instance.pp 
b/modules/role/manifests/prometheus/mysqld_exporter_instance.pp
new file mode 100644
index 0000000..e67d888
--- /dev/null
+++ b/modules/role/manifests/prometheus/mysqld_exporter_instance.pp
@@ -0,0 +1,30 @@
+define role::prometheus::mysqld_exporter_instance (
+    $socket = "/run/mysqld/mysqld.${title}.sock",
+    $port = 13306,
+    ) {
+
+    prometheus::mysqld_exporter::instance { $title:
+        client_socket  => $socket,
+        # TODO: collect also TokuDB metrics, but only from
+        # selected nodes
+        # TODO: collect table stats, but less frequently,
+        # and avoid s3/dbstore/labsdb hosts
+        arguments      => "-collect.global_status \
+-collect.global_variables \
+-collect.info_schema.processlist \
+-collect.info_schema.processlist.min_time=0 \
+-collect.slave_status \
+-collect.info_schema.tables=false \
+",
+        listen_address => ":${port}",
+    }
+
+    $prometheus_nodes = hiera('prometheus_nodes')
+    $prometheus_ferm_nodes = join($prometheus_nodes, ' ')
+
+    ferm::service { "prometheus-mysqld-exporter@${title}":
+        proto  => 'tcp',
+        port   => $port,
+        srange => "@resolve((${prometheus_ferm_nodes}))",
+    }
+}

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I664f04c7b026aedf32a1ef1ec648fea81dd47436
Gerrit-PatchSet: 21
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Jcrespo <[email protected]>
Gerrit-Reviewer: Filippo Giunchedi <[email protected]>
Gerrit-Reviewer: Jcrespo <[email protected]>
Gerrit-Reviewer: Marostegui <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to