Example #1
0
// New creates and returns a new MetricSet instance.
func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
	// Unpack additional configuration options.
	config := struct {
		Hosts    []string `config:"hosts"    validate:"nonzero,required"`
		Username string   `config:"username"`
		Password string   `config:"password"`
	}{
		Username: "",
		Password: "",
	}
	err := base.Module().UnpackConfig(&config)
	if err != nil {
		return nil, err
	}

	// Create and validate the data source name.
	dsn, err := mysql.CreateDSN(base.Host(), config.Username, config.Password, base.Module().Config().Timeout)
	if err != nil {
		return nil, err
	}

	return &MetricSet{
		BaseMetricSet: base,
		dsn:           dsn,
	}, nil
}
Example #2
0
// New creates and returns a new MetricSet instance.
func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
	// Unpack additional configuration options.
	config := struct {
		Username string `config:"username"`
		Password string `config:"password"`
	}{
		Username: "",
		Password: "",
	}
	err := base.Module().UnpackConfig(&config)
	if err != nil {
		return nil, err
	}

	hostToDSN := make(map[string]string, len(base.Module().Config().Hosts))
	for _, host := range base.Module().Config().Hosts {
		// TODO (akroh): Apply validation to the mysql DSN format.
		dsn := mysql.CreateDSN(host, config.Username, config.Password)
		hostToDSN[host] = dsn
	}

	return &MetricSet{
		BaseMetricSet: base,
		hostToDSN:     hostToDSN,
		connections:   map[string]*sql.DB{},
	}, nil
}
Example #3
0
// New creates and returns a new MetricSet instance.
func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
	// Unpack additional configuration options.
	config := struct {
		Username string `config:"username"`
		Password string `config:"password"`
	}{
		Username: "",
		Password: "",
	}
	err := base.Module().UnpackConfig(&config)
	if err != nil {
		return nil, err
	}

	// TODO (akroh): Apply validation to the mysql DSN format.
	dsn := mysql.CreateDSN(base.Host(), config.Username, config.Password)

	return &MetricSet{
		BaseMetricSet: base,
		dsn:           dsn,
	}, nil
}
Example #4
0
// Setup any metric specific configuration
func (m *MetricSeter) Setup(ms *helper.MetricSet) error {

	// Additional configuration options
	config := struct {
		Username string `config:"username"`
		Password string `config:"password"`
	}{
		Username: "",
		Password: "",
	}

	for _, host := range ms.Config.Hosts {
		dsn := mysql.CreateDSN(host, config.Username, config.Password)

		db, err := mysql.Connect(dsn)
		if err != nil {
			logp.Err(err.Error())
		}

		m.connections[host] = db
	}

	return nil
}