datadog

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2018 License: Apache-2.0 Imports: 7 Imported by: 0

README

Datadog Metrics

This is a go-os/metrics plugin for datadog. It pushes tagged statsd style metrics to datadog.

For middleware examples see andrew-jones/go-micro-middleware.

Note: Counters and gauges are untested as my middleware only creates histograms at this stage.

Usage

func main() {
	// Create datadog metrics collector
	m := datadog.NewMetrics(
		metrics.Namespace("micro"),
		metrics.WithFields(metrics.Fields{
			"service": "greeter",
		}),
		metrics.Collectors("dd-agent:8125"),
	)
	defer m.Close()

	// Create broker
	b := rabbitmq.NewBroker(
		broker.Addrs("amqp://guest:guest@rabbit:5672"),
	)
	if err := b.Init(); err != nil {
		log.Fatalf("Unexpected init error: %v", err)
	}
	if err := b.Connect(); err != nil {
		log.Fatalf("Unexpected connect error: %v", err)
	}
	// Wrap the broker in logging and metric middleware
	b = middleware.LogBrokerWrapper(
		middleware.MetricBrokerWrapper(b, m, time.Millisecond),
	)
    // Subscribe to broker, setting up a durable queue with auto ack disabled
    // eventsubscriber is a package implementing broker.Handler
    _, err := b.Subscribe(
		"routing.key",
		eventsubscriber.NewBrokerHandler(subscriber.NewSubscriber("greeter")),
		broker.Queue("greeter"),
		broker.DisableAutoAck(),
		rabbitmq.DurableQueue(),
	)
	if err != nil {
		log.Fatalf("Could not subscribe handler to broker: %v", err)
	}

	// Create service
	service := micro.NewService(
		micro.Name("greeter"),
		micro.Broker(b),
		micro.Server(
			server.NewServer(
				server.Name("greeter"),
				server.WrapHandler(middleware.MetricHandlerWrapper(m, time.Millisecond)),
			),
		),
	)
	// setup command line usage
	service.Init()
	// Run server
	if err := service.Run(); err != nil {
		log.Fatal(err)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMetrics

func NewMetrics(opts ...metrics.Option) metrics.Metrics

Types

This section is empty.

Jump to

Keyboard shortcuts

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