@@ -183,7 +183,7 @@ type ServerMonitor struct {
183
183
BinaryLogOldestTimestamp int64 `json:"binaryLogOldestTimestamp"`
184
184
BinaryLogPurgeBefore int64 `json:"binaryLogPurgeBefore"`
185
185
MaxSlowQueryTimestamp int64 `json:"maxSlowQueryTimestamp"`
186
- WorkLoad map [ string ] WorkLoad `json:"workLoad"`
186
+ WorkLoad * config. WorkLoadsMap `json:"workLoad"`
187
187
DelayStat * ServerDelayStat `json:"delayStat"`
188
188
SlaveVariables SlaveVariables `json:"slaveVariables"`
189
189
IsInSlowQueryCapture bool
@@ -285,6 +285,7 @@ func (cluster *Cluster) newServerMonitor(url string, user string, pass string, c
285
285
server .Plugins = config .NewPluginsMap ()
286
286
server .Users = config .NewGrantsMap ()
287
287
server .BinaryLogFiles = config .NewUIntsMap ()
288
+ server .WorkLoad = config .NewWorkLoadsMap ()
288
289
289
290
server .HaveSemiSync = true
290
291
server .HaveInnodbTrxCommit = true
@@ -335,11 +336,9 @@ func (cluster *Cluster) newServerMonitor(url string, user string, pass string, c
335
336
server .DelayStat = new (ServerDelayStat )
336
337
server .DelayStat .ResetDelayStat ()
337
338
338
- server .WorkLoad = make (map [string ]WorkLoad )
339
-
340
339
server .CurrentWorkLoad ()
341
- server .WorkLoad [ "max" ] = server .WorkLoad [ "current" ]
342
- server .WorkLoad [ "average" ] = server .WorkLoad [ "current" ]
340
+ server .WorkLoad . Set ( "max" , server .WorkLoad . Get ( "current" ))
341
+ server .WorkLoad . Set ( "average" , server .WorkLoad . Get ( "current" ))
343
342
344
343
/*if cluster.Conf.MasterSlavePgStream || cluster.Conf.MasterSlavePgLogical {
345
344
server.Conn, err = sqlx.Open("postgres", server.DSN)
@@ -1679,81 +1678,81 @@ func (server *ServerMonitor) StartGroupReplication() error {
1679
1678
}
1680
1679
1681
1680
func (server * ServerMonitor ) CurrentWorkLoad () {
1682
- new_current_WorkLoad := server .WorkLoad [ "current" ]
1681
+ new_current_WorkLoad := server .WorkLoad . GetOrNew ( "current" )
1683
1682
new_current_WorkLoad .Connections = server .GetServerConnections ()
1684
1683
new_current_WorkLoad .CpuThreadPool = server .GetCPUUsageFromThreadsPool ()
1685
1684
new_current_WorkLoad .QPS = server .QPS
1686
- server .WorkLoad [ "current" ] = new_current_WorkLoad
1685
+ server .WorkLoad . Set ( "current" , new_current_WorkLoad )
1687
1686
1688
1687
}
1689
1688
1690
1689
func (server * ServerMonitor ) AvgWorkLoad () {
1691
- new_avg_WorkLoad := server .WorkLoad [ "average" ]
1692
- if server .WorkLoad [ "average" ] .Connections > 0 {
1693
- new_avg_WorkLoad .Connections = (server .GetServerConnections () + server .WorkLoad [ "average" ] .Connections ) / 2
1690
+ new_avg_WorkLoad := server .WorkLoad . Get ( "average" )
1691
+ if server .WorkLoad . Get ( "average" ) .Connections > 0 {
1692
+ new_avg_WorkLoad .Connections = (server .GetServerConnections () + server .WorkLoad . Get ( "average" ) .Connections ) / 2
1694
1693
} else {
1695
1694
new_avg_WorkLoad .Connections = server .GetServerConnections ()
1696
1695
}
1697
1696
1698
- if server .WorkLoad [ "average" ] .CpuThreadPool > 0 {
1699
- new_avg_WorkLoad .CpuThreadPool = (server .GetCPUUsageFromThreadsPool () + server .WorkLoad [ "average" ] .CpuThreadPool ) / 2
1697
+ if server .WorkLoad . Get ( "average" ) .CpuThreadPool > 0 {
1698
+ new_avg_WorkLoad .CpuThreadPool = (server .GetCPUUsageFromThreadsPool () + server .WorkLoad . Get ( "average" ) .CpuThreadPool ) / 2
1700
1699
} else {
1701
1700
new_avg_WorkLoad .CpuThreadPool = server .GetCPUUsageFromThreadsPool ()
1702
1701
}
1703
1702
1704
- if server .WorkLoad [ "average" ] .QPS > 0 {
1705
- new_avg_WorkLoad .QPS = (server .QPS + server .WorkLoad [ "average" ] .QPS ) / 2
1703
+ if server .WorkLoad . Get ( "average" ) .QPS > 0 {
1704
+ new_avg_WorkLoad .QPS = (server .QPS + server .WorkLoad . Get ( "average" ) .QPS ) / 2
1706
1705
} else {
1707
- new_avg_WorkLoad .QPS = server .WorkLoad [ "average" ] .QPS
1706
+ new_avg_WorkLoad .QPS = server .WorkLoad . Get ( "average" ) .QPS
1708
1707
}
1709
1708
1710
- server .WorkLoad [ "average" ] = new_avg_WorkLoad
1709
+ server .WorkLoad . Set ( "average" , new_avg_WorkLoad )
1711
1710
}
1712
1711
1713
1712
func (server * ServerMonitor ) MaxWorkLoad () {
1714
- max_workLoad := server .WorkLoad [ "max" ]
1715
- if server .GetServerConnections () > server .WorkLoad [ "max" ] .Connections {
1713
+ max_workLoad := server .WorkLoad . Get ( "max" )
1714
+ if server .GetServerConnections () > server .WorkLoad . Get ( "max" ) .Connections {
1716
1715
max_workLoad .Connections = server .GetServerConnections ()
1717
1716
}
1718
1717
1719
- if server .QPS > server .WorkLoad [ "max" ] .QPS {
1718
+ if server .QPS > server .WorkLoad . Get ( "max" ) .QPS {
1720
1719
max_workLoad .QPS = server .QPS
1721
1720
}
1722
1721
1723
- if server .GetCPUUsageFromThreadsPool () > server .WorkLoad [ "max" ] .CpuThreadPool {
1722
+ if server .GetCPUUsageFromThreadsPool () > server .WorkLoad . Get ( "max" ) .CpuThreadPool {
1724
1723
max_workLoad .CpuThreadPool = server .GetCPUUsageFromThreadsPool ()
1725
1724
}
1726
1725
1727
- server .WorkLoad [ "max" ] = max_workLoad
1726
+ server .WorkLoad . Set ( "max" , max_workLoad )
1728
1727
}
1729
1728
1730
1729
func (server * ServerMonitor ) CpuFromStatWorkLoad (start_time time.Time ) time.Time {
1731
- if server .WorkLoad [ "current" ] .BusyTime != "" {
1730
+ if server .WorkLoad . Get ( "current" ) .BusyTime != "" {
1732
1731
1733
- old_cpu_time := server .WorkLoad [ "current" ] .CpuUserStats
1734
- current_workLoad := server .WorkLoad [ "current" ]
1732
+ old_cpu_time := server .WorkLoad . Get ( "current" ) .CpuUserStats
1733
+ current_workLoad := server .WorkLoad . Get ( "current" )
1735
1734
new_cpu_usage , _ := server .GetCPUUsageFromStats (start_time )
1736
1735
current_workLoad .BusyTime , _ = server .GetBusyTimeFromStats ()
1737
1736
current_workLoad .CpuUserStats = new_cpu_usage
1738
- server .WorkLoad [ "current" ] = current_workLoad
1737
+ server .WorkLoad . Set ( "current" , current_workLoad )
1739
1738
1740
1739
if old_cpu_time != 0 {
1741
- avg_workLoad := server .WorkLoad [ "average" ]
1740
+ avg_workLoad := server .WorkLoad . Get ( "average" )
1742
1741
avg_workLoad .CpuUserStats = (current_workLoad .CpuUserStats + old_cpu_time ) / 2
1743
- server .WorkLoad [ "average" ] = avg_workLoad
1742
+ server .WorkLoad . Set ( "average" , avg_workLoad )
1744
1743
}
1745
- if current_workLoad .CpuUserStats > server .WorkLoad [ "max" ] .CpuUserStats {
1746
- max_workLoad := server .WorkLoad [ "max" ]
1744
+ if current_workLoad .CpuUserStats > server .WorkLoad . Get ( "max" ) .CpuUserStats {
1745
+ max_workLoad := server .WorkLoad . Get ( "max" )
1747
1746
max_workLoad .CpuUserStats = current_workLoad .CpuUserStats
1748
- server .WorkLoad [ "max" ] = max_workLoad
1747
+ server .WorkLoad . Set ( "max" , max_workLoad )
1749
1748
1750
1749
}
1751
1750
return time .Now ()
1752
1751
1753
1752
} else {
1754
- current_workLoad := server .WorkLoad [ "current" ]
1753
+ current_workLoad := server .WorkLoad . Get ( "current" )
1755
1754
current_workLoad .BusyTime , _ = server .GetBusyTimeFromStats ()
1756
- server .WorkLoad [ "current" ] = current_workLoad
1755
+ server .WorkLoad . Set ( "current" , current_workLoad )
1757
1756
return time .Now ()
1758
1757
}
1759
1758
}
0 commit comments