ec2macossystemmonitor

package
v0.0.0-...-9a85ff4 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultLogInterval = 10

defaultLogInterval is the number of writes before emitting a log entry 10 = once every 10 minutes

View Source
const DefaultRelaydSocketPath = "/tmp/.ec2monitoring.sock"

DefaultRelaydSocketPath is the default socket for relayd listener.

View Source
const SocketTimeout = 5 * time.Second

Variables

This section is empty.

Functions

func BuildMessage

func BuildMessage(tag string, data string, compress bool) ([]byte, error)

BuildMessage takes a tag along with data for the tag and builds a byte slice to be sent to the relay.

The tag is used as a way to namespace various payloads that are supported. Data is the payload and its format is specific to each tag. Each payload has the option to be compressed and this flag is part of the envelope created for sending data. The slice of bytes is passed back to the caller to allow flexibility to log the bytes if desired before passing to the relay via PassToRelayd

func CheckSocketExists

func CheckSocketExists(socketPath string) (exists bool)

CheckSocketExists is a helper function to quickly check if the service UDS exists.

func PassToRelayd

func PassToRelayd(messageBytes []byte) (n int, err error)

PassToRelayd takes a byte slice and writes it to a UNIX socket to send for relaying.

func RunningCpuUsage

func RunningCpuUsage() (s string, err error)

RunningCpuUsage gathers the value expected for CloudWatch but allows long running measurement. This is intended for usage where repeated calls will take place.

func SendMessage

func SendMessage(tag string, data string, compress bool) (n int, err error)

SendMessage takes a tag along with data for the tag and writes to a UNIX socket to send for relaying. This is provided for convenience to allow quick sending of data to the relay. It calls BuildMessage and then PassToRelayd in order.

Types

type IntervalLogger

type IntervalLogger struct {
	LogInterval int
	Counter     int
	Message     string
	// contains filtered or unexported fields
}

IntervalLogger is a special logger that provides a way to only log at a certain interval.

func (*IntervalLogger) PushToInterval

func (t *IntervalLogger) PushToInterval(i int, message string) (flushed bool)

PushToInterval adds to the counter and sets the Message, care should be taken to retrieve the Message before setting since its overwritten

type Logger

type Logger struct {
	LogToStdout    bool
	LogToSystemLog bool
	Tag            string
	SystemLog      *syslog.Writer
}

Logger contains booleans for where to log, a tag used in syslog and the syslog Writer itself.

func NewLogger

func NewLogger(tag string, systemLog bool, stdout bool) (logger *Logger, err error)

NewLogger creates a new logger. Logger writes using the LOG_LOCAL0 facility by default if system logging is enabled.

func (*Logger) Error

func (l *Logger) Error(v ...interface{})

Error writes an error to stdout and/or the system log.

func (*Logger) Errorf

func (l *Logger) Errorf(format string, v ...interface{})

Errorf writes a formatted error to stdout and/or the system log.

func (*Logger) Fatal

func (l *Logger) Fatal(v ...interface{})

Fatal writes an error to stdout and/or the system log then exits 1.

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, v ...interface{})

Fatalf writes a formatted error to stdout and/or the system log then exits 1.

func (*Logger) Info

func (l *Logger) Info(v ...interface{})

Info writes info to stdout and/or the system log.

func (*Logger) Infof

func (l *Logger) Infof(format string, v ...interface{})

Infof writes formatted info to stdout and/or the system log.

func (*Logger) Warn

func (l *Logger) Warn(v ...interface{})

Warn writes a warning to stdout and/or the system log.

func (*Logger) Warnf

func (l *Logger) Warnf(format string, v ...interface{})

Warnf writes a formatted warning to stdout and/or the system log.

type SerialConnection

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

SerialConnection is the container for passing the ReadWriteCloser for serial connections.

func NewSerialConnection

func NewSerialConnection(device string) (conn *SerialConnection, err error)

NewSerialConnection creates a serial device connection and returns a reference to the connection.

func (*SerialConnection) Close

func (s *SerialConnection) Close() (err error)

Close is simply a pass through to close the device so it remains open in the scope needed.

func (*SerialConnection) RelayData

func (s *SerialConnection) RelayData(sock net.Conn) (n int, err error)

RelayData is the primary function for reading data from the socket provided and writing to the serial connection.

type SerialMessage

type SerialMessage struct {
	// Checksum is the checksum used to ensure all data was received
	Checksum uint32 `json:"csum"`
	// Payload is the SerialPayload in json format
	Payload string `json:"payload"`
}

SerialMessage is the container to actually send on the serial connection, contains checksum of SerialPayload to provide additional assurance the entire payload has been written.

type SerialPayload

type SerialPayload struct {
	// Tag is the namespace that separates different types of data on the device
	Tag string `json:"tag"`
	// Compress determines if the data is compressed and base64 encoded
	Compress bool `json:"compress"`
	// Data is the actual data payload to be consumed
	Data string `json:"data"`
}

SerialPayload is the container for a payload that is written to serial device.

type SerialRelay

type SerialRelay struct {

	// ReadyToClose is the channel for communicating the need to close
	// connections.
	//
	// TODO: use context as replacement for cancellation
	ReadyToClose chan bool
	// contains filtered or unexported fields
}

SerialRelay manages client & listener to relay recieved messages to a serial connection.

func NewRelay

func NewRelay(serialDevice string) (relay SerialRelay, err error)

NewRelay creates an instance of the relay server and returns a SerialRelay for manual closing.

The SerialRelay returned from NewRelay is designed to be used in a go routine by using StartRelay. This allows the caller to handle OS Signals and other events for clean shutdown rather than relying upon defer calls.

func (*SerialRelay) CleanUp

func (relay *SerialRelay) CleanUp()

CleanUp manually closes the connections for a Serial Relay. This is called from StartRelay when true is sent on ReadyToClose so it should only be called separately if closing outside of that mechanism.

func (*SerialRelay) StartRelay

func (relay *SerialRelay) StartRelay(logger *Logger, relayStatus *StatusLogBuffer)

StartRelay starts the listener ahdn handles connections for the serial relay.

This is a server implementation of the SerialRelay so it logs to a provided logger, and empty logger can be provided to stop logging if desired. This function is designed to be used in a go routine so logging may be the only way to get data about behavior while it is running. The resources can be shut down by sending true to the ReadyToClose channel. This invokes CleanUp() which is exported in case the caller desires to call it instead.

type StatusLogBuffer

type StatusLogBuffer struct {
	Message string
	Written int64
}

StatusLogBuffer contains a message format string and a written bytes for this format string for flushing the logs

Jump to

Keyboard shortcuts

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