senders

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2023 License: Apache-2.0 Imports: 15 Imported by: 42

Documentation

Overview

Example (Sender)
package main

import (
	"github.com/wavefronthq/wavefront-sdk-go/histogram"
	wavefront "github.com/wavefronthq/wavefront-sdk-go/senders"
)

func main() {
	sender, err := wavefront.NewSender("http://localhost")
	if err != nil {
		// handle error
	}

	// Wavefront metrics data format
	// <metricName> <metricValue> [<timestamp>] source=<source> [pointTags]
	// Example: "new-york.power.usage 42422 1533529977 source=localhost datacenter=dc1"
	err = sender.SendMetric("new-york.power.usage", 42422.0, 0, "go_test", map[string]string{"env": "test"})
	if err != nil {
		// handle err
	}

	// When you use a Sender SDK, you won’t see span-level RED metrics by default unless you use the Wavefront proxy and define a custom tracing port (TracingPort). See Instrument Your Application with Wavefront Sender SDKs for details.
	// Wavefront Tracing Span Data format
	// <tracingSpanName> source=<source> [pointTags] <start_millis> <duration_milliseconds>
	// Example:
	// "getAllUsers source=localhost traceId=7b3bf470-9456-11e8-9eb6-529269fb1459
	// spanId=0313bafe-9457-11e8-9eb6-529269fb1459 parent=2f64e538-9457-11e8-9eb6-529269fb1459
	// application=Wavefront http.method=GET 1552949776000 343"
	err = sender.SendSpan("getAllUsers", 1552949776000, 343, "localhost",
		"7b3bf470-9456-11e8-9eb6-529269fb1459",
		"0313bafe-9457-11e8-9eb6-529269fb1459",
		[]string{"2f64e538-9457-11e8-9eb6-529269fb1459"},
		nil,
		[]wavefront.SpanTag{
			{Key: "application", Value: "Wavefront"},
			{Key: "service", Value: "istio"},
			{Key: "http.method", Value: "GET"},
		},
		nil)
	if err != nil {
		// handle err
	}

	// Wavefront delta counter format
	// <metricName> <metricValue> source=<source> [pointTags]
	// Example: "lambda.thumbnail.generate 10 source=thumbnail_service image-format=jpeg"
	err = sender.SendDeltaCounter("lambda.thumbnail.generate", 10.0, "thumbnail_service", map[string]string{"format": "jpeg"})
	if err != nil {
		// handle err
	}

	// Wavefront Histogram data format
	// {!M | !H | !D} [<timestamp>] #<count> <mean> [centroids] <histogramName> source=<source> [pointTags]
	// Example: You can choose to send to at most 3 bins - Minute/Hour/Day
	// "!M 1533529977 #20 30.0 #10 5.1 request.latency source=appServer1 region=us-west"
	// "!H 1533529977 #20 30.0 #10 5.1 request.latency source=appServer1 region=us-west"
	// "!D 1533529977 #20 30.0 #10 5.1 request.latency source=appServer1 region=us-west"

	centroids := []histogram.Centroid{
		{
			Value: 30.0,
			Count: 20,
		},
		{
			Value: 5.1,
			Count: 10,
		},
	}

	hgs := map[histogram.Granularity]bool{
		histogram.MINUTE: true,
		histogram.HOUR:   true,
		histogram.DAY:    true,
	}

	err = sender.SendDistribution("request.latency", centroids, hgs, 0, "appServer1", map[string]string{"region": "us-west"})
	if err != nil {
		// handle err
	}

	if err := sender.Flush(); err != nil {
		// handle error
	}
	sender.Close()
}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DistributionSender

type DistributionSender interface {
	// SendDistribution sends a distribution of metrics to Wavefront with optional timestamp and tags.
	// Each centroid is a 2-dimensional entity with the first dimension the mean value
	// and the second dimension the count of points in the centroid.
	// The granularity informs the set of intervals (minute, hour, and/or day) by which the
	// histogram data should be aggregated.
	SendDistribution(name string, centroids []histogram.Centroid, hgs map[histogram.Granularity]bool, ts int64, source string, tags map[string]string) error
}

DistributionSender Interface for sending distributions to Wavefront

type EventSender

type EventSender interface {
	// SendEvent sends an event to Wavefront with optional tags
	SendEvent(name string, startMillis, endMillis int64, source string, tags map[string]string, setters ...event.Option) error
}

EventSender Interface for sending events to Wavefront. NOT yet supported.

type MetricSender

type MetricSender interface {
	// SendMetric sends a single metric to Wavefront with optional timestamp and tags.
	SendMetric(name string, value float64, ts int64, source string, tags map[string]string) error

	// SendDeltaCounter sends a delta counter (counter aggregated at the Wavefront service) to Wavefront.
	// the timestamp for a delta counter is assigned at the server side.
	SendDeltaCounter(name string, value float64, source string, tags map[string]string) error
}

MetricSender Interface for sending metrics to Wavefront

type MultiSender added in v0.9.8

type MultiSender interface {
	Sender
}

MultiSender Interface for sending metrics, distributions and spans to multiple Wavefront services at the same time

func NewMultiSender added in v0.9.8

func NewMultiSender(senders ...Sender) MultiSender

NewMultiSender creates a new Wavefront MultiClient

type Option added in v0.9.8

type Option func(*configuration)

Option Wavefront client configuration options

func BatchSize added in v0.9.8

func BatchSize(n int) Option

BatchSize set max batch of data sent per flush interval. Defaults to 10,000. recommended not to exceed 40,000.

func FlushInterval added in v0.13.0

func FlushInterval(interval time.Duration) Option

FlushInterval set the interval at which to flush data to Wavefront. Defaults to 1 Second.

func FlushIntervalSeconds added in v0.9.8

func FlushIntervalSeconds(n int) Option

FlushIntervalSeconds set the interval (in seconds) at which to flush data to Wavefront. Defaults to 1 Second.

func MaxBufferSize added in v0.9.8

func MaxBufferSize(n int) Option

MaxBufferSize set the size of internal buffers beyond which received data is dropped. Defaults to 50,000.

func MetricsPort added in v0.9.10

func MetricsPort(port int) Option

MetricsPort sets the port on which to report metrics. Default is 2878.

func SDKMetricsTags added in v0.9.10

func SDKMetricsTags(tags map[string]string) Option

SDKMetricsTags adds the additional tags provided in tags to all internal metrics this library reports. Clients can use multiple SDKMetricsTags calls when creating a sender. In that case, the sender sends all the tags from each of the SDKMetricsTags calls in addition to the standard "pid" and "version" tags to all internal metrics. The "pid" tag is the process ID; the "version" tag is the version of this SDK.

func TLSConfigOptions added in v0.12.0

func TLSConfigOptions(tlsCfg *tls.Config) Option

func Timeout added in v0.12.0

func Timeout(timeout time.Duration) Option

Timeout sets the HTTP timeout (in seconds). Defaults to 10 seconds.

func TracesPort added in v0.9.10

func TracesPort(port int) Option

TracesPort sets the port on which to report traces. Default is 30001.

type Sender

type Sender interface {
	MetricSender
	DistributionSender
	SpanSender
	EventSender
	internal.Flusher
	Close()
	// contains filtered or unexported methods
}

Sender Interface for sending metrics, distributions and spans to Wavefront

func NewSender added in v0.9.8

func NewSender(wfURL string, setters ...Option) (Sender, error)

NewSender creates Wavefront client

Example (Direct)
package main

import (
	wavefront "github.com/wavefronthq/wavefront-sdk-go/senders"
)

func main() {
	// For Direct Ingestion endpoints, by default all data is sent to port 80
	// or port 443 for unencrypted or encrypted connections, respectively.
	// 11111111-2222-3333-4444-555555555555 is your API token with direct ingestion permission.
	sender, err := wavefront.NewSender("https://11111111-2222-3333-4444-555555555555@surf.wavefront.com")
	if err != nil {
		// handle error
	}
	err = sender.Flush()
	if err != nil {
		// handle error
	}
	sender.Close()
}
Example (Options)
package main

import (
	"crypto/tls"
	wavefront "github.com/wavefronthq/wavefront-sdk-go/senders"
	"time"
)

func main() {
	// NewSender accepts optional arguments. Use these if you need to set non-default ports for your Wavefront Proxy, tune batching parameters, or set tags for internal SDK metrics.
	sender, err := wavefront.NewSender(
		"http://localhost",
		wavefront.BatchSize(20000),                // Send batches of 20,000.
		wavefront.FlushInterval(5*time.Second),    // Flush every 5 seconds.
		wavefront.MetricsPort(4321),               // Use port 4321 for metrics.
		wavefront.TracesPort(40001),               // Use port 40001 for traces.
		wavefront.Timeout(15),                     // Set an HTTP timeout in seconds (default is 10s)
		wavefront.TLSConfigOptions(&tls.Config{}), // Set TLS config options.
	)

	if err != nil {
		// handle error
	}
	sender.Close()
}
Example (Proxy)
package main

import (
	wavefront "github.com/wavefronthq/wavefront-sdk-go/senders"
)

func main() {
	// For Proxy endpoints, by default metrics and histograms are sent to
	// port 2878 and spans are sent to port 30001.
	sender, err := wavefront.NewSender("http://localhost")
	if err != nil {
		// handle error
	}

	err = sender.Flush()
	if err != nil {
		// handle error
	}
	sender.Close()
}

func NewWavefrontNoOpClient added in v0.9.9

func NewWavefrontNoOpClient() (Sender, error)

NewWavefrontNoOpClient returns a Wavefront Client instance for which all operations are no-ops.

type SpanLog

type SpanLog struct {
	Timestamp int64
	Fields    map[string]string
}

type SpanSender

type SpanSender interface {
	// SendSpan sends a tracing span to Wavefront.
	// traceId, spanId, parentIds and preceding spanIds are expected to be UUID strings.
	// parents and preceding spans can be empty for a root span.
	// span tag keys can be repeated (example: "user"="foo" and "user"="bar")
	// span logs are currently omitted
	SendSpan(name string, startMillis, durationMillis int64, source, traceId, spanId string, parents, followsFrom []string, tags []SpanTag, spanLogs []SpanLog) error
}

SpanSender Interface for sending tracing spans to Wavefront

type SpanTag

type SpanTag struct {
	Key   string
	Value string
}

Jump to

Keyboard shortcuts

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