py

package
v0.0.0-...-f3e8d88 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2017 License: Apache-2.0 Imports: 24 Imported by: 0

README

package py

This package provides all the concrete types needed to load and run python checks.

In particular, it provides:

  • implementations of the Check and Loader interfaces defined in the check package, for python checks
  • the bindings that python checks can use to fetch information from and submit data to the core agent

Before making modifications to the bindings, please make sure you understand the basics of the Python C API usage. Also, make sure you have a good understanding of the necessity and usage of the stickyLock struct (see inline documentation).

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// PythonVersion contains the interpreter version string provided by
	// `sys.version`. It's empty if the interpreter was not initialized.
	PythonVersion = ""

	// PythonHome contains the computed value of the Python Home path once the
	// intepreter is created. It might be empty in case the interpreter wasn't
	// initialized, or the Agent was built using system libs and the env var
	// PYTHONHOME is empty. It's expected to always contain a value when the
	// Agent is built using embedded libs.
	PythonHome = ""
	// PythonPath contains the string representation of the Python list returned
	// by `sys.path`. It's empty if the interpreter was not initialized.
	PythonPath = ""
)

Functions

func GetConfig

func GetConfig(key *C.char) *C.PyObject

GetConfig returns a value from the agent configuration.

func GetHostname

func GetHostname(self *C.PyObject, args *C.PyObject) *C.PyObject

GetHostname expose the current hostname of the agent to python check (used as a PyCFunction in the datadog_agent python module)

func GetVersion

func GetVersion(self *C.PyObject, args *C.PyObject) *C.PyObject

GetVersion expose the version of the agent to python check (used as a PyCFunction in the datadog_agent python module)

func Headers

func Headers(self *C.PyObject, args *C.PyObject) *C.PyObject

Headers return HTTP headers with basic information like UserAgent already set (used as a PyCFunction in the datadog_agent python module)

func Initialize

func Initialize(paths ...string) *python.PyThreadState

Initialize wraps all the operations needed to start the Python interpreter and configure the environment. This function should be called at most once in the Agent lifetime.

func LogMessage

func LogMessage(message *C.char, logLevel C.int) *C.PyObject

LogMessage logs a message from python through the agent logger (see https://docs.python.org/2.7/library/logging.html#logging-levels)

func SubmitEvent

func SubmitEvent(check *C.PyObject, checkID *C.char, event *C.PyObject) *C.PyObject

SubmitEvent is the method exposed to Python scripts to submit events

func SubmitMetric

func SubmitMetric(check *C.PyObject, checkID *C.char, mt C.MetricType, name *C.char, value C.float, tags *C.PyObject, hostname *C.char) *C.PyObject

SubmitMetric is the method exposed to Python scripts to submit metrics

func SubmitServiceCheck

func SubmitServiceCheck(check *C.PyObject, checkID *C.char, name *C.char, status C.int, tags *C.PyObject, hostname *C.char, message *C.char) *C.PyObject

SubmitServiceCheck is the method exposed to Python scripts to submit service checks

func ToPython

func ToPython(obj interface{}) (*python.PyObject, error)

ToPython converts a go object into a Python object

Types

type PythonCheck

type PythonCheck struct {
	ModuleName string
	// contains filtered or unexported fields
}

PythonCheck represents a Python check, implements `Check` interface

func NewPythonCheck

func NewPythonCheck(name string, class *python.PyObject) *PythonCheck

NewPythonCheck conveniently creates a PythonCheck instance

func (*PythonCheck) Configure

func (c *PythonCheck) Configure(data check.ConfigData, initConfig check.ConfigData) error

Configure the Python check from YAML data

func (*PythonCheck) GetMetricStats

func (c *PythonCheck) GetMetricStats() (map[string]int64, error)

GetMetricStats returns the stats from the last run of the check

func (*PythonCheck) GetWarnings

func (c *PythonCheck) GetWarnings() []error

GetWarnings grabs the last warnings from the struct

func (*PythonCheck) ID

func (c *PythonCheck) ID() check.ID

ID returns the ID of the check

func (*PythonCheck) Interval

func (c *PythonCheck) Interval() time.Duration

Interval returns the scheduling time for the check

func (*PythonCheck) Run

func (c *PythonCheck) Run() error

Run a Python check

func (*PythonCheck) Stop

func (c *PythonCheck) Stop()

Stop does nothing

func (*PythonCheck) String

func (c *PythonCheck) String() string

String representation (for debug and logging)

type PythonCheckLoader

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

PythonCheckLoader is a specific loader for checks living in Python modules

func NewPythonCheckLoader

func NewPythonCheckLoader() (*PythonCheckLoader, error)

NewPythonCheckLoader creates an instance of the Python checks loader

func (*PythonCheckLoader) Load

func (cl *PythonCheckLoader) Load(config check.Config) ([]check.Check, error)

Load tries to import a Python module with the same name found in config.Name, searches for subclasses of the AgentCheck class and returns the corresponding Check

func (*PythonCheckLoader) String

func (cl *PythonCheckLoader) String() string

Jump to

Keyboard shortcuts

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