save code
This commit is contained in:
parent
63e4412d67
commit
f11c0a8216
29
monitor.go
29
monitor.go
@ -12,6 +12,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.zhangdeman.cn/zhangdeman/util"
|
"git.zhangdeman.cn/zhangdeman/util"
|
||||||
|
redisClient "github.com/redis/go-redis/v9"
|
||||||
|
|
||||||
yml "gopkg.in/yaml.v3"
|
yml "gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
@ -21,7 +22,7 @@ import (
|
|||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
//
|
//
|
||||||
// Date : 12:24 下午 2021/11/27
|
// Date : 12:24 下午 2021/11/27
|
||||||
func GetRedisServerInfo(client *redis.Client) (*ServerInfo, error) {
|
func GetRedisServerInfo(client *redisClient.ClusterClient) (*ServerInfo, error) {
|
||||||
var result ServerInfo
|
var result ServerInfo
|
||||||
if err := infoToStruct(client, "server", &result); nil != err {
|
if err := infoToStruct(client, "server", &result); nil != err {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -34,7 +35,7 @@ func GetRedisServerInfo(client *redis.Client) (*ServerInfo, error) {
|
|||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
//
|
//
|
||||||
// Date : 12:59 下午 2021/11/27
|
// Date : 12:59 下午 2021/11/27
|
||||||
func GetMemoryInfo(client *redis.Client) (*MemoryInfo, error) {
|
func GetMemoryInfo(client *redisClient.ClusterClient) (*MemoryInfo, error) {
|
||||||
var result MemoryInfo
|
var result MemoryInfo
|
||||||
if err := infoToStruct(client, "memory", &result); nil != err {
|
if err := infoToStruct(client, "memory", &result); nil != err {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -47,7 +48,7 @@ func GetMemoryInfo(client *redis.Client) (*MemoryInfo, error) {
|
|||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
//
|
//
|
||||||
// Date : 1:10 下午 2021/11/27
|
// Date : 1:10 下午 2021/11/27
|
||||||
func GetClientInfo(client *redis.Client) (*ClientInfo, error) {
|
func GetClientInfo(client *redisClient.ClusterClient) (*ClientInfo, error) {
|
||||||
var result ClientInfo
|
var result ClientInfo
|
||||||
if err := infoToStruct(client, "clients", &result); nil != err {
|
if err := infoToStruct(client, "clients", &result); nil != err {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -60,7 +61,7 @@ func GetClientInfo(client *redis.Client) (*ClientInfo, error) {
|
|||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
//
|
//
|
||||||
// Date : 1:11 下午 2021/11/27
|
// Date : 1:11 下午 2021/11/27
|
||||||
func GetPersistence(client *redis.Client) (*Persistence, error) {
|
func GetPersistence(client *redisClient.ClusterClient) (*Persistence, error) {
|
||||||
var result Persistence
|
var result Persistence
|
||||||
if err := infoToStruct(client, "persistence", &result); nil != err {
|
if err := infoToStruct(client, "persistence", &result); nil != err {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -73,7 +74,7 @@ func GetPersistence(client *redis.Client) (*Persistence, error) {
|
|||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
//
|
//
|
||||||
// Date : 1:19 下午 2021/11/27
|
// Date : 1:19 下午 2021/11/27
|
||||||
func GetStats(client *redis.Client) (*Stats, error) {
|
func GetStats(client *redisClient.ClusterClient) (*Stats, error) {
|
||||||
var result Stats
|
var result Stats
|
||||||
if err := infoToStruct(client, "stats", &result); nil != err {
|
if err := infoToStruct(client, "stats", &result); nil != err {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -86,7 +87,7 @@ func GetStats(client *redis.Client) (*Stats, error) {
|
|||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
//
|
//
|
||||||
// Date : 1:23 下午 2021/11/27
|
// Date : 1:23 下午 2021/11/27
|
||||||
func GetReplication(client *redis.Client) (*Replication, error) {
|
func GetReplication(client *redisClient.ClusterClient) (*Replication, error) {
|
||||||
var result Replication
|
var result Replication
|
||||||
if err := infoToStruct(client, "replication", &result); nil != err {
|
if err := infoToStruct(client, "replication", &result); nil != err {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -100,7 +101,7 @@ func GetReplication(client *redis.Client) (*Replication, error) {
|
|||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
//
|
//
|
||||||
// Date : 4:26 下午 2021/11/27
|
// Date : 4:26 下午 2021/11/27
|
||||||
func GetSlaveList(client *redis.Client) []SlaveNode {
|
func GetSlaveList(client *redisClient.ClusterClient) []SlaveNode {
|
||||||
// 解析从库信息
|
// 解析从库信息
|
||||||
slaveList := make([]SlaveNode, 0)
|
slaveList := make([]SlaveNode, 0)
|
||||||
var data map[string]string
|
var data map[string]string
|
||||||
@ -158,7 +159,7 @@ func GetSlaveList(client *redis.Client) []SlaveNode {
|
|||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
//
|
//
|
||||||
// Date : 1:24 下午 2021/11/27
|
// Date : 1:24 下午 2021/11/27
|
||||||
func GetCPUInfo(client *redis.Client) (*CPU, error) {
|
func GetCPUInfo(client *redisClient.ClusterClient) (*CPU, error) {
|
||||||
var result CPU
|
var result CPU
|
||||||
if err := infoToStruct(client, "cpu", &result); nil != err {
|
if err := infoToStruct(client, "cpu", &result); nil != err {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -171,7 +172,7 @@ func GetCPUInfo(client *redis.Client) (*CPU, error) {
|
|||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
//
|
//
|
||||||
// Date : 1:27 下午 2021/11/27
|
// Date : 1:27 下午 2021/11/27
|
||||||
func GetCommandStats(client *redis.Client) (*Stats, error) {
|
func GetCommandStats(client *redisClient.ClusterClient) (*Stats, error) {
|
||||||
var result Stats
|
var result Stats
|
||||||
if err := infoToStruct(client, "stats", &result); nil != err {
|
if err := infoToStruct(client, "stats", &result); nil != err {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -184,7 +185,7 @@ func GetCommandStats(client *redis.Client) (*Stats, error) {
|
|||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
//
|
//
|
||||||
// Date : 1:32 下午 2021/11/27
|
// Date : 1:32 下午 2021/11/27
|
||||||
func GetCommandInfo(client *redis.Client) ([]CmdStat, error) {
|
func GetCommandInfo(client *redisClient.ClusterClient) ([]CmdStat, error) {
|
||||||
var result map[string]string
|
var result map[string]string
|
||||||
if err := infoToStruct(client, "commandstats", &result); nil != err {
|
if err := infoToStruct(client, "commandstats", &result); nil != err {
|
||||||
return make([]CmdStat, 0), err
|
return make([]CmdStat, 0), err
|
||||||
@ -235,7 +236,7 @@ func GetCommandInfo(client *redis.Client) ([]CmdStat, error) {
|
|||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
//
|
//
|
||||||
// Date : 2:44 下午 2021/11/27
|
// Date : 2:44 下午 2021/11/27
|
||||||
func GetKeyspace(client *redis.Client) ([]DB, error) {
|
func GetKeyspace(client *redisClient.ClusterClient) ([]DB, error) {
|
||||||
var result map[string]string
|
var result map[string]string
|
||||||
if err := infoToStruct(client, "keyspace", &result); nil != err {
|
if err := infoToStruct(client, "keyspace", &result); nil != err {
|
||||||
return make([]DB, 0), err
|
return make([]DB, 0), err
|
||||||
@ -276,7 +277,7 @@ func GetKeyspace(client *redis.Client) ([]DB, error) {
|
|||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
//
|
//
|
||||||
// Date : 3:30 下午 2021/11/27
|
// Date : 3:30 下午 2021/11/27
|
||||||
func GetCluster(client *redis.Client) (*Cluster, error) {
|
func GetCluster(client *redisClient.ClusterClient) (*Cluster, error) {
|
||||||
var result Cluster
|
var result Cluster
|
||||||
if err := infoToStruct(client, "cluster", &result); nil != err {
|
if err := infoToStruct(client, "cluster", &result); nil != err {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -289,7 +290,7 @@ func GetCluster(client *redis.Client) (*Cluster, error) {
|
|||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
//
|
//
|
||||||
// Date : 3:35 下午 2021/11/27
|
// Date : 3:35 下午 2021/11/27
|
||||||
func GetErrorStats(client *redis.Client) ([]Error, error) {
|
func GetErrorStats(client *redisClient.ClusterClient) ([]Error, error) {
|
||||||
var result map[string]string
|
var result map[string]string
|
||||||
if err := infoToStruct(client, "errorstats", &result); nil != err {
|
if err := infoToStruct(client, "errorstats", &result); nil != err {
|
||||||
return make([]Error, 0), err
|
return make([]Error, 0), err
|
||||||
@ -316,7 +317,7 @@ func GetErrorStats(client *redis.Client) ([]Error, error) {
|
|||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
//
|
//
|
||||||
// Date : 12:28 下午 2021/11/27
|
// Date : 12:28 下午 2021/11/27
|
||||||
func infoToStruct(client *redis.Client, module string, receiver interface{}) error {
|
func infoToStruct(client *redisClient.ClusterClient, module string, receiver interface{}) error {
|
||||||
data := client.Info(context.Background(), module).String()
|
data := client.Info(context.Background(), module).String()
|
||||||
// yaml 文件规范要求, key: val , 注意 : 的后面有空格
|
// yaml 文件规范要求, key: val , 注意 : 的后面有空格
|
||||||
data = strings.ReplaceAll(data, ":", ": ")
|
data = strings.ReplaceAll(data, ":", ": ")
|
||||||
|
Loading…
Reference in New Issue
Block a user