Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
207 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// replication-manager - Replication Manager Monitoring and CLI for MariaDB and MySQL | ||
// Copyright 2017 Signal 18 SARL | ||
// Authors: Guillaume Lefranc <guillaume@signal18.io> | ||
// Stephane Varoqui <svaroqui@gmail.com> | ||
// This source code is licensed under the GNU General Public License, version 3. | ||
// Redistribution/Reuse of this code is permitted under the GNU v3 license, as | ||
// an additional term, ALL code must carry the original Author(s) credit in comment form. | ||
// See LICENSE in this directory for the integral text. | ||
package cluster | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/signal18/replication-manager/sphinx" | ||
"github.com/signal18/replication-manager/state" | ||
) | ||
|
||
func connectSphinx(proxy *Proxy) (sphinx.SphinxSQL, error) { | ||
sphinx := sphinx.SphinxSQL{ | ||
User: proxy.User, | ||
Password: proxy.Pass, | ||
Host: proxy.Host, | ||
Port: proxy.Port, | ||
} | ||
|
||
var err error | ||
err = sphinx.Connect() | ||
if err != nil { | ||
return sphinx, err | ||
} | ||
return sphinx, nil | ||
} | ||
|
||
func (cluster *Cluster) initSphinx(proxy *Proxy) { | ||
if cluster.conf.SphinxOn == false { | ||
return | ||
} | ||
|
||
sphinx, err := connectSphinx(proxy) | ||
if err != nil { | ||
cluster.sme.AddState("ERR00051", state.State{ErrType: "ERROR", ErrDesc: fmt.Sprintf(clusterError["ERR00051"], err), ErrFrom: "MON"}) | ||
return | ||
} | ||
defer sphinx.Connection.Close() | ||
|
||
} | ||
|
||
func (cluster *Cluster) refreshSphinx(proxy *Proxy) { | ||
if cluster.conf.SphinxOn == false { | ||
return | ||
} | ||
|
||
sphinx, err := connectSphinx(proxy) | ||
if err != nil { | ||
cluster.sme.AddState("ERR00051", state.State{ErrType: "ERROR", ErrDesc: fmt.Sprintf(clusterError["ERR00051"], err), ErrFrom: "MON"}) | ||
return | ||
} | ||
defer sphinx.Connection.Close() | ||
proxy.Version = sphinx.GetVersion() | ||
|
||
proxy.BackendsWrite = nil | ||
proxy.BackendsRead = nil | ||
|
||
status, err := sphinx.GetStatus() | ||
var bke = Backend{ | ||
Host: cluster.conf.ProvProxRouteAddr, | ||
Port: cluster.conf.ProvProxRoutePort, | ||
Status: "UP", | ||
PrxName: "", | ||
PrxStatus: "UP", | ||
PrxConnections: status["CONNECTIONS"], | ||
PrxByteIn: "0", | ||
PrxByteOut: "0", | ||
PrxLatency: status["AVG_QUERY_WALL"], | ||
} | ||
if err == nil { | ||
proxy.BackendsWrite = append(proxy.BackendsRead, bke) | ||
} | ||
} | ||
|
||
func (cluster *Cluster) setMaintenanceSphinx(proxy *Proxy, host string, port string) { | ||
if cluster.conf.SphinxOn == false { | ||
return | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package sphinx | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/go-sql-driver/mysql" | ||
"github.com/jmoiron/sqlx" | ||
) | ||
|
||
type SphinxSQL struct { | ||
Connection *sqlx.DB | ||
User string | ||
Password string | ||
Port string | ||
Host string | ||
} | ||
|
||
func (sphinxql *SphinxSQL) Connect() error { | ||
SphinxConfig := mysql.Config{ | ||
User: sphinxql.User, | ||
Passwd: sphinxql.Password, | ||
Net: "tcp", | ||
Addr: fmt.Sprintf("%s:%s", sphinxql.Host, sphinxql.Port), | ||
Timeout: time.Second * 5, | ||
ReadTimeout: time.Second * 15, | ||
} | ||
|
||
var err error | ||
sphinxql.Connection, err = sqlx.Connect("mysql", SphinxConfig.FormatDSN()) | ||
if err != nil { | ||
return fmt.Errorf("Could not connect to SphinxQL (%s)", err) | ||
} | ||
return nil | ||
} | ||
|
||
func (sphinxql *SphinxSQL) GetVariables() (map[string]string, error) { | ||
type Variable struct { | ||
Variable_name string | ||
Value string | ||
} | ||
|
||
vars := make(map[string]string) | ||
rows, err := sphinxql.Connection.Queryx("SHOW VARIABLES") | ||
if err != nil { | ||
return nil, errors.New("Could not get status variables") | ||
} | ||
for rows.Next() { | ||
var v Variable | ||
err := rows.Scan(&v.Variable_name, &v.Value) | ||
if err != nil { | ||
return nil, errors.New("Could not get results from status scan") | ||
} | ||
vars[v.Variable_name] = v.Value | ||
} | ||
return vars, nil | ||
} | ||
|
||
func (sphinxql *SphinxSQL) GetStatus() (map[string]string, error) { | ||
type Variable struct { | ||
Variable_name string | ||
Value string | ||
} | ||
|
||
vars := make(map[string]string) | ||
rows, err := sphinxql.Connection.Queryx("SHOW STATUS") | ||
if err != nil { | ||
return nil, errors.New("Could not get status variables") | ||
} | ||
for rows.Next() { | ||
var v Variable | ||
err := rows.Scan(&v.Variable_name, &v.Value) | ||
if err != nil { | ||
return nil, errors.New("Could not get results from status scan") | ||
} | ||
vars[v.Variable_name] = v.Value | ||
} | ||
return vars, nil | ||
|
||
} | ||
|
||
func (sphinxql *SphinxSQL) GetVersion() string { | ||
var version string | ||
return version | ||
} | ||
|
||
func (sphinxql *SphinxSQL) GetIndexes() (map[string]string, error) { | ||
type Indexes struct { | ||
Index string | ||
Type string | ||
} | ||
|
||
vars := make(map[string]string) | ||
rows, err := sphinxql.Connection.Queryx("SHOW TABLES") | ||
if err != nil { | ||
return nil, errors.New("Could not get status variables") | ||
} | ||
for rows.Next() { | ||
var v Indexes | ||
err := rows.Scan(&v.Index, &v.Type) | ||
if err != nil { | ||
return nil, errors.New("Could not get results from status scan") | ||
} | ||
vars[v.Index] = v.Type | ||
} | ||
return vars, nil | ||
} |