Пример #1
0
// New initializes mysqlstat
// arguments: metrics context, username, password, path to config file for
// mysql. username and password can be left as "" if a config file is specified.
func New(m *metrics.MetricContext, user, password, host, config string) (*MysqlStatDBs, error) {
	s := new(MysqlStatDBs)
	// connect to database
	var err error
	s.Db, err = tools.New(user, password, host, config)
	if err != nil { //error in connecting to database
		s.Db.Log(err)
		return nil, err
	}
	s.SetMaxConnections(defaultMaxConns)
	s.Metrics = MysqlStatMetricsNew(m)
	return s, nil
}
Пример #2
0
// New initializes mysqlstat and returns it
// arguments: metrics context, username, password, path to config file for
// mysql. username and password can be left as "" if a config file is specified.
func New(m *metrics.MetricContext, user, password, host, config string) (*MysqlStatUsers, error) {
	s := new(MysqlStatUsers)
	s.M = m
	s.nLock = &sync.Mutex{}
	// connect to database
	var err error
	s.Db, err = tools.New(user, password, host, config)
	if err != nil { //error in connecting to database
		return nil, err
	}
	s.nLock.Lock()
	s.Users = make(map[string]*MysqlStatPerUser)
	s.nLock.Unlock()
	return s, nil
}