-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: riak监控增加指标_增加实例重启_调整dbconfig获取方式 #1576
- Loading branch information
1 parent
2553309
commit c24e765
Showing
24 changed files
with
439 additions
and
39 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
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
65 changes: 65 additions & 0 deletions
65
dbm-services/riak/db-tools/dbactuator/internal/subcmd/riakcmd/restart.go
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,65 @@ | ||
package riakcmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"dbm-services/common/go-pubpkg/logger" | ||
"dbm-services/riak/db-tools/dbactuator/internal/subcmd" | ||
"dbm-services/riak/db-tools/dbactuator/pkg/components/riak" | ||
"dbm-services/riak/db-tools/dbactuator/pkg/util" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// RestartAct 重启riak dbactor参数 | ||
type RestartAct struct { | ||
*subcmd.BaseOptions | ||
Payload riak.RestartComp | ||
} | ||
|
||
// NewRestartCommand riak重启节点 | ||
func NewRestartCommand() *cobra.Command { | ||
act := RestartAct{ | ||
BaseOptions: subcmd.GBaseOptions, | ||
} | ||
cmd := &cobra.Command{ | ||
Use: "restart", | ||
Short: "重启节点", | ||
Example: fmt.Sprintf("dbactuator riak restart %s", subcmd.CmdBaseExampleStr), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
util.CheckErr(act.Validator()) | ||
util.CheckErr(act.Init()) | ||
util.CheckErr(act.Run()) | ||
}, | ||
} | ||
return cmd | ||
} | ||
|
||
// Validator TODO | ||
func (d *RestartAct) Validator() error { | ||
return d.BaseOptions.Validate() | ||
} | ||
|
||
// Init 反序列化并检查 | ||
func (d *RestartAct) Init() error { | ||
if err := d.DeserializeAndValidate(&d.Payload); err != nil { | ||
logger.Error("DeserializeAndValidate err %s", err.Error()) | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
// Run 运行,重启节点 | ||
func (d *RestartAct) Run() error { | ||
steps := subcmd.Steps{ | ||
{ | ||
FunName: "重启节点", | ||
Func: d.Payload.Restart, | ||
}, | ||
} | ||
if err := steps.Run(); err != nil { | ||
return err | ||
} | ||
logger.Info("restart success") | ||
return nil | ||
} |
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
40 changes: 40 additions & 0 deletions
40
dbm-services/riak/db-tools/dbactuator/pkg/components/riak/restart.go
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,40 @@ | ||
// Package riak TODO | ||
/* | ||
* @Description: 安装 Riak | ||
*/ | ||
package riak | ||
|
||
import ( | ||
"dbm-services/common/go-pubpkg/logger" | ||
"dbm-services/riak/db-tools/dbactuator/pkg/util/osutil" | ||
"fmt" | ||
"time" | ||
) | ||
|
||
// RestartComp TODO | ||
type RestartComp struct { | ||
Params *RestartParam `json:"extend"` | ||
RestartRunTimeCtx `json:"-"` | ||
} | ||
|
||
// RestartParam TODO | ||
type RestartParam struct { | ||
} | ||
|
||
// RestartRunTimeCtx 运行时上下文 | ||
type RestartRunTimeCtx struct { | ||
} | ||
|
||
// Restart 启动 | ||
func (i *RestartComp) Restart() error { | ||
cmd := "riak restart" | ||
_, err := osutil.ExecShellCommand(false, cmd) | ||
if err != nil { | ||
logger.Error("execute shell [%s] error: %s", cmd, err.Error()) | ||
err = fmt.Errorf("execute shell [%s] error: %s", cmd, err.Error()) | ||
return err | ||
} | ||
time.Sleep(time.Minute) | ||
logger.Info("restart riak success") | ||
return nil | ||
} |
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
32 changes: 32 additions & 0 deletions
32
dbm-services/riak/db-tools/riak-monitor/pkg/itemscollect/connections/connections.go
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,32 @@ | ||
package connections | ||
|
||
import ( | ||
"dbm-services/riak/db-tools/riak-monitor/pkg/utils" | ||
"fmt" | ||
"strings" | ||
|
||
"golang.org/x/exp/slog" | ||
) | ||
|
||
// Connections riak实例上的连接 | ||
func Connections() (string, error) { | ||
localIp, err := utils.GetLocalIP() | ||
if err != nil { | ||
errInfo := fmt.Sprintf("get local ip error: %s", err.Error()) | ||
slog.Error(errInfo) | ||
return "", fmt.Errorf(errInfo) | ||
} | ||
// 使用netstat查看端口上的连接 | ||
cmd := `netstat -anpl|grep ':8087' | grep "beam.smp" | grep -E -v '0.0.0.0:*'` | ||
// 剔除本机上的蓝鲸监控连接,返回连接数 | ||
cmd = fmt.Sprintf(`%s | awk '{ if (index($5,"%s:") == 0) { print $0 } }' | wc -l`, cmd, localIp) | ||
resp, err := utils.ExecShellCommand(false, cmd) | ||
if err != nil { | ||
errInfo := fmt.Sprintf("execute [ %s ] error: %s", cmd, err.Error()) | ||
slog.Error(errInfo) | ||
return "", fmt.Errorf(errInfo) | ||
} | ||
resp = strings.Replace(resp, " ", "", -1) | ||
resp = strings.Replace(resp, "\n", "", -1) | ||
return resp, nil | ||
} |
46 changes: 46 additions & 0 deletions
46
dbm-services/riak/db-tools/riak-monitor/pkg/itemscollect/connections/init.go
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,46 @@ | ||
package connections | ||
|
||
import ( | ||
"dbm-services/riak/db-tools/riak-monitor/pkg/monitoriteminterface" | ||
"fmt" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
// NameConnections 检查riak连接数监控名称 | ||
var NameConnections = "riak_connections_heart_beat" | ||
|
||
func init() {} | ||
|
||
// Checker TODO | ||
type Checker struct { | ||
name string | ||
f func() (string, error) | ||
} | ||
|
||
// Run TODO | ||
func (c *Checker) Run() (msg string, err error) { | ||
msg, err = c.f() | ||
if err != nil { | ||
return "", errors.Wrap(err, fmt.Sprintf("run %s", c.name)) | ||
} | ||
return msg, nil | ||
} | ||
|
||
// Name 监控名称 | ||
func (c *Checker) Name() string { | ||
return c.name | ||
} | ||
|
||
// NewConnections 查看连接 | ||
func NewConnections(cc *monitoriteminterface.ConnectionCollect) monitoriteminterface.MonitorItemInterface { | ||
return &Checker{ | ||
name: NameConnections, | ||
f: Connections, | ||
} | ||
} | ||
|
||
// RegisterConnections 注册查看连接 | ||
func RegisterConnections() (string, monitoriteminterface.MonitorItemConstructorFuncType) { | ||
return NameConnections, NewConnections | ||
} |
Oops, something went wrong.