Documentation ¶
Overview ¶
Example ¶
Example is an example of a receiver and sender
package main import ( "context" "fmt" "log" "time" "github.com/zeebo/admission/admproto" "github.com/zeebo/errs" "golang.org/x/sync/errgroup" monkit "gopkg.in/spacemonkeygo/monkit.v2" "storj.io/storj/pkg/telemetry" ) func main() { ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() var group errgroup.Group receiver, err := telemetry.Listen("127.0.0.1:0") if err != nil { log.Fatal(err) } // receiver group.Go(func() (err error) { defer func() { err = errs.Combine(err, receiver.Close()) }() err = receiver.Serve(ctx, telemetry.HandlerFunc( func(application, instance string, key []byte, val float64) { fmt.Printf("receive %s %s %s %v\n", application, instance, string(key), val) }, )) if err == context.Canceled { err = nil } return err }) // sender group.Go(func() error { client, err := telemetry.NewClient(receiver.Addr(), telemetry.ClientOpts{ Interval: time.Second, Application: "example", Instance: telemetry.DefaultInstanceID(), Registry: monkit.Default, FloatEncoding: admproto.Float32Encoding, }) if err != nil { return err } client.Run(ctx) return nil }) if err := group.Wait(); err != nil { fmt.Println(err) } }
Output:
Index ¶
Examples ¶
Constants ¶
View Source
const ( // DefaultInterval is the default amount of time between metric payload sends DefaultInterval = time.Minute // DefaultPacketSize sets the target packet size. MTUs are often 1500, // though a good argument could be made for 512 DefaultPacketSize = 1000 // DefaultApplication is the default values for application name. Should be used // when value in ClientOpts.Application is not set and len(os.Args) == 0 DefaultApplication = "unknown" )
Variables ¶
View Source
var Error = errs.Class("telemetry error")
Error is the default telemetry errs class
Functions ¶
func DefaultInstanceID ¶
func DefaultInstanceID() string
DefaultInstanceID will return the first non-nil mac address if possible, unknown otherwise.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a telemetry client for sending UDP packets at a regular interval from a monkit.Registry
func NewClient ¶
func NewClient(remoteAddr string, opts ClientOpts) (rv *Client, err error)
NewClient constructs a telemetry client that sends packets to remoteAddr over UDP.
type ClientOpts ¶
type ClientOpts struct { // Interval is how frequently stats from the provided Registry will be // sent up. Note that this interval is "jittered", so the actual interval // is taken from a normal distribution with a mean of Interval and a // variance of Interval/4. Defaults to DefaultInterval Interval time.Duration // Application is the application name, usually prepended to metric names. // By default it will be os.Args[0] Application string // Instance is a string that identifies this particular server. Could be a // node id, but defaults to the result of DefaultInstanceId() Instance string // PacketSize controls how we fragment the data as it goes out in UDP // packets. Defaults to DefaultPacketSize PacketSize int // Registry is where to get stats from. Defaults to monkit.Default Registry *monkit.Registry // FloatEncoding is how floats should be encoded on the wire. // Default is float16. FloatEncoding admproto.FloatEncoding }
ClientOpts allows you to set Client Options
type HandlerFunc ¶
HandlerFunc turns a func into a Handler
Click to show internal directories.
Click to hide internal directories.