Documentation
¶
Overview ¶
Package exec implements tools to write plugins for collectd's "exec plugin" in Go.
Example ¶
e := NewExecutor() // simple "value" callback answer := func() api.Value { return api.Gauge(42) } e.ValueCallback(answer, &api.ValueList{ Identifier: api.Identifier{ Host: "example.com", Plugin: "golang", Type: "answer", TypeInstance: "live_universe_and_everything", }, Interval: time.Second, }) // "complex" void callback bicycles := func(ctx context.Context, interval time.Duration) { vl := &api.ValueList{ Identifier: api.Identifier{ Host: "example.com", Plugin: "golang", Type: "bicycles", }, Interval: interval, Time: time.Now(), Values: make([]api.Value, 1), } data := []struct { TypeInstance string Value api.Gauge }{ {"beijing", api.Gauge(9000000)}, } for _, d := range data { vl.Values[0] = d.Value vl.Identifier.TypeInstance = d.TypeInstance Putval.Write(ctx, vl) } } e.VoidCallback(bicycles, time.Second) // blocks forever e.Run(context.Background())
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
Putval is the dispatcher used by the exec package to print ValueLists.
Functions ¶
Types ¶
type Executor ¶
type Executor struct {
// contains filtered or unexported fields
}
Executor holds one or more callbacks which are called periodically.
func NewExecutor ¶
func NewExecutor() *Executor
NewExecutor returns a pointer to a new Executor object.
func (*Executor) Stop ¶
func (e *Executor) Stop()
Stop sends a signal to all callbacks to exit and returns. This unblocks "Run()" but does not block itself.
func (*Executor) ValueCallback ¶
ValueCallback adds a simple "value" callback to the Executor. The callback only returns a Number, i.e. either a api.Gauge or api.Derive, and formatting and printing is done by the executor.
func (*Executor) VoidCallback ¶
func (e *Executor) VoidCallback(callback func(context.Context, time.Duration), interval time.Duration)
VoidCallback adds a "complex" callback to the Executor. While the functions prototype is simpler, all the work has to be done by the callback, i.e. the callback needs to format and print the appropriate lines to "STDOUT". However, this allows cases in which the number of values reported varies, e.g. depending on the system the code is running on.