Пример #1
0
func TestModuleRunner(t *testing.T) {
	pubClient, factory := newPubClientFactory()

	config, err := common.NewConfigFrom(map[string]interface{}{
		"module":     moduleName,
		"metricsets": []string{metricSetName},
	})
	if err != nil {
		t.Fatal(err)
	}

	// Create a new ModuleWrapper based on the configuration.
	module, err := metricbeat.NewModuleWrapper(config, mb.Registry)
	if err != nil {
		t.Fatal(err)
	}

	// Create the ModuleRunner facade.
	runner := metricbeat.NewModuleRunner(factory, module)

	// Start the module and have it publish to a new publisher.Client.
	runner.Start()

	assert.NotNil(t, <-pubClient.Channel)

	// Stop the module. This blocks until all MetricSets in the Module have
	// stopped and the publisher.Client is closed.
	runner.Stop()
}
Пример #2
0
// ExampleModuleRunner demonstrates how to use ModuleRunner to start and stop
// a module.
func ExampleModuleRunner() {
	// A *beat.Beat is injected into a Beater when it runs and contains the
	// Publisher used to publish events. This Beat pointer is created here only
	// for demonstration purposes.
	var b *beat.Beat

	config, err := common.NewConfigFrom(map[string]interface{}{
		"module":     moduleName,
		"metricsets": []string{metricSetName},
	})
	if err != nil {
		return
	}

	// Create a new ModuleWrapper based on the configuration.
	module, err := metricbeat.NewModuleWrapper(config, mb.Registry)
	if err != nil {
		return
	}

	// Create the ModuleRunner facade.
	runner := metricbeat.NewModuleRunner(b.Publisher.Connect, module)

	// Start the module and have it publish to a new publisher.Client.
	runner.Start()

	// Stop the module. This blocks until all MetricSets in the Module have
	// stopped and the publisher.Client is closed.
	runner.Stop()
}