monitor

package
v3.2.10 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2021 License: LGPL-3.0 Imports: 16 Imported by: 11

Documentation

Overview

Package monitor package handle the logging, collection and computation of statistical data. Every application can send some Measure (for the moment, we mostly measure the CPU time but it can be applied later for any kind of measures). The Monitor receives them and updates a Stats struct. This Stats struct can hold many different kinds of Measurements (the measure of a specific action such as "round time" or "verify time" etc). These measurements contain Values which compute the actual min/max/dev/avg values.

The Proxy allows to relay Measure from clients to the listening Monitor. A starter feature is also the DataFilter which can apply some filtering rules to the data before making any statistics about them.

Index

Constants

View Source
const DefaultSinkPort = 10000

DefaultSinkPort is the default port where a monitor will listen and a proxy will contact the monitor.

View Source
const InvalidHostIndex = -1

InvalidHostIndex is the default value when the measure is not assigned to a specific host

View Source
const Sink = "0.0.0.0"

Sink is the address where to listen for the monitor. The endpoint can be a monitor.Proxy or a direct connection with measure.go

Variables

This section is empty.

Functions

func ConnectSink

func ConnectSink(addr string) error

ConnectSink connects to the given endpoint and initialises a json encoder. It can be the address of a proxy or a monitoring process. Returns an error if it could not connect to the endpoint.

func EndAndCleanup

func EndAndCleanup()

EndAndCleanup sends a message to end the logging and closes the connection

func RecordSingleMeasure

func RecordSingleMeasure(name string, value float64)

RecordSingleMeasure sends the pair name - value to the monitor directly.

func RecordSingleMeasureWithHost

func RecordSingleMeasureWithHost(name string, value float64, host int)

RecordSingleMeasureWithHost sends the pair name - value with the host index to the monitor directly.

Types

type BucketStats

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

BucketStats splits the statistics into buckets according to network addresses and associated rules

func (*BucketStats) Get

func (bs *BucketStats) Get(index int) *Stats

Get returns the bucket at the given index if it exists, nil otherwise

func (*BucketStats) Set

func (bs *BucketStats) Set(index int, rules []string, stats *Stats) error

Set creates a new bucket at the given index that uses the rules to filter incoming measures

func (*BucketStats) Update

func (bs *BucketStats) Update(m *singleMeasure)

Update takes a single measure and fill the buckets that will match the host index if defined in the measure

type CounterIO

type CounterIO interface {
	// Rx returns the number of bytes read by this interface.
	Rx() uint64
	// Tx returns the number of bytes transmitted / written by this interface.
	Tx() uint64
	// MsgRx returns the number of messages read by this interface.
	MsgRx() uint64
	// MsgTx returns the number of messages transmitted / written by this interface.
	MsgTx() uint64
}

CounterIO is an interface that can be used to count how many bytes does an object have written and how many bytes does it have read. For example it is implemented by cothority/network/ Conn + Host to know how many bytes a connection / Host has written /read.

type CounterIOMeasure

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

CounterIOMeasure is a struct that takes a CounterIO and can send the measurements to the monitor. Each time Record() is called, the measurements are put back to 0 (while the CounterIO still sends increased bytes number).

func NewCounterIOMeasure

func NewCounterIOMeasure(name string, counter CounterIO) *CounterIOMeasure

NewCounterIOMeasure returns a CounterIOMeasure fresh. The base value are set to the current value of counter.Rx() and counter.Tx().

func NewCounterIOMeasureWithHost

func NewCounterIOMeasureWithHost(name string, counter CounterIO, host int) *CounterIOMeasure

NewCounterIOMeasureWithHost returns a CounterIOMeasure bounded to a host index. The base value are set to the current value of counter.Rx() and counter.Tx().

func (*CounterIOMeasure) Record

func (cm *CounterIOMeasure) Record()

Record send the actual number of bytes read and written (**name**_written & **name**_read) and reset the counters.

func (*CounterIOMeasure) Reset

func (cm *CounterIOMeasure) Reset()

Reset sets the base to the current value of the counter.

type DataFilter

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

DataFilter is used to process data before making any statistics about them

func NewDataFilter

func NewDataFilter(config map[string]string) DataFilter

NewDataFilter returns a new data filter initialized with the rights values taken out from the run config. If absent, will take defaults values. Keys expected are: discard_measurementname = perc => will take the lower and upper percentile = perc discard_measurementname = lower,upper => will take different percentiles

func (*DataFilter) Filter

func (df *DataFilter) Filter(measure string, values []float64) []float64

Filter out a serie of values

type Measure

type Measure interface {
	// Record must be called when you want to send the value
	// over the monitor listening.
	// Implementation of this interface must RESET the value to `0` at the end
	// of Record(). `0` means the initial value / meaning this measure had when
	// created.
	// Example: TimeMeasure.Record() will reset the time to `time.Now()`
	//          CounterIOMeasure.Record() will  reset the counter of the bytes
	//          read / written to 0.
	//          etc
	Record()
}

Measure is an interface for measurements Usage:

measure := monitor.SingleMeasure("bandwidth")

or

measure := monitor.NewTimeMeasure("round")
measure.Record()

type Monitor

type Monitor struct {
	SinkPort uint16
	// contains filtered or unexported fields
}

Monitor struct is used to collect measures and make the statistics about them. It takes a stats object so it update that in a concurrent-safe manner for each new measure it receives.

func NewMonitor

func NewMonitor(stats *Stats) *Monitor

NewMonitor returns a new monitor given the stats

func (*Monitor) InsertBucket

func (m *Monitor) InsertBucket(index int, rules []string, stats *Stats)

InsertBucket creates a bucket at the given index that will use the rules to filter the incoming measures

func (*Monitor) Listen

func (m *Monitor) Listen() error

Listen will start listening for incoming connections on this address It needs the stats struct pointer to update when measures come Return an error if something went wrong during the connection setup

func (*Monitor) Stop

func (m *Monitor) Stop()

Stop will close every connections it has And will stop updating the stats

type Stats

type Stats struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Stats holds the different measurements done

func AverageStats

func AverageStats(stats []*Stats) *Stats

AverageStats will make an average of the given stats

func NewStats

func NewStats(rc map[string]string, defaults ...string) *Stats

NewStats return a NewStats with some fields extracted from the platform run config It enforces the default set of measure to have if you pass that as defaults.

func (*Stats) Collect

func (s *Stats) Collect()

Collect make the final computations before stringing or writing. Automatically done in other methods anyway.

func (*Stats) String

func (s *Stats) String() string

Returns an overview of the stats - not complete data returned!

func (*Stats) Update

func (s *Stats) Update(m *singleMeasure)

Update will update the Stats with this given measure

func (*Stats) Value

func (s *Stats) Value(name string) *Value

Value returns the value object corresponding to this name in this Stats

func (*Stats) WriteHeader

func (s *Stats) WriteHeader(w io.Writer)

WriteHeader will write the header to the writer

func (*Stats) WriteIndividualStats

func (s *Stats) WriteIndividualStats(w io.Writer) error

WriteIndividualStats will write the values to the specified writer but without making averages. Each value should either be:

  • represented once - then it'll be copied to all runs
  • have the same frequency as the other non-once values

func (*Stats) WriteValues

func (s *Stats) WriteValues(w io.Writer)

WriteValues will write the values to the specified writer

type TCPProxy

type TCPProxy struct {
	Listener        net.Listener
	Endpoints       []*net.SRV
	MonitorInterval time.Duration
	// contains filtered or unexported fields
}

A TCPProxy proxies connections arriving at the Listener to one of the Endpoints.

func NewProxy

func NewProxy(toPort uint16, addr string, listenPort uint16) (*TCPProxy, error)

NewProxy returns a new TCP proxy listening on addr:listenPort, which forwards connections to localhost:toPort.

func (*TCPProxy) Run

func (tp *TCPProxy) Run() error

Run starts servicing clients. It will not return until Stop is called.

func (*TCPProxy) Stop

func (tp *TCPProxy) Stop()

Stop stops a running TCPProxy. After calling Stop, Run will return.

type TimeMeasure

type TimeMeasure struct {
	Wall *singleMeasure
	CPU  *singleMeasure
	User *singleMeasure
	// contains filtered or unexported fields
}

TimeMeasure represents a measure regarding time: It includes the wallclock time, the cpu time + the user time.

func NewTimeMeasure

func NewTimeMeasure(name string) *TimeMeasure

NewTimeMeasure return *TimeMeasure

func NewTimeMeasureWithHost

func NewTimeMeasureWithHost(name string, host int) *TimeMeasure

NewTimeMeasureWithHost makes a time measure bounded to a host index.

func (*TimeMeasure) Record

func (tm *TimeMeasure) Record()

Record sends the measurements to the monitor:

- wall time: *name*_wall

- system time: *name*_system

- user time: *name*_user

type Value

type Value struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Value is used to compute the statistics it reprensent the time to an action (setup, shamir round, coll round etc) use it to compute streaming mean + dev

func AverageValue

func AverageValue(st ...*Value) *Value

AverageValue will create a Value averaging all Values given

func NewValue

func NewValue(name string) *Value

NewValue returns a new value object with this name

func (*Value) Avg

func (t *Value) Avg() float64

Avg returns the average (mean) of the Values

func (*Value) Collect

func (t *Value) Collect()

Collect will collect all float64 stored in the store's Value and will compute the basic statistics about them such as min, max, dev and avg.

func (*Value) Dev

func (t *Value) Dev() float64

Dev returns the standard deviation of the Values

func (*Value) Filter

func (t *Value) Filter(filt DataFilter)

Filter outs its Values

func (*Value) HeaderFields

func (t *Value) HeaderFields() []string

HeaderFields returns the first line of the CSV-file

func (*Value) Max

func (t *Value) Max() float64

Max returns the maximum of all stored float64

func (*Value) Min

func (t *Value) Min() float64

Min returns the minimum of all stored float64

func (*Value) NumValue

func (t *Value) NumValue() int

NumValue returns the number of Value added

func (*Value) SingleValues

func (t *Value) SingleValues(i int) []string

SingleValues returns the string representation of an entry in the value

func (*Value) Store

func (t *Value) Store(newTime float64)

Store takes this new time and stores it for later analysis Since we might want to do percentile sorting, we need to have all the Values For the moment, we do a simple store of the Value, but note that some streaming percentile algorithm exists in case the number of messages is growing to big.

func (*Value) Sum

func (t *Value) Sum() float64

Sum returns the sum of all stored float64

func (*Value) Values

func (t *Value) Values() []string

Values returns the string representation of a Value

Jump to

Keyboard shortcuts

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