Last active
December 23, 2015 09:49
-
-
Save lukebigum/a138cfe02854ae4cc779 to your computer and use it in GitHub Desktop.
sfptpd statistics with Collectd Tail Plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class profile::statistics::sfptpd( | |
$stats_log = '/var/log/sfptpd/stats.log', | |
$daemon_log = '/var/log/sfptpd/sfptpd.log', | |
) { | |
#LB: take the known SolarFlare cards and the hash of PTP Hardware Clocks, and get a unique list | |
#of phc device names so we know what to look for in the sfptpd log files. | |
if (!is_hash($::phc)) { | |
fail('The $::phc Fact is expected to be a hash, is stringify_facts=true?') | |
} | |
#LB: get Solar Flare NICs as an Array | |
$sfc_list = split($::nic_driver_sfc, ',') | |
#LB: for every SF NIC, print the ptp device name as a comma separated string | |
$sf_phcs = inline_template('<% @sfc_list.each do |nic| %><% if @phc.has_key?(nic) %><%= @phc[nic] %>,<% end %><% end %>') | |
#LB: replace 'ptp' with 'phc', split and deduplicate array | |
$sf_phcs_list = unique(split(regsubst($sf_phcs, 'ptp', 'phc', 'G'), ',')) | |
#LB: these are the three collectd::tail::file Matches hashes for the different | |
#metrics we want to pull from the sfptpd log. | |
$offset_hash = { | |
regex => "->SUBS\\\\(.*offset:[[:space:]]+(-?[[:digit:]]+\\\\.[[:digit:]]+)", | |
dstype => 'GaugeLast', | |
type => 'precise_time_offset', | |
instance => 'offset-SUBS', | |
} | |
$frequency_hash = { | |
regex => "->SUBS\\\\(.*freq-adj:[[:space:]]+(-?[[:digit:]]+\\\\.[[:digit:]]+)", | |
dstype => 'GaugeLast', | |
type => 'precise_frequency_offset', | |
instance => 'frequency-SUBS', | |
} | |
$delay_hash = { | |
regex => "->SUBS\\\\(.*one-way-delay:[[:space:]]+(-?[[:digit:]]+\\\\.[[:digit:]]+)", | |
dstype => 'GaugeLast', | |
type => 'precise_latency', | |
instance => 'path-delay-SUBS', | |
} | |
#LB: call our custom function subs_repl_array() 3 times, so we get one large array of the above | |
#matches for each of our SF PHCs plus the system clock | |
$in_array = flatten([[$sf_phcs_list], 'system']) | |
$offset_result = subs_repl_array($in_array, $offset_hash) | |
$frequency_result = subs_repl_array($in_array, $frequency_hash) | |
$delay_result = subs_repl_array($in_array, $delay_hash) | |
#LB: flatten everything into a 1D array | |
$final_result = [ $offset_result, $frequency_result, $delay_result ] | |
$matches = flatten($final_result) | |
#LB: collect stats for all SF PHCs being disciplined by the sfptpd daemon, plus the system clock | |
collectd::plugin::tail::file { 'sfptpd_stats': | |
filename => $stats_log, | |
instance => 'sfptpd_stats', | |
matches => $matches, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment