Skip to content

Instantly share code, notes, and snippets.

@lukebigum
lukebigum / tail-sfptpd_stats.conf
Created December 23, 2015 09:52
collectd sfptpd stats Tailer
# Generated by Puppet
<Plugin "tail">
<File "/var/log/sfptpd/stats.log">
Instance "sfptpd_stats"
<Match>
Regex "->phc6\\(.*offset:[[:space:]]+(-?[[:digit:]]+\\.[[:digit:]]+)"
DSType "GaugeLast"
Type "precise_time_offset"
Instance "offset-phc6"
@lukebigum
lukebigum / networking_driver_to_interface.rb
Last active December 23, 2015 09:27
Facter Fact of networking drivers and the interfaces that uses them
#LB: This custom fact will create Facter facts of the format nic_driver_<driver>
#that contain a comma separated string of all the networking interfaces that use this driver.
#Facter already knows about interfaces
drivers = Hash.new
Facter.value(:interfaces).split(',').each do |int|
#call ethtool to get the driver for this NIC
driver = %x{/sbin/ethtool -i #{int} 2>/dev/null | grep 'driver: '}.chomp.sub("driver: ", "")
if driver == ''
driver = 'virtual'
@lukebigum
lukebigum / profile_statistics_sfptpd.pp
Last active December 23, 2015 09:49
sfptpd statistics with Collectd Tail Plugin
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
@lukebigum
lukebigum / phc.rb
Created December 23, 2015 09:15
Facter Fact for PTP Hardware Clocks
#Look for networking interfaces that have ptp devices
module PhcFact
def self.add_facts
phc = {}
Dir.glob("/sys/class/net/*/device/ptp/*") do |dir|
m = /\/sys\/class\/net\/(\S+)\/device\/ptp\/(\S+)/.match(dir)
phc[m[1]] = m[2]
end
Facter.add("phc") do
setcode do
@lukebigum
lukebigum / subs_repl_array.rb
Last active December 23, 2015 09:41
Substitute and Replicate Array
module Puppet::Parser::Functions
newfunction(:subs_repl_array, :type => :rvalue, :doc => <<-'ENDHEREDOC'
Takes an Array of strings and a hash of strings, then for every element in the array,
it goes searching the hash values for the string 'SUBS' and replaces it with the array element.
The value returned is itself an array of hashes, where each hash element is a copy of the input hash
with the relevant substitution made. The number of hashes returned is the same as the input array.
$out_array = subs_repl_array($in_array, $in_hash)
@lukebigum
lukebigum / sfptpd.pp
Created December 22, 2015 17:09
sfptpd via supervisord
class { 'sfptpd':
interface => $management_interface,
stats_log_enable => true,
manage_service => false,
daemon => false,
message_log => 'stderr',
stats_log_file => 'stdout',
}
class { 'supervisord':
@lukebigum
lukebigum / ptp_bridge.pp
Created December 10, 2015 17:00
PTP Bridge more statistics
class { '::profile::statistics':
interval => 1,
}
class { '::profile::statistics::write_network':
server => 'localhost',
}
class { '::profile::statistics::remote_ntp_offset':
ntp_server => 'timesource.example.com',
}
include ::collectd::plugin::tail
@lukebigum
lukebigum / ptp_bridge.pp
Last active December 10, 2015 17:01
PTP bridge base statistics
class { '::profile::statistics':
interval => 1,
}
class { '::profile::statistics::write_network':
server => 'localhost',
}
class { '::profile::statistics::remote_ntp_offset':
ntp_server => 'timesource.example.com',
}
@lukebigum
lukebigum / write_network.pp
Created December 10, 2015 16:56
Collectd write to network
class profile::statistics::write_network($server = 'localhost') inherits profile {
collectd::plugin::network::server { $server:
port => 25826,
}
}
@lukebigum
lukebigum / tail_linuxptp_log.pp
Created December 10, 2015 15:51
Collectd tail linuxptp log file
define profile::statistics::tail_linuxptp_log($filename) {
collectd::plugin::tail::file { $name:
filename => $filename,
instance => $name,
matches => [
{
regex => 'offset[[:space:]]+(-?[[:digit:]]+)',
dstype => 'GaugeLast',
type => 'precise_time_offset',
instance => 'offset',