forked from signal18/replication-manager
/
prx_sphinx.go
86 lines (73 loc) · 2.25 KB
/
prx_sphinx.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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
}
}