Documentation ¶
Index ¶
- Constants
- func BuildMessage(tag string, data string, compress bool) ([]byte, error)
- func CheckSocketExists(socketPath string) (exists bool)
- func PassToRelayd(messageBytes []byte) (n int, err error)
- func RunningCpuUsage() (s string, err error)
- func SendMessage(tag string, data string, compress bool) (n int, err error)
- type IntervalLogger
- type Logger
- func (l *Logger) Error(v ...interface{})
- func (l *Logger) Errorf(format string, v ...interface{})
- func (l *Logger) Fatal(v ...interface{})
- func (l *Logger) Fatalf(format string, v ...interface{})
- func (l *Logger) Info(v ...interface{})
- func (l *Logger) Infof(format string, v ...interface{})
- func (l *Logger) Warn(v ...interface{})
- func (l *Logger) Warnf(format string, v ...interface{})
- type SerialConnection
- type SerialMessage
- type SerialPayload
- type SerialRelay
- type StatusLogBuffer
Constants ¶
const DefaultLogInterval = 10
defaultLogInterval is the number of writes before emitting a log entry 10 = once every 10 minutes
const DefaultRelaydSocketPath = "/tmp/.ec2monitoring.sock"
DefaultRelaydSocketPath is the default socket for relayd listener.
const SocketTimeout = 5 * time.Second
Variables ¶
This section is empty.
Functions ¶
func BuildMessage ¶
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 ¶
CheckSocketExists is a helper function to quickly check if the service UDS exists.
func PassToRelayd ¶
PassToRelayd takes a byte slice and writes it to a UNIX socket to send for relaying.
func RunningCpuUsage ¶
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 ¶
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 ¶
Logger contains booleans for where to log, a tag used in syslog and the syslog Writer itself.
func NewLogger ¶
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) Fatal ¶
func (l *Logger) Fatal(v ...interface{})
Fatal writes an error to stdout and/or the system log then exits 1.
func (*Logger) Fatalf ¶
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.
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.
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 ¶
StatusLogBuffer contains a message format string and a written bytes for this format string for flushing the logs