Skip to content

Commit

Permalink
feat - add connnection on mysql and proxysql
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicola Strappazzon C committed Feb 1, 2024
1 parent b088156 commit 5e28541
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
16 changes: 9 additions & 7 deletions mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import (
)

type MySQL struct {
Host string `json:"host" yaml:"host"`
Port uint16 `json:"port" yaml:"port"`
Username string `json:"username" yaml:"username"`
Password string `json:"password" yaml:"password"`
Schema string `json:"schema" yaml:"schema"`
Status string `json:"status" yaml:"status"`
Timeout uint8 `json:"timeout" yaml:"timeout"`
Connection *Connection
Host string `json:"host" yaml:"host"`
Name string `json:"name" yaml:"name"`
Password string `json:"password" yaml:"password"`
Port uint16 `json:"port" yaml:"port"`
Schema string `json:"schema" yaml:"schema"`
Status string `json:"status" yaml:"status"`
Timeout uint8 `json:"timeout" yaml:"timeout"`
Username string `json:"username" yaml:"username"`
}

func (m *MySQL) DSN() string {
Expand Down
1 change: 1 addition & 0 deletions proxysql/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ func (p *ProxySQL) AddServer(s Server) {
func (p *ProxySQL) Link() {
for i, _ := range p.Servers {
p.Servers[i].Connection = p.Connection
p.Servers[i].Stats.Connection = p.Connection
}
}
13 changes: 12 additions & 1 deletion proxysql/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,21 @@ func (s *Server) Update() error {
}

func (s *Server) Fetcher() error {
return s.Connection.Instance.QueryRow(s.QuerySelect()).Scan(
err := s.Connection.Instance.QueryRow(s.QuerySelect()).Scan(
&s.HostgroupID,
&s.Hostname,
&s.Port,
&s.Status,
&s.Weight,
&s.MaxConnections,
&s.MaxReplicationLag)

// c.ProxySQL.Servers.First().Stats.Connection = c.ProxySQL.Connection
// c.ProxySQL.Servers.First().Stats.HostgroupID = c.ProxySQL.Servers.First().HostgroupID
// c.ProxySQL.Servers.First().Stats.Hostname = c.AWS.RDS.Replica.Instance.Endpoint
// c.ProxySQL.Servers.First().Stats.Fetcher()

return err
}

func (s *Server) Delete() error {
Expand All @@ -56,6 +63,10 @@ func (s *Server) Delete() error {
return nil
}

func (s *Server) IsOnLine() bool {
return s.Status == ONLINE && s.Stats.Status == ONLINE
}

func (s *Server) QueryInsert() string {
return fmt.Sprintf(
"INSERT INTO mysql_servers (hostgroup_id, hostname, port, status, weight, max_connections, max_replication_lag) VALUES (%d, '%s', %d, '%s', %d, %d, %d);",
Expand Down
4 changes: 2 additions & 2 deletions proxysql/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ func (p *Stats) Fetcher() error {

func (p *Stats) QuerySelect() string {
return fmt.Sprintf(
"SELECT hostgroup, srv_host, srv_port, status, ConnUsed, ConnFree, ConnOK, ConnERR, MaxConnUsed, Queries, Queries_GTID_sync, Bytes_data_sent, Bytes_data_recv, Latency_us " +
"FROM stats_mysql_connection_pool WHERE hostgroup = %d AND srv_host = '%s' LIMIT 1;",
"SELECT hostgroup, srv_host, srv_port, status, ConnUsed, ConnFree, ConnOK, ConnERR, MaxConnUsed, Queries, Queries_GTID_sync, Bytes_data_sent, Bytes_data_recv, Latency_us "+
"FROM stats_mysql_connection_pool WHERE hostgroup = %d AND srv_host = '%s' LIMIT 1;",
p.HostgroupID,
p.Hostname,
)
Expand Down

0 comments on commit 5e28541

Please sign in to comment.