Faidon Liambotis has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/367877 )
Change subject: Revert "Kill module puppet_statsd"
......................................................................
Revert "Kill module puppet_statsd"
This reverts commit 995500b495e19866f346a66d28cfd8f91d9e5cc4.
Change-Id: I3d1d3cc27d0d7d42d097b8b02715402f8160e3c3
---
M .rubocop_todo.yml
A modules/puppet_statsd/README.md
A modules/puppet_statsd/lib/facter/puppet_config_dir.rb
A modules/puppet_statsd/lib/puppet/reports/statsd.rb
A modules/puppet_statsd/manifests/init.pp
A modules/puppet_statsd/templates/statsd.yaml.erb
6 files changed, 144 insertions(+), 0 deletions(-)
Approvals:
Faidon Liambotis: Verified; Looks good to me, approved
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index 1e01d06..4f63875 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -9,6 +9,7 @@
Lint/UselessAssignment:
Exclude:
+ - 'modules/puppet_statsd/lib/puppet/reports/statsd.rb'
- 'modules/service/Rakefile'
- 'modules/wmflib/lib/puppet/parser/functions/validate_array_re.rb'
@@ -95,6 +96,10 @@
Exclude:
- 'modules/graphite/lib/puppet/parser/functions/configparser_format.rb'
+Style/RedundantSelf:
+ Exclude:
+ - 'modules/puppet_statsd/lib/puppet/reports/statsd.rb'
+
Style/RegexpLiteral:
Exclude:
- 'modules/bacula/spec/classes/bacula_client_spec.rb'
@@ -122,6 +127,7 @@
Exclude:
- 'modules/base/lib/facter/labsproject.rb'
- 'modules/graphite/lib/puppet/parser/functions/configparser_format.rb'
+ - 'modules/puppet_statsd/lib/puppet/reports/statsd.rb'
- 'modules/wmflib/lib/puppet/parser/functions/ini.rb'
Layout/SpaceAroundEqualsInParameterDefault:
diff --git a/modules/puppet_statsd/README.md b/modules/puppet_statsd/README.md
new file mode 100644
index 0000000..d2181bd
--- /dev/null
+++ b/modules/puppet_statsd/README.md
@@ -0,0 +1,46 @@
+# Puppet StatsD reporter
+
+This module configures a Puppet reporter that sends timing information on
+Puppet runs to StatsD.
+
+### Setup
+
+To configure StatsD reporting, enable pluginsync and reports on your master and
+clients in `puppet.conf`:
+
+```ini
+[master]
+report = true
+reports = statsd
+pluginsync = true
+
+[agent]
+report = true
+pluginsync = true
+```
+
+And include the class on all nodes you want to report:
+
+```puppet
+class { 'puppet_statsd':
+ statsd_host => 'statsd.eqiad.wmnet',
+ statsd_port => 8125,
+ metric_format => 'puppet.<%= metric %>.<%= hostname %>',
+}
+```
+
+### Module parameters
+
+* `statsd_host`: StatsD host to send metrics to.
+* `statsd_port`: Port on which StatsD host is listening (default: 8125).
+* `metric_format`: ERB Template string for metric names; the variables
+ 'hostname' and 'metric' will be set in template scope to the local hostname
+ and the metric name, respectively. Default: 'puppet.<%= metric %>.<%=
hostname %>'.
+
+### License
+
+Copyright (c) 2013 Ori Livneh and Wikimedia Foundation. All Rights Reserved.
+
+`puppet_statsd` is distributed under the GNU General Public License, Version 2,
+or, at your discretion, any later version. The GNU General Public License is
+available via the Web at <http://www.gnu.org/licenses/gpl-2.0.html>.
diff --git a/modules/puppet_statsd/lib/facter/puppet_config_dir.rb
b/modules/puppet_statsd/lib/facter/puppet_config_dir.rb
new file mode 100644
index 0000000..2aae8d4
--- /dev/null
+++ b/modules/puppet_statsd/lib/facter/puppet_config_dir.rb
@@ -0,0 +1,9 @@
+# Defines a custom Facter fact, $puppet_config_dir, which specifies the
+# location of Puppet's configuration directory (usually /etc/puppet).
+require 'puppet'
+
+Facter.add('puppet_config_dir') do
+ setcode do
+ Puppet.settings[:confdir]
+ end
+end
diff --git a/modules/puppet_statsd/lib/puppet/reports/statsd.rb
b/modules/puppet_statsd/lib/puppet/reports/statsd.rb
new file mode 100644
index 0000000..becf69d
--- /dev/null
+++ b/modules/puppet_statsd/lib/puppet/reports/statsd.rb
@@ -0,0 +1,30 @@
+# Puppet StatsD reporter
+# Sends timing measurements for Puppet runs to StatsD
+require 'puppet'
+require 'yaml'
+require 'erb'
+
+Puppet::Reports.register_report(:statsd) do
+ desc = 'Send Puppet metrics to StatsD'
+
+ def load_config
+ config_file = File.join Puppet.settings[:confdir], 'statsd.yaml'
+ raise Puppet::ParseError, "#{config_file} is missing" unless
File.exists? config_file
+ YAML.load_file(config_file)
+ end
+
+ def process
+ config = load_config
+ hostname = self.host
+ Puppet.notice "Sending metrics for #{self.host} to "\
+ "#{config[:statsd_host]}:#{config[:statsd_port]}.."
+
+ socket = UDPSocket.new
+ self.metrics['time'].values.each do |metric,description,value|
+ value = (value * 1000).round # Convert fractional seconds to
whole miliseconds
+ name = ERB.new(config[:metric_format]).result(binding)
+ socket.send("#{name}:#{value}|ms", 0, config[:statsd_host],
config[:statsd_port])
+ end
+ socket.close
+ end
+end
diff --git a/modules/puppet_statsd/manifests/init.pp
b/modules/puppet_statsd/manifests/init.pp
new file mode 100644
index 0000000..0408cee
--- /dev/null
+++ b/modules/puppet_statsd/manifests/init.pp
@@ -0,0 +1,47 @@
+# == Class: puppet_statsd
+#
+# This module configures a Puppet reporter that sends timing information
+# on Puppet runs to StatsD.
+#
+# === Parameters
+#
+# [*statsd_host*]
+# StatsD host to send metrics to.
+#
+# [*statsd_port*]
+# Port on which StatsD host is listening (default: 8125).
+#
+# [*metric_format*]
+# ERB Template string for metric names; the variables 'hostname' and
+# 'metric' will be set in template scope to the local hostname and the
+# metric name, respectively. Default: 'puppet.<%= metric %>.<%= hostname %>'.
+#
+# === Examples
+#
+# To enable, enable pluginsync and reports on your master and clients in
+# puppet.conf:
+#
+# [master]
+# report = true
+# reports = statsd
+# pluginsync = true
+#
+# [agent]
+# report = true
+# pluginsync = true
+#
+# ..and include the class:
+#
+# class { 'puppet_statsd':
+# statsd_host => 'statsd.eqiad.wmnet',
+# }
+#
+class puppet_statsd(
+ $statsd_host,
+ $statsd_port = 8125,
+ $metric_format = 'puppet.<%= metric %>.<%= hostname %>'
+) {
+ file { "${::puppet_config_dir}/statsd.yaml":
+ content => template('puppet_statsd/statsd.yaml.erb'),
+ }
+}
diff --git a/modules/puppet_statsd/templates/statsd.yaml.erb
b/modules/puppet_statsd/templates/statsd.yaml.erb
new file mode 100644
index 0000000..23921ca
--- /dev/null
+++ b/modules/puppet_statsd/templates/statsd.yaml.erb
@@ -0,0 +1,6 @@
+# Configuration file for Puppet StatsD reporter
+# Managed by Puppet.
+---
+:statsd_host: '<%= @statsd_host %>'
+:statsd_port: <%= @statsd_port.to_i %>
+:metric_format: '<%= @metric_format %>'
--
To view, visit https://gerrit.wikimedia.org/r/367877
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I3d1d3cc27d0d7d42d097b8b02715402f8160e3c3
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Faidon Liambotis <[email protected]>
Gerrit-Reviewer: Alexandros Kosiaris <[email protected]>
Gerrit-Reviewer: Faidon Liambotis <[email protected]>
Gerrit-Reviewer: Giuseppe Lavagetto <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits