Exemple #1
0
func NewMysqlInstance(logger *pct.Logger, mysqlConn mysql.Connector, subscribers *Subscribers) (mi *MysqlInstance, err error) {
	if err := mysqlConn.Connect(1); err != nil {
		// 0. caller
		// 1. monitor.Add()
		// 2. monitor.createMysqlInstance()
		// 3. here
		return nil, err
	}
	defer mysqlConn.Close()

	// Get current MySQL uptime - this is later used to detect if MySQL was restarted
	lastUptime, err := mysqlConn.Uptime()
	if err != nil {
		// This shouldn't happen because we just opened the connection.
		return nil, err
	}
	lastUptimeCheck := time.Now()

	mi = &MysqlInstance{
		logger:          logger,
		mysqlConn:       mysqlConn,
		Subscribers:     subscribers,
		lastUptime:      lastUptime,
		lastUptimeCheck: lastUptimeCheck,
	}

	return mi, nil
}
Exemple #2
0
func (i *Installer) IsVersionSupported(conn mysql.Connector) (bool, error) {
	if err := conn.Connect(1); err != nil {
		return false, err
	}
	defer conn.Close()

	return conn.AtLeastVersion(agent.MIN_SUPPORTED_MYSQL_VERSION)
}
Exemple #3
0
func (f *RealIntervalIterFactory) Make(analyzerType string, mysqlConn mysql.Connector, tickChan chan time.Time) qan.IntervalIter {
	switch analyzerType {
	case "slowlog":
		// The interval iter gets the slow log file (@@global.slow_query_log_file)
		// every tick because it can change (not typical, but possible). If it changes,
		// the start offset is reset to 0 for the new file.
		getSlowLogFunc := func() (string, error) {
			if err := mysqlConn.Connect(1); err != nil {
				return "", err
			}
			defer mysqlConn.Close()
			// Slow log file can be absolute or relative. If it's relative,
			// then prepend the datadir.
			dataDir := mysqlConn.GetGlobalVarString("datadir")
			filename := AbsDataFile(dataDir, mysqlConn.GetGlobalVarString("slow_query_log_file"))
			return filename, nil
		}
		return slowlog.NewIter(pct.NewLogger(f.logChan, "qan-interval"), getSlowLogFunc, tickChan)
	case "perfschema":
		return perfschema.NewIter(pct.NewLogger(f.logChan, "qan-interval"), tickChan)
	default:
		panic("Invalid analyzerType: " + analyzerType)
	}
}