示例#1
0
//initializes mysqlstat.
// starts off collect
func New(m *metrics.MetricContext, Step time.Duration, user, password, config string) (*MysqlStat, error) {
	s := new(MysqlStat)

	// connect to database
	var err error
	s.db, err = mysqltools.New(user, password, config)
	if err != nil {
		s.db.Log(err)
		return nil, err
	}
	s.Metrics = MysqlStatMetricsNew(m, Step)

	s.Collect()

	ticker := time.NewTicker(Step)
	go func() {
		for _ = range ticker.C {
			go s.Collect()
		}
	}()
	return s, nil
}
示例#2
0
//initializes mysqlstat
// starts off collect
func New(m *metrics.MetricContext, Step time.Duration, user, password, config string) (*MysqlStatTables, error) {
	s := new(MysqlStatTables)
	s.m = m
	s.nLock = &sync.Mutex{}
	// connect to database
	var err error
	s.db, err = mysqltools.New(user, password, config)
	s.nLock.Lock()
	s.DBs = make(map[string]*DBStats)
	s.nLock.Unlock()
	if err != nil { //error in connecting to database
		return nil, err
	}

	s.Collect()

	ticker := time.NewTicker(Step)
	go func() {
		for _ = range ticker.C {
			go s.Collect()
		}
	}()
	return s, nil
}