monitor

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package server provides a common server implementation that can connect with remote.Remote.

Package wire defines structs used in the wire format for the remote checker.

Index

Constants

View Source
const CurrentVersion = 1

CurrentVersion is the current wire and protocol version.

View Source
const HeaderStructSize = 8

HeaderStructSize size of header struct in bytes.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientHandler

type ClientHandler interface {
	// NewClient is called when a new client connects to the server. It returns
	// a handler that will be bound to the client.
	NewClient() (MessageHandler, error)
}

ClientHandler is used to interface with client that connect to the server.

type CommonServer

type CommonServer struct {
	Log *slog.Logger

	// Endpoint is the path to the socket that the server listens to.
	Endpoint string
	// contains filtered or unexported fields
}

CommonServer provides common functionality to connect and process messages from different clients. Implementors decide how clients and messages are handled, e.g. counting messages for testing.

func (*CommonServer) Close

func (s *CommonServer) Close()

Close stops listening and closes all connections.

func (*CommonServer) Init

func (s *CommonServer) Init(log *slog.Logger, path string, handler ClientHandler)

Init initializes the server. It must be called before it is used.

func (*CommonServer) Start

func (s *CommonServer) Start() error

Start creates the socket file and listens for new connections.

func (*CommonServer) WaitForNoClients

func (s *CommonServer) WaitForNoClients()

WaitForNoClients waits until the number of clients connected reaches 0.

type Header struct {
	// HeaderSize is the size of the header in bytes. The payload comes
	// immediately after the header. The length is needed to allow the header to
	// expand in the future without breaking remotes that do not yet understand
	// the new fields.
	HeaderSize uint16

	// MessageType describes the payload. It must be one of the pb.MessageType
	// values and determine how the payload is interpreted. This is more efficient
	// than using protobuf.Any because Any uses the full protobuf name to identify
	// the type.
	MessageType uint16

	// DroppedCount is the number of points that failed to be written and had to
	// be dropped. It wraps around after max(uint32).
	DroppedCount uint32
}

Header is used to describe the message being sent to the remote process.

0 --------- 16 ---------- 32 ----------- 64 -----------+
| HeaderSize | MessageType | DroppedCount | Payload... |
+---- 16 ----+---- 16 -----+----- 32 -----+------------+

+marshal

type MessageHandler

type MessageHandler interface {
	// Message processes a single message. raw contains the entire unparsed
	// message. hdr is the parser message header and payload is the unparsed
	// message data.
	Message(raw []byte, hdr Header, payload []byte) error

	// Version returns what wire version of the protocol is supported.
	Version() uint32

	// Close closes the handler.
	Close()
}

MessageHandler is used to process messages from a client.

Jump to

Keyboard shortcuts

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