Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for flattening the hostname component of metrics. #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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') %>