MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / LoadStatus

Method LoadStatus

agent/app/service/database_mysql.go:540–587  ·  view source on GitHub ↗
(req dto.OperationWithNameAndType)

Source from the content-addressed store, hash-verified

538}
539
540func (u *MysqlService) LoadStatus(req dto.OperationWithNameAndType) (*dto.MysqlStatus, error) {
541 app, err := appInstallRepo.LoadBaseInfo(req.Type, req.Name)
542 if err != nil {
543 return nil, err
544 }
545
546 statusMap, err := executeSqlForMaps(app.ContainerName, app.Key, app.Password, "show global status;")
547 if err != nil {
548 return nil, err
549 }
550
551 var info dto.MysqlStatus
552 arr, err := json.Marshal(statusMap)
553 if err != nil {
554 return nil, err
555 }
556 _ = json.Unmarshal(arr, &info)
557
558 if value, ok := statusMap["Run"]; ok {
559 uptime, _ := strconv.Atoi(value)
560 info.Run = time.Unix(time.Now().Unix()-int64(uptime), 0).Format(constant.DateTimeLayout)
561 } else {
562 if value, ok := statusMap["Uptime"]; ok {
563 uptime, _ := strconv.Atoi(value)
564 info.Run = time.Unix(time.Now().Unix()-int64(uptime), 0).Format(constant.DateTimeLayout)
565 }
566 }
567
568 info.File = "OFF"
569 info.Position = "OFF"
570 masterStatus := "show master status;"
571 if common.CompareAppVersion(app.Version, "8.4.0") && (req.Type == constant.AppMysql || req.Type == constant.AppMysqlCluster) {
572 masterStatus = "show binary log status;"
573 }
574 rows, err := executeSqlForRows(app.ContainerName, app.Key, app.Password, masterStatus)
575 if err != nil {
576 return nil, err
577 }
578 if len(rows) > 2 {
579 itemValue := strings.Split(rows[1], "\t")
580 if len(itemValue) > 2 {
581 info.File = itemValue[0]
582 info.Position = itemValue[1]
583 }
584 }
585
586 return &info, nil
587}
588
589func (u *MysqlService) LoadFormatOption(req dto.OperationWithName) []dto.MysqlFormatCollationOption {
590 defaultList := []dto.MysqlFormatCollationOption{{Format: "utf8mb4"}, {Format: "utf8mb3"}, {Format: "gbk"}, {Format: "big5"}}

Callers

nothing calls this directly

Calls 4

executeSqlForMapsFunction · 0.85
executeSqlForRowsFunction · 0.85
LoadBaseInfoMethod · 0.65
FormatMethod · 0.45

Tested by

no test coverage detected