Exemple #1
0
func TestFetch(t *testing.T) {

	if testing.Short() {
		t.Skip("Skipping in short mode, because it requires MySQL")
	}

	// Setup Metric
	m := New()

	config := helper.ModuleConfig{
		Hosts: []string{mysql.GetMySQLEnvDSN()},
	}
	module := &helper.Module{
		Config: config,
	}
	ms := helper.NewMetricSet("status", m, module)

	// Load events
	events, err := m.Fetch(ms)
	assert.NoError(t, err)

	// Check event fields
	connections := events[0]["Connections"].(int)
	openTables := events[0]["Open_tables"].(int)
	openFiles := events[0]["Open_files"].(int)
	openStreams := events[0]["Open_streams"].(int)

	assert.True(t, connections > 0)
	assert.True(t, openTables > 0)
	assert.True(t, openFiles > 0)
	assert.True(t, openStreams == 0)
}
Exemple #2
0
func TestConnect(t *testing.T) {

	if testing.Short() {
		t.Skip("Skipping in short mode, because it requires Redis")
	}

	// Setup
	r := &MetricSeter{}

	config := helper.ModuleConfig{
		Hosts: []string{redis.GetRedisEnvHost() + ":" + redis.GetRedisEnvPort()},
	}
	module := &helper.Module{
		Config: config,
	}
	ms := helper.NewMetricSet("info", r, module)

	data, err := r.Fetch(ms)
	assert.NoError(t, err)

	// Check fields
	assert.Equal(t, 8, len(data[0]))

	server := data[0]["server"].(common.MapStr)

	assert.Equal(t, "3.0.7", server["redis_version"])
	assert.Equal(t, "standalone", server["redis_mode"])
}
Exemple #3
0
func TestFetch(t *testing.T) {

	config := helper.ModuleConfig{
		Hosts: []string{mysql.GetMySQLEnvDSN()},
	}
	module := &helper.Module{
		Config: config,
	}

	ms, msErr := helper.NewMetricSet("status", New, module)
	assert.NoError(t, msErr)

	var err error

	// Setup metricset
	err = ms.Setup()
	assert.NoError(t, err)

	// Load events
	event, err := ms.MetricSeter.Fetch(ms, module.Config.Hosts[0])
	assert.NoError(t, err)

	// Check event fields
	connections := event["Connections"].(int)
	open := event["open"].(common.MapStr)
	openTables := open["Open_tables"].(int)
	openFiles := open["Open_files"].(int)
	openStreams := open["Open_streams"].(int)

	assert.True(t, connections > 0)
	assert.True(t, openTables > 0)
	assert.True(t, openFiles >= 0)
	assert.True(t, openStreams == 0)
}
Exemple #4
0
func getRedisMetricSet(pass string) (*helper.MetricSet, error) {
	config, _ := getRedisModuleConfig(pass)
	module, mErr := helper.NewModule(config, redis.New)
	if mErr != nil {
		return nil, mErr
	}
	return helper.NewMetricSet("info", New, module)
}
func TestConnect(t *testing.T) {

	config, _ := getApacheModuleConfig()

	module, mErr := helper.NewModule(config, apache.New)
	assert.NoError(t, mErr)
	ms, msErr := helper.NewMetricSet("status", New, module)
	assert.NoError(t, msErr)

	// Setup metricset and metricseter
	err := ms.Setup()
	assert.NoError(t, err)
	err = ms.MetricSeter.Setup(ms)
	assert.NoError(t, err)

	// Check that host is correctly set
	assert.Equal(t, apache.GetApacheEnvHost(), ms.Config.Hosts[0])

	data, err := ms.MetricSeter.Fetch(ms, ms.Config.Hosts[0])
	assert.NoError(t, err)

	// Check fields
	assert.Equal(t, 13, len(data))
}
Exemple #6
0
// Fetches statistics from the output of running beats
package expvar

import (
	"github.com/elastic/beats/libbeat/common"
	"github.com/elastic/beats/metricbeat/helper"
	"github.com/elastic/beats/metricbeat/module/golang"
)

func init() {
	MetricSet.Register()
}

// MetricSet Setup
var MetricSet = helper.NewMetricSet("expvar", ExpvarMetric{}, golang.Module)

// MetricSetter object
type ExpvarMetric struct {
	helper.MetricSetConfig
}

func (b ExpvarMetric) Setup() error {
	return nil
}

// Fetch expvars from a running beat
func (b ExpvarMetric) Fetch() (events []common.MapStr, err error) {

	//path := "http://localhost:6060/debug/vars"

	event := common.MapStr{
Exemple #7
0
	rd "github.com/garyburd/redigo/redis"

	"github.com/elastic/beats/libbeat/common"
	"github.com/elastic/beats/libbeat/logp"

	"github.com/elastic/beats/metricbeat/helper"
	"github.com/elastic/beats/metricbeat/module/redis"
)

func init() {
	MetricSet.Register()
}

// Metric object
var MetricSet = helper.NewMetricSet("info", MetricSeter{}, redis.Module)

var Config = &MetricSetConfig{}

type MetricSetConfig struct {
}

type MetricSeter struct {
	Name   string
	Config MetricSetConfig
}

func (m MetricSeter) Setup() error {
	// Loads module config
	// This is module specific config object
	MetricSet.LoadConfig(&Config)
Exemple #8
0
import (
	"fmt"
	"net/http"

	"github.com/elastic/beats/libbeat/common"

	"github.com/elastic/beats/libbeat/logp"
	"github.com/elastic/beats/metricbeat/helper"
	"github.com/elastic/beats/metricbeat/module/apache"
)

func init() {
	MetricSet.Register()
}

var MetricSet = helper.NewMetricSet("status", MetricSeter{}, apache.Module)

type MetricSeter struct {
}

func (m MetricSeter) Setup() error {
	return nil
}

func (m MetricSeter) Fetch() (events []common.MapStr, err error) {

	hosts := MetricSet.Module.GetHosts()

	for _, host := range hosts {
		resp, err := http.Get(host + "server-status?auto")
		defer resp.Body.Close()
Exemple #9
0
import (
	"database/sql"

	"github.com/elastic/beats/libbeat/common"
	"github.com/elastic/beats/libbeat/logp"
	"github.com/elastic/beats/metricbeat/helper"
	"github.com/elastic/beats/metricbeat/module/mysql"
)

func init() {
	MetricSet.Register()
}

// Metric Setup
var MetricSet = helper.NewMetricSet("status", MetricSeter{}, mysql.Module)

// MetricSetter object
type MetricSeter struct {
	helper.MetricSetConfig
}

func (m MetricSeter) Setup() error {
	return nil
}

// Fetches status messages from mysql hosts
func (m MetricSeter) Fetch() (events []common.MapStr, err error) {

	// Load status for all hosts and add it to events
	for _, host := range MetricSet.Module.GetHosts() {