Пример #1
0
// StatsdSetup sets up the connection to dogstatsd.
func StatsdSetup() *godspeed.Godspeed {
	statsd, err := godspeed.NewDefault()
	if err != nil {
		Log("StatsdSetup(): Problem setting up connection.", "info")
		return nil
	}
	return statsd
}
Пример #2
0
func (t *TestSuite) SetUpTest(c *C) {
	gs, err := godspeed.NewDefault()
	c.Assert(err, IsNil)
	t.g = gs

	t.l, t.c, t.o = gspdtest.BuildListener(8125)
	go gspdtest.Listener(t.l, t.c, t.o)
}
Пример #3
0
func (t *TestSuite) TestNewDefault(c *C) {
	var g *godspeed.Godspeed
	g, err := godspeed.NewDefault()
	c.Assert(err, IsNil)

	defer g.Conn.Close()

	testBasicFunc(t, c, g)
}
Пример #4
0
// StatsdDuplicate sends Dogstatsd metrics whenever there's a duplicate watch.
func StatsdDuplicate(watchType string, watchID string) {
	if DogStatsd {
		statsd, _ := godspeed.NewDefault()
		defer statsd.Conn.Close()
		tags := makeTags(watchType, watchID, "", "")
		metricName := fmt.Sprintf("%s.duplicate", MetricPrefix)
		statsd.Incr(metricName, tags)
	}
	Log(fmt.Sprintf("dogstatsd='%t' %s='%s' action='duplicate'", DogStatsd, watchType, watchID), "debug")
}
Пример #5
0
// StatsdBlank sends Dogstatsd metrics whenever there's a blank watch.
func StatsdBlank(watchType string) {
	if DogStatsd {
		statsd, _ := godspeed.NewDefault()
		defer statsd.Conn.Close()
		tags := makeTags(watchType, "", "", "")
		metricName := fmt.Sprintf("%s.blank", MetricPrefix)
		statsd.Incr(metricName, tags)
	}
	Log(fmt.Sprintf("dogstatsd='%t' watchType='%s' action='blank'", DogStatsd, watchType), "debug")
}
Пример #6
0
func ExampleNewDefault() {
	g, err := godspeed.NewDefault()

	if err != nil {
		// handle error
	}

	defer g.Conn.Close()

	g.Gauge("example.stat", 1, nil)
}
Пример #7
0
func ExampleGodspeed_Incr() {
	g, _ := godspeed.NewDefault()

	defer g.Conn.Close()

	err := g.Incr("example.counter", nil)

	if err != nil {
		// handle error
	}
}
Пример #8
0
func ExampleGodspeed_SetNamespace() {
	g, _ := godspeed.NewDefault()

	defer g.Conn.Close()

	namespace := "example"

	g.SetNamespace(namespace)

	fmt.Println(g.Namespace)
	// Output: example
}
Пример #9
0
func ExampleGodspeed_AddTags() {
	g, _ := godspeed.NewDefault()

	defer g.Conn.Close()

	newTags := []string{"production", "example"}

	tags := g.AddTags(newTags)

	fmt.Println(tags)
	// Output: [production example]
}
Пример #10
0
// StatsdRunTime sends timing metrics via Dogstatsd.
func StatsdRunTime(start time.Time, exec string, watchType string, watchID string, id string) {
	elapsed := time.Since(start)
	if DogStatsd {
		milliseconds := int64(elapsed / time.Millisecond)
		statsd, _ := godspeed.NewDefault()
		defer statsd.Conn.Close()
		tags := makeTags(watchType, watchID, exec, id)
		metricName := fmt.Sprintf("%s.time", MetricPrefix)
		statsd.Gauge(metricName, float64(milliseconds), tags)
	}
	Log(fmt.Sprintf("dogstatsd='%t' %s='%s' exec='%s' id='%s' elapsed='%s'", DogStatsd, watchType, watchID, exec, id, elapsed), "debug")
}
Пример #11
0
func ExampleGodspeed_AddTag() {
	// be sure to handle the error
	g, _ := godspeed.NewDefault()

	defer g.Conn.Close()

	g.AddTag("example1")

	tags := g.AddTag("example2")

	fmt.Println(tags)
	// Output: [example1 example2]
}
Пример #12
0
func ExampleGodspeed_Gauge() {
	g, err := godspeed.NewDefault()

	if err != nil {
		// handle error
	}

	defer g.Conn.Close()

	err = g.Gauge("example.gauge", 1, nil)

	if err != nil {
		// handle error
	}
}
Пример #13
0
func ExampleGodspeed_Count() {
	g, err := godspeed.NewDefault()

	if err != nil {
		// handle error
	}

	defer g.Conn.Close()

	err = g.Count("example.count", 1, nil)

	if err != nil {
		// handle error
	}
}
Пример #14
0
func ExampleGodspeed_Send() {
	g, err := godspeed.NewDefault()

	if err != nil {
		// handle error
	}

	defer g.Conn.Close()

	tags := []string{"example"}

	err = g.Send("example.stat", "g", 1, 1, tags)

	if err != nil {
		// handle error
	}
}
Пример #15
0
func (e *Datadog) getGodspeed() {
	var gs *godspeed.Godspeed
	var err error
	// if config options not set, use defaults
	if e.Config.Host == "" || e.Config.Port == "" {
		gs, err = godspeed.NewDefault()
	} else {
		port, err := strconv.Atoi(e.Config.Port)
		if err != nil {
			log.Error(err.Error())
		}
		gs, err = godspeed.New(e.Config.Host, port, false)
	}
	if err != nil {
		log.Error(err.Error())
	}
	e._godspeed = gs
}
Пример #16
0
func ExampleGodspeed_Event() {
	// make sure to handle the error
	g, _ := godspeed.NewDefault()

	defer g.Conn.Close()

	title := "Nginx service restart"
	text := "The Nginx service has been restarted"

	// the optionals are for the optional arguments available for an event
	// http://docs.datadoghq.com/guides/dogstatsd/#fields
	optionals := make(map[string]string)
	optionals["alert_type"] = "info"
	optionals["source_type_name"] = "nginx"

	addlTags := []string{"source_type:nginx"}

	err := g.Event(title, text, optionals, addlTags)

	if err != nil {
		fmt.Println("err:", err)
	}
}
func ExampleGodspeed_ServiceCheck() {
	// check the error
	g, _ := godspeed.NewDefault()

	defer g.Conn.Close()

	service := "Nagios Service"
	status := 0 // OK

	// if you don't want these, pass nil to the function instead
	optionals := make(map[string]string)
	optionals["service_check_message"] = "down"
	optionals["timestamp"] = "1431484263"

	// if you don't want these, pass nil to the function instead
	tags := []string{"some:tag"}

	err := g.ServiceCheck(service, status, optionals, tags)

	if err != nil {
		fmt.Fprintf(os.Stderr, err.Error())
	}
}
Пример #18
0
func Example() {
	// this uses the default host and port (127.0.0.1:8125)
	g, err := godspeed.NewDefault()

	if err != nil {
		// handle error
	}

	// defer closing the connection
	defer g.Conn.Close()

	g.AddTags([]string{"example", "example2"})

	err = g.Incr("example.run_count", nil)

	// all emission method calls should return an error object
	// you should probably check it
	if err != nil {
		// handle error
	}

	// this returns an error object too, just omitting for brevity
	g.Gauge("example.gauge", 42, nil)
}