示例#1
0
func WriteEvent(f mb.EventFetcher, t *testing.T) error {

	if !*dataFlag {
		t.Skip("Skip data generation tests")
	}

	event, err := f.Fetch()
	if err != nil {
		return err
	}

	return createEvent(event, f)
}
示例#2
0
文件: module.go 项目: YaSuenag/hsbeat
func (msw *metricSetWrapper) singleEventFetch(fetcher mb.EventFetcher) (common.MapStr, error) {
	start := time.Now()
	event, err := fetcher.Fetch()
	elapsed := time.Since(start)

	if err == nil {
		msw.stats.Add(successesKey, 1)
	} else {
		msw.stats.Add(failuresKey, 1)
	}

	if event, err = createEvent(msw, event, err, start, elapsed); err != nil {
		return nil, errors.Wrap(err, "createEvent failed")
	}

	return event, nil
}
示例#3
0
func WriteEvent(f mb.EventFetcher, t *testing.T) error {

	if !*dataFlag {
		t.Skip("Skip data generation tests")
	}

	event, err := f.Fetch()
	if err != nil {
		return err
	}

	path, err := os.Getwd()
	if err != nil {
		return err
	}

	fullEvent := common.MapStr{
		"@timestamp": "2016-05-23T08:05:34.853Z",
		"beat": common.MapStr{
			"hostname": "beathost",
			"name":     "beathost",
		},
		"metricset": common.MapStr{
			"host":   "localhost",
			"module": f.Module().Name(),
			"name":   f.Name(),
			"rtt":    115,
		},
		f.Module().Name(): common.MapStr{
			f.Name(): event,
		},
		"type": "metricsets",
	}

	output, _ := json.MarshalIndent(fullEvent, "", "    ")

	err = ioutil.WriteFile(path+"/_beat/data.json", output, 0644)
	if err != nil {
		return err
	}

	return nil
}
示例#4
0
文件: module.go 项目: yan2jared/beats
func (msw *metricSetWrapper) singleEventFetch(fetcher mb.EventFetcher, host string) error {
	start := time.Now()
	event, err := fetcher.Fetch(host)
	elapsed := time.Since(start)
	if err == nil {
		msw.stats.Add(successesKey, 1)
	} else {
		msw.stats.Add(failuresKey, 1)
	}

	event, err = createEvent(msw, host, event, err, start, elapsed)
	if err != nil {
		logp.Warn("createEvent error: %v", err)
	}

	if event != nil {
		msw.module.pubClient.PublishEvent(event)
		msw.stats.Add(eventsKey, 1)
	}

	return nil
}