pyrunner

package
v3.8.4+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2018 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package pyrunner holds the logic for managing Python plugins using a subprocess running Python.

Index

Constants

View Source
const (
	MessageTypeNone            MessageType = 0
	MessageTypeConfigure                   = 1
	MessageTypeConfigureResult             = 2
	MessageTypeShutdown                    = 3
	MessageTypeLog                         = 4
)

MessageTypes that are standard

Variables

This section is empty.

Functions

This section is empty.

Types

type LogMessage

type LogMessage struct {
	Message     string  `json:"message"`
	Level       string  `json:"level"`
	Logger      string  `json:"logger"`
	SourcePath  string  `json:"source_path"`
	LineNumber  int     `json:"lineno"`
	CreatedTime float64 `json:"created"`
}

LogMessage represents the log message that comes back from python

type MessageReceiver

type MessageReceiver interface {
	RecvMessage() (MessageType, io.Reader, error)
}

MessageReceiver can get messages from Python

type MessageType

type MessageType uint32

MessageType is the type of the message going to the python runner

type MonitorCore

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

MonitorCore is the adapter to the Python monitor runner process. It communiates with Python using named pipes. Each general type of Python plugin (e.g. Datadog, collectd, etc.) should get its own generic monitor struct that uses this adapter by embedding it.

This will run a single, dedicated Python subprocess that actually runs the Python monitoring code. Getting data/metrics/events out of the Python code is the responsibility of modules that embed this MonitorCore, hence there are no predefined "datapoint" message types.

func New

func New(pythonPkg string) *MonitorCore

New returns a new uninitialized monitor core

func (*MonitorCore) ConfigureInPython

func (mc *MonitorCore) ConfigureInPython(config config.MonitorCustomConfig, handler func(MessageReceiver)) error

ConfigureInPython sends the given config to the python subproc and returns whether configuration was successful. This method should only be called once for the lifetime of the monitor. The returned MessageReceiver can be used to get datapoints/events out of the Python process, the exact format of the data is left up to the users of this core.

func (*MonitorCore) HandleLogMessage

func (mc *MonitorCore) HandleLogMessage(logReader io.Reader) error

HandleLogMessage will decode a log message from the given logReader and log it using the provided logger.

func (*MonitorCore) Logger

func (mc *MonitorCore) Logger() log.FieldLogger

Logger returns the logger that should be used

func (*MonitorCore) Shutdown

func (mc *MonitorCore) Shutdown()

Shutdown the whole Runner child process, not just individual monitors

func (*MonitorCore) ShutdownCalled

func (mc *MonitorCore) ShutdownCalled() bool

ShutdownCalled returns true if the Shutdown method has been called.

Jump to

Keyboard shortcuts

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