Utilities for using collectd together with Golang.
Utilities for using collectd together with Go.
package mainimport ( "context" "time"
"collectd.org/api" "collectd.org/exec"
)
func main() { vl := api.ValueList{ Identifier: api.Identifier{ Host: exec.Hostname(), Plugin: "golang", Type: "gauge", }, Time: time.Now(), Interval: exec.Interval(), Values: []api.Value{api.Gauge(42)}, } exec.Putval.Write(context.Background(), &vl) }
This is a very simple package and very much a Work in Progress, so expect things to move around and be renamed a lot.
The repository is organized as follows:
collectd.org/apideclares data structures you may already know from the collectd source code itself, such as
ValueList.
collectd.org/execdeclares some utilities for writing binaries to be executed with the exec plugin. It provides some utilities (getting the hostname, e.g.) and an executor which you may use to easily schedule function calls.
collectd.org/formatdeclares functions for formatting ValueLists in other format. Right now, only
PUTVALis implemented. Eventually I plan to add parsers for some formats, such as the JSON export.
collectd.org/networkimplements collectd's binary network protocol. It offers client and server implementations, see
network.Clientand
network.ListenAndWrite()for more details.
To use this package in your own programs, simply use
go getto fetch the packages you need, for example:
go get collectd.org/api
Florian "octo" Forster <ff at octo.it>