daemon

package
v0.0.0-...-35f3e1e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MathDefaultHistory is a default number of samples to keep
	MathDefaultHistory = 100
	// MathDefaultM is a default formula to calculate M
	MathDefaultM = "mean(clockaccuracy, 100) + abs(mean(offset, 100)) + 1.0 * stddev(offset, 100)"
	// MathDefaultW is a default formula to calculate W
	MathDefaultW = "mean(m, 100) + 4.0 * stddev(m, 100)"
	// MathDefaultDrift is a default formula to calculate default drift
	MathDefaultDrift = "1.5 * mean(freqchangeabs, 99)"
)
View Source
const ManagedPTPDevicePath = string(fbclock.PTPPath)

ManagedPTPDevicePath is the path we will set up a copy of iface's PHC device, so that fbclock clients can access it without explicit configuration.

View Source
const MathHelp = `` /* 1161-byte string literal not displayed */

MathHelp is a help message used by flags in main

Variables

This section is empty.

Functions

func SetupDeviceDir

func SetupDeviceDir(iface string) error

SetupDeviceDir creates a PHC device path from the interface name

Types

type CSVLogger

type CSVLogger struct {
	// contains filtered or unexported fields
}

CSVLogger logs Sample as CSV into given writer

func NewCSVLogger

func NewCSVLogger(w io.Writer, sampleRate int) *CSVLogger

NewCSVLogger returns new CSVLogger

func (*CSVLogger) Log

func (l *CSVLogger) Log(s *LogSample) error

Log implements Logger interface

type Config

type Config struct {
	PTPClientAddress               string        // where should fbclock connect to
	RingSize                       int           // must be at least the size of N samples we use in expressions
	Math                           Math          // configuration for calculation we'll be doing
	Interval                       time.Duration // how often do we poll ptp4l and update data in shm
	Iface                          string        // network interface to use
	LinearizabilityTestInterval    time.Duration // perform the linearizability test every so often
	SPTP                           bool          // wherever we run in sptp or ptp4l mode
	LinearizabilityTestMaxGMOffset time.Duration // max offset between GMs before linearizability test considered failed
}

Config represents configuration we expect to read from file

func ReadConfig

func ReadConfig(path string) (*Config, error)

ReadConfig reads config and unmarshals it from yaml into Config

func (*Config) EvalAndValidate

func (c *Config) EvalAndValidate() error

EvalAndValidate makes sure config is valid and evaluates expressions for further use.

type Daemon

type Daemon struct {
	DataFetcher
	// contains filtered or unexported fields
}

Daemon is a component of fbclock that runs continuously, talks to ptp4l, does the math and populates shared memory for client library to read from.

func New

func New(cfg *Config, stats StatsServer, l Logger) (*Daemon, error)

New creates new fbclock-daemon

func (*Daemon) Run

func (s *Daemon) Run(ctx context.Context) error

Run a daemon

type DataFetcher

type DataFetcher interface {
	//function to gm data
	FetchGMs(cfg *Config) (targest []string, err error)
	//function to fetch stats
	FetchStats(cfg *Config) (*DataPoint, error)
}

DataFetcher is the data fetcher interface

type DataPoint

type DataPoint struct {
	// IngressTimeNS represents ingress time in NanoSeconds
	IngressTimeNS int64
	// MasterOffsetNS represents master offset in NanoSeconds
	MasterOffsetNS float64
	// PathDelayNS represents path delay in NanoSeconds
	PathDelayNS float64
	// FreqAdjustmentPPB represents freq adjustment in parts per billion
	FreqAdjustmentPPB float64
	// ClockAccuracyNS represents clock accurary in nanoseconds
	ClockAccuracyNS float64
}

DataPoint is what we store in DataPoint ring buffer

func (*DataPoint) SanityCheck

func (d *DataPoint) SanityCheck() error

SanityCheck checks datapoint for correctness

type DummyLogger

type DummyLogger struct {
	// contains filtered or unexported fields
}

DummyLogger logs M and W to given writer

func NewDummyLogger

func NewDummyLogger(w io.Writer, sampleRate int) *DummyLogger

NewDummyLogger returns new DummyLogger

func (*DummyLogger) Log

func (l *DummyLogger) Log(s *LogSample) error

Log implements Logger interface

type HTTPFetcher

type HTTPFetcher struct {
	DataFetcher
}

HTTPFetcher provides data fetcher implementation using http

func (*HTTPFetcher) FetchGMs

func (hf *HTTPFetcher) FetchGMs(cfg *Config) (targets []string, err error)

FetchGMs fetches GMs via http

func (*HTTPFetcher) FetchStats

func (hf *HTTPFetcher) FetchStats(cfg *Config) (*DataPoint, error)

FetchStats fetches GMs via http

type JSONStats

type JSONStats struct {
	Stats
}

JSONStats is what we want to report as stats via http

func NewJSONStats

func NewJSONStats() *JSONStats

NewJSONStats returns a new JSONStats

func (*JSONStats) Start

func (s *JSONStats) Start(monitoringport int)

Start runs http server and initializes maps

type LogSample

type LogSample struct {
	MasterOffsetNS          float64
	MasterOffsetMeanNS      float64
	MasterOffsetStddevNS    float64
	PathDelayNS             float64
	PathDelayMeanNS         float64
	PathDelayStddevNS       float64
	FreqAdjustmentPPB       float64
	FreqAdjustmentMeanPPB   float64
	FreqAdjustmentStddevPPB float64
	MeasurementNS           float64
	MeasurementMeanNS       float64
	MeasurementStddevNS     float64
	WindowNS                float64
	ClockAccuracyMean       float64
}

LogSample has all the measurements we may want to log

func (*LogSample) CSVRecords

func (s *LogSample) CSVRecords() []string

CSVRecords returns all data from this sample as CSV. Must by synced with `header` variable.

type Logger

type Logger interface {
	Log(*LogSample) error
}

Logger is something that can store LogSample somewhere

type Math

type Math struct {
	M string // Measurement, our value for clock quality

	W string // window of uncertainty, without adjustment for potential holdover

	Drift string // drift in PPB, for holdover multiplier calculations
	// contains filtered or unexported fields
}

Math stores our math expressions for M ans W values in two forms: string and parsed

func (*Math) Prepare

func (m *Math) Prepare() error

Prepare will prepare all math expressions

type SockFetcher

type SockFetcher struct {
	DataFetcher
}

SockFetcher provides data fetcher implementation using ptp4l Sock

func (*SockFetcher) FetchGMs

func (sf *SockFetcher) FetchGMs(cfg *Config) (targets []string, err error)

FetchGMs fetches gm data from ptp4l socket

func (*SockFetcher) FetchStats

func (sf *SockFetcher) FetchStats(cfg *Config) (*DataPoint, error)

FetchStats fetches stats from ptp4l socket

type Stats

type Stats struct {
	// contains filtered or unexported fields
}

Stats is an implementation of

func NewStats

func NewStats() *Stats

NewStats created new instance of Stats

func (*Stats) Copy

func (s *Stats) Copy(dst *Stats)

Copy all key-values between maps

func (*Stats) Get

func (s *Stats) Get() map[string]int64

Get returns an map of counters

func (*Stats) Reset

func (s *Stats) Reset()

Reset all the values of counters

func (*Stats) SetCounter

func (s *Stats) SetCounter(key string, val int64)

SetCounter will set a counter to the provided value.

func (*Stats) UpdateCounterBy

func (s *Stats) UpdateCounterBy(key string, count int64)

UpdateCounterBy will increment counter

type StatsServer

type StatsServer interface {
	// Reset atomically sets all the counters to 0
	Reset()
	SetCounter(key string, val int64)
	UpdateCounterBy(key string, count int64)
}

StatsServer is a stats server interface

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL