func ExamplePublisher_Publish() {
	url, _ := sampler.NewJsonURL("http://www.canary.io")
	target := sampler.Target{
		URL: *url,
	}

	t1, _ := time.Parse(time.RFC3339, "2014-12-28T00:00:00Z")
	t2, _ := time.Parse(time.RFC3339, "2014-12-28T00:00:01Z")

	sample := sampler.Sample{
		TimeStart:  t1,
		TimeEnd:    t2,
		StatusCode: 200,
	}

	p := New()
	p.Publish(sensor.Measurement{
		Target:     target,
		Sample:     sample,
		IsOK:       true,
		StateCount: 2,
	})
	// Output:
	// 2014-12-28T00:00:01Z http://www.canary.io 200 1000.000000 true 2
}
Example #2
0
// builds the app configuration via ENV
func getConfig() (c canary.Config, url sampler.JsonURL, err error) {
	flag.Usage = usage
	flag.Parse()

	sampleIntervalString := os.Getenv("SAMPLE_INTERVAL")
	sampleInterval := 1
	if sampleIntervalString != "" {
		sampleInterval, err = strconv.Atoi(sampleIntervalString)
		if err != nil {
			err = fmt.Errorf("SAMPLE_INTERVAL is not a valid integer")
		}
	}
	c.DefaultSampleInterval = sampleInterval

	timeout := 0
	defaultTimeout := os.Getenv("DEFAULT_MAX_TIMEOUT")
	if defaultTimeout == "" {
		timeout = 10
	} else {
		timeout, err = strconv.Atoi(defaultTimeout)
		if err != nil {
			err = fmt.Errorf("DEFAULT_MAX_TIMOEUT is not a valid integer")
		}
	}
	c.MaxSampleTimeout = timeout

	args := flag.Args()
	if len(args) < 1 {
		usage()
	}

	u, err := sampler.NewJsonURL(args[0])
	if err == nil {
		url = *u
	}

	return
}