Merge remote-tracking branch 'upstream/master' into stacklight
diff --git a/galera/files/collectd_mysql.conf b/galera/files/collectd_mysql.conf
new file mode 100644
index 0000000..ce5bf55
--- /dev/null
+++ b/galera/files/collectd_mysql.conf
@@ -0,0 +1,14 @@
+<LoadPlugin mysql>
+  Globals false
+</LoadPlugin>
+
+<Plugin mysql>
+    <Database "mysql">
+        Host "localhost"
+        Socket "{{ plugin.socket }}"
+        User "{{ plugin.username }}"
+        Password "{{ plugin.password }}"
+        MasterStats false
+        SlaveStats false
+    </Database>
+</Plugin>
diff --git a/galera/files/collectd_mysql_check.conf b/galera/files/collectd_mysql_check.conf
new file mode 100644
index 0000000..d772c84
--- /dev/null
+++ b/galera/files/collectd_mysql_check.conf
@@ -0,0 +1,9 @@
+Import "collectd_mysql_check"
+
+<Module "collectd_mysql_check">
+    Host "localhost"
+    Socket "{{ plugin.socket }}"
+    Username "{{ plugin.username }}"
+    Password "{{ plugin.password }}"
+</Module>
+
diff --git a/galera/files/collectd_mysql_status.conf b/galera/files/collectd_mysql_status.conf
new file mode 100644
index 0000000..2a32845
--- /dev/null
+++ b/galera/files/collectd_mysql_status.conf
@@ -0,0 +1,44 @@
+<LoadPlugin dbi>
+  Globals false
+</LoadPlugin>
+
+<Plugin dbi>
+  <Query "wsrep_ready">
+    Statement "select replace(lower(VARIABLE_NAME), 'wsrep_', 'cluster.') as metric, replace(replace(VARIABLE_VALUE, 'ON', 1), 'OFF', 0) as value from information_schema.GLOBAL_STATUS where VARIABLE_NAME IN ('wsrep_ready', 'wsrep_connected');"
+    MinVersion 50000
+    <Result>
+      Type "gauge"
+      InstancesFrom "metric"
+      ValuesFrom "value"
+    </Result>
+  </Query>
+  <Query "wsrep_cluster_status">
+    Statement "select replace(replace(lower(VARIABLE_NAME), 'wsrep_', ''), '_', '.') as metric, replace(replace(replace(VARIABLE_VALUE, 'Primary', 1), 'Non-Primary', 2), 'Disconnected', 3) as value from information_schema.GLOBAL_STATUS where VARIABLE_NAME = 'wsrep_cluster_status';"
+    MinVersion 50000
+    <Result>
+      Type "gauge"
+      InstancesFrom "metric"
+      ValuesFrom "value"
+    </Result>
+  </Query>
+  <Query "wsrep_cluster">
+    Statement "select replace(replace(lower(VARIABLE_NAME), 'wsrep_', 'cluster.'), 'cluster_size', 'size') as metric, VARIABLE_VALUE as value from information_schema.GLOBAL_STATUS where VARIABLE_NAME IN ('wsrep_cluster_size', 'wsrep_replicated', 'wsrep_replicated_bytes', 'wsrep_received_bytes', 'wsrep_received', 'wsrep_local_commits', 'wsrep_local_cert_failures', 'wsrep_local_send_queue', 'Slow_queries');"
+    MinVersion 50000
+    <Result>
+      Type "gauge"
+      InstancesFrom "metric"
+      ValuesFrom "value"
+    </Result>
+  </Query>
+  <Database "mysql_status">
+    Driver "mysql"
+    DriverOption "mysql_unix_socket" "{{ plugin.socket }}"
+    DriverOption "username" "{{ plugin.username }}"
+    DriverOption "password" "{{ plugin.password }}"
+    DriverOption "dbname" "mysql"
+    SelectDB "mysql"
+    Query "wsrep_ready"
+    Query "wsrep_cluster_status"
+    Query "wsrep_cluster"
+  </Database>
+</Plugin>
diff --git a/galera/map.jinja b/galera/map.jinja
index bed74ad..cf9c66d 100644
--- a/galera/map.jinja
+++ b/galera/map.jinja
@@ -1,7 +1,7 @@
 
 {%- set master = salt['grains.filter_by']({
   'Debian': {
-    'pkgs': ['mysql-server-wsrep-5.6', 'galera-3', 'rsync', 'python-mysqldb', 'libmysqlclient18', 'psmisc', 'netcat', 'percona-xtrabackup', 'socat'],
+    'pkgs': ['mysql-server-wsrep-5.6', 'galera-3', 'rsync', 'python-mysqldb', 'libmysqlclient18', 'psmisc', 'netcat', 'percona-xtrabackup', 'socat', 'libdbd-mysql', 'python-pymysql'],
     'service': 'mysql',
     'wsrep_provider': '/usr/lib/galera/libgalera_smm.so',
     'log_file': '/var/log/mysql.log',
@@ -21,7 +21,7 @@
 
 {%- set slave = salt['grains.filter_by']({
   'Debian': {
-    'pkgs': ['mysql-server-wsrep', 'galera', 'rsync', 'python-mysqldb', 'libmysqlclient18', 'psmisc', 'netcat', 'percona-xtrabackup', 'socat'],
+    'pkgs': ['mysql-server-wsrep', 'galera', 'rsync', 'python-mysqldb', 'libmysqlclient18', 'psmisc', 'netcat', 'percona-xtrabackup', 'socat', 'libdbd-mysql', 'python-pymysql'],
     'service': 'mysql',
     'wsrep_provider': '/usr/lib/galera/libgalera_smm.so',
     'log_file': '/var/log/mysql.log',
diff --git a/galera/meta/collectd.yml b/galera/meta/collectd.yml
new file mode 100644
index 0000000..4533ad0
--- /dev/null
+++ b/galera/meta/collectd.yml
@@ -0,0 +1,29 @@
+{%- if pillar.galera is defined  %}
+{%- if pillar.galera.master is defined %}
+{%- from "galera/map.jinja" import master with context %}
+{%- set server = master %}
+{%- elif pillar.galera.slave is defined %}
+{%- from "galera/map.jinja" import slave with context %}
+{%- set server = slave %}
+{%- endif %}
+{%- endif %}
+
+{%- if server is defined %}
+local_plugin:
+  mysql:
+    template: galera/files/collectd_mysql.conf
+    socket: {{ server.socket }}
+    password: {{ server.admin.password }}
+    username: {{ server.admin.user }}
+  mysql_status:
+    template: galera/files/collectd_mysql_status.conf
+    socket: {{ server.socket }}
+    password: {{ server.admin.password }}
+    username: {{ server.admin.user }}
+  mysql_check:
+    plugin: python
+    template: galera/files/collectd_mysql_check.conf
+    socket: {{ server.socket }}
+    password: {{ server.admin.password }}
+    username: {{ server.admin.user }}
+{%- endif %}
diff --git a/metadata/service/master/cluster.yml b/metadata/service/master/cluster.yml
index db45e54..7705f6b 100644
--- a/metadata/service/master/cluster.yml
+++ b/metadata/service/master/cluster.yml
@@ -1,5 +1,7 @@
 applications:
 - galera
+classes:
+- service.galera.support
 parameters:
   _param:
     galera_server_cluster_name: galeracluster
@@ -32,4 +34,4 @@
       - name: haproxy
         host: '%'
       - name: haproxy
-        host: ${_param:cluster_local_address}
\ No newline at end of file
+        host: ${_param:cluster_local_address}
diff --git a/metadata/service/slave/cluster.yml b/metadata/service/slave/cluster.yml
index 8f829b2..2432da6 100644
--- a/metadata/service/slave/cluster.yml
+++ b/metadata/service/slave/cluster.yml
@@ -1,5 +1,7 @@
 applications:
 - galera
+classes:
+- service.galera.support
 parameters:
   _param:
     galera_server_cluster_name: galeracluster
@@ -32,4 +34,4 @@
       - name: haproxy
         host: '%'
       - name: haproxy
-        host: ${_param:cluster_local_address}
\ No newline at end of file
+        host: ${_param:cluster_local_address}
diff --git a/metadata/service/support.yml b/metadata/service/support.yml
index 61b87bd..96add0a 100644
--- a/metadata/service/support.yml
+++ b/metadata/service/support.yml
@@ -2,7 +2,7 @@
   galera:
     _support:
       collectd:
-        enabled: false
+        enabled: true
       heka:
         enabled: false
       sensu:
@@ -10,4 +10,4 @@
       sphinx:
         enabled: true
       config:
-        enabled: true
\ No newline at end of file
+        enabled: true