Beispiel #1
0
/* Initializes a server object */
func newServerMonitor(url string) (*ServerMonitor, error) {
	server := new(ServerMonitor)
	server.URL = url
	server.Host, server.Port = splitHostPort(url)
	var err error
	server.IP, err = dbhelper.CheckHostAddr(server.Host)
	if err != nil {
		return server, errors.New(fmt.Sprintf("ERROR: DNS resolution error for host %s", server.Host))
	}
	server.Conn, err = dbhelper.MySQLConnect(dbUser, dbPass, dbhelper.GetAddress(server.Host, server.Port, *socket))
	if err != nil {
		return server, errors.New(fmt.Sprintf("ERROR: could not connect to server %s: %s", url, err))
	}
	return server, nil
}
/* Initializes a server object */
func newServerMonitor(url string) (*ServerMonitor, error) {
	server := new(ServerMonitor)
	server.URL = url
	server.Host, server.Port = splitHostPort(url)
	var err error
	server.IP, err = dbhelper.CheckHostAddr(server.Host)
	if err != nil {
		return server, errors.New(fmt.Sprintf("ERROR: DNS resolution error for host %s", server.Host))
	}
	params := fmt.Sprintf("timeout=%ds", timeout)
	server.Conn, err = dbhelper.MySQLConnect(dbUser, dbPass, dbhelper.GetAddress(server.Host, server.Port, socket), params)
	if err != nil {
		server.State = stateFailed
		return server, err
	}
	return server, nil
}
Beispiel #3
0
func clustercheck(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("content-type", "text/html")
	db = dbhelper.Connect(myvars["user"], myvars["password"], dbhelper.GetAddress(myvars["host"], myvars["port"], myvars["socket"]))
	defer db.Close()
	var (
		readonly string
		state    int
	)
	if *dwr == true {
		db.QueryRow("select variable_value as readonly from information_schema.global_variables where variable_name='read_only'").Scan(&readonly)
	}
	err := db.QueryRow("select variable_value as state from information_schema.global_status where variable_name='wsrep_local_state'").Scan(&state)
	if err != nil {
		w.WriteHeader(503)
		fmt.Fprintf(w, "Cannot check cluster state: %v", err)
	} else if (*dwr == false && state == 4) || (*awd == false && state == 2) || (*dwr == true && readonly == "OFF" && state == 4) {
		fmt.Fprint(w, "MariaDB Cluster Node is synced.")
	} else {
		w.WriteHeader(503)
		fmt.Fprint(w, "MariaDB Cluster Node is not synced.")
	}
}