Skip to content

Commit

Permalink
Add support for a new parameter graphite_flatten_hostname that
Browse files Browse the repository at this point in the history
converts the hostname into one single graphite metric component.

In our case we do not use the components of the host fqdn as part of the
metric tree. Instead, the fqdn is a single component with dots replaced
by underscores. e.g. foo.example.com becomes foo_example_com.

This commit adds support for this but leaves it turned off by default.
It also adds the missing parameter docs to the class header.
  • Loading branch information
Taylan Develioglu committed Jun 24, 2016
1 parent a8d7e18 commit 3b81e27
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
21 changes: 13 additions & 8 deletions lib/puppet/reports/graphite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
GRAPHITE_PREFIX = config[:graphite_prefix]
GRAPHITE_SUFFIX = config[:graphite_suffix]
GRAPHITE_REVERSE_HOSTNAME = config[:graphite_reverse_hostname]
GRAPHITE_FLATTEN_HOSTNAME = config[:graphite_flatten_hostname]

desc <<-DESC
Send notification of failed reports to a Graphite server via socket.
Expand All @@ -26,25 +27,29 @@ def send_metric payload

def process
Puppet.debug "Sending status for #{self.host} to Graphite server at #{GRAPHITE_SERVER}"

prefix_parts = Array.new

if GRAPHITE_PREFIX != nil
prefix_parts.push GRAPHITE_PREFIX
end

hostname = self.host
if GRAPHITE_REVERSE_HOSTNAME
prefix_parts.push self.host.split(".").reverse.join(".")
else
prefix_parts.push self.host
hostname = hostname.split(".").reverse.join(".")
end

if GRAPHITE_FLATTEN_HOSTNAME
hostname = hostname.gsub(".", "_")
end

prefix_parts.push hostname

if GRAPHITE_SUFFIX != nil
prefix_parts.push GRAPHITE_SUFFIX
end

prefix = prefix_parts.join(".")

epochtime = Time.now.utc.to_i
self.metrics.each { |metric,data|
data.values.each { |val|
Expand Down
27 changes: 21 additions & 6 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@
# String. The config file's group. Should be pe_puppet for Puppet Enterprise.
# Default: puppet
#
# [*graphite_prefix*]
# String. Prefix to use for graphite metrics.
# Default: undef
#
# [*graphite_suffix*]
# String. Suffix to use for graphite metrics.
# Default: puppet
#
# [*graphite_reverse_hostname*]
# Bool. Reverse the components of the fqdn in the graphite metrics.
# Default: true
#
# [*graphite_flatten_hostname*]
# Bool. Replace all dot ('.') characters in the fqdn with underscores ('_').
# Default: false
#
# === Examples
#
Expand All @@ -41,15 +56,15 @@
#
#
class graphite_reporter (
$graphite_host = $graphite_reporter::params::graphite_host,
$graphite_port = $graphite_reporter::params::graphite_port,
$config_file = $graphite_reporter::params::config_file,
$config_owner = $graphite_reporter::params::config_owner,
$config_group = $graphite_reporter::params::config_group,

$graphite_host = $graphite_reporter::params::graphite_host,
$graphite_port = $graphite_reporter::params::graphite_port,
$config_file = $graphite_reporter::params::config_file,
$config_owner = $graphite_reporter::params::config_owner,
$config_group = $graphite_reporter::params::config_group,
$graphite_prefix = $graphite_reporter::params::graphite_prefix,
$graphite_suffix = $graphite_reporter::params::graphite_suffix,
$graphite_reverse_hostname = $graphite_reporter::params::graphite_reverse_hostname,
$graphite_flatten_hostname = $graphite_reporter::params::graphite_flatten_hostname,
) inherits graphite_reporter::params {

file { $config_file:
Expand Down
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
$graphite_prefix = undef
$graphite_suffix = 'puppet'
$graphite_reverse_hostname = true
$graphite_flatten_hostname = false

if str2bool($::is_pe) {
$config_file = '/etc/puppetlabs/puppet/graphite.yaml'
Expand Down
1 change: 1 addition & 0 deletions templates/graphite.yaml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
:graphite_prefix: <%= scope.lookupvar('graphite_prefix') %>
:graphite_suffix: <%= scope.lookupvar('graphite_suffix') %>
:graphite_reverse_hostname: <%= scope.lookupvar('graphite_reverse_hostname') %>
:graphite_flatten_hostname: <%= scope.lookupvar('graphite_flatten_hostname') %>

0 comments on commit 3b81e27

Please sign in to comment.