monitoring

package
v0.9.21-alpha Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package monitoring contains code related to collecting and sending performance data of nodes to a locally hosted website at localhost:12345. It records certain event such as when a node connected to other nodes or completed its initial sync. I prefered writing my own lightweight monitoring that I fully understand over using sth like Grafana + Prometheus.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RandomShortSleep

func RandomShortSleep()

RandomShortSleep is used to sleep for a short amount (between 5 and 15 milliseconds). It is used to retry something networking-related after a short delay.

func SendPerformanceStat

func SendPerformanceStat(p PerformanceData) error

SendPerformanceStat is the function implicitely (you are supposed to call SendPerformanceStatWithRetries) to transmit their collected performance data to the server run at localhost:12345 Return nil when stat was successfully reported to the server and an acknowledgement of that was received. Otherwise returns an error message.

func SendPerformanceStatWithRetries

func SendPerformanceStatWithRetries(p PerformanceData) error

SendPerformanceStatWithRetries is the function used by nodes to report performance stats. Should it fail (e.g. packet gets lost or no ACK from stats server received), it will try again but only up to performanceStatReportingUpperCap times often. If no retries are available and error still is not nil, then an error message is returned.

func StartPerformanceStatsServer

func StartPerformanceStatsServer()

StartPerformanceStatsServer is used to start the server that displays performance data submitted by nodes in the browser.

Types

type Event

type Event int

Event is an int alias later used to created an enum that describes which kind of event occurred that the stats are reported for

const (
	Event_Libp2pNodeIDKnown          Event = iota + 71 // you know now your libp2p node ID (either it was read from file or new identity was created)
	Event_FirstPeerConnected                           // you have connected to your first peer (Note: If this peer is the RA the event RAConnected will not be reported again)
	Event_NewPeerConnected                             // you have connected to a new peer (but it is not your first one)
	Event_RAConnected                                  // you have connected to the RA
	Event_InitialSyncChaindbReceived                   // you have received all chaindb data and as next step will verify it (full nodes will build entire state after this to be able to verify it)
	Event_InitialSyncChaindbVerified                   // you have synced to other nodes but you do not know the current BPH or currently pending transactions. You will still need to request them
	Event_InitialSyncCompleted                         // you have completed your initial sync
	Event_SimtaskReceived                              // you have a new simtask (new block problem) from the RA
	Event_TransactionReceived                          // you have received a new transaction via topic
	Event_MinerCommitReceived                          // you have received a new miner commitment (a miner claims to have solved the current block problem and provides 'zero' knowledge proof)
	Event_RACommitRevealed                             // you have received RA secret bytes reveal (necessary for everyone to select winner)
	Event_BlockWinnerFound                             // you YOURSELF have determined who will be the next block winner (if everything works every node should always choose the same block winner)
	Event_NewBlockReceived                             // you have received a new block from the RA (light nodes also receive a full block but then only store its header)

	Event_RANewProblemSent         // RA only: you have successfully sent a new block problem to the respective topic
	Event_RANewBlockSent           // RA only: you have successfully created and sent a new block to the respective topic
	Event_RACommitRevealSent       // RA only: you have successfully sent your secret bytes reveal to the respective topic
	Event_RAReceivedSimulationData // RA only: a miner sent you their block problem solution
)

func (Event) String

func (e Event) String() string

String implements the string interface for Event so that the name of the enum element will be printed instead of its int value.

type PerformanceData

type PerformanceData struct {
	Time      string `json:"time"`   // Example: whatever is returned by time.Now().UnixNano() as string
	Sender    string `json:"sender"` // Example: this refer to the docker container name, e.g. "1f". Default value when flag -dockerAlias not set: "mynode"
	EventType string `json:"eventtype"`
	Message   string `json:"message"` // Example: You can put additional info here. I usually put the libp2p node ID of the node I just connected to, or a bogus value for the completed initial sync (field is not allowed to be empty)
}

PerformanceData holds relevant data of a measurement in string form. Useful as the JS code that will handle the received data only has to handle strings.

func NewPerformanceData

func NewPerformanceData(currentTime int64, senderNode string, eventType Event, message string) PerformanceData

NewPerformanceData is the constructor used for holding PerformanceData. It actually converts the given data to string and returns an instance of PerformanceData.

Jump to

Keyboard shortcuts

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