Skip to content

Commit

Permalink
database exception monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
wallyxjh committed Jul 7, 2024
1 parent f649f30 commit 42583a5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
14 changes: 9 additions & 5 deletions service/exceptionmonitor/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package api

import (
"errors"
"fmt"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -58,6 +59,7 @@ var (
FeishuWebhookURLMap = make(map[string]string)
ClusterRegionMap = make(map[string]string)
BaseURL string
LOCALREGION string
DatabaseMonitor bool
DiskMonitor bool
CPUMemMonitor bool
Expand All @@ -75,6 +77,7 @@ func GetENV() error {
ClusterName = getEnvWithCheck("ClusterName", &missingEnvVars)
MonitorType = getEnvWithCheck("MonitorType", &missingEnvVars)
clusterNS := getEnvWithCheck("ClusterNS", &missingEnvVars)
LOCALREGION = getEnvWithCheck("LOCALREGION", &missingEnvVars)
DatabaseMonitor, _ = strconv.ParseBool(getEnvWithCheck("DatabaseMonitor", &missingEnvVars))
DiskMonitor, _ = strconv.ParseBool(getEnvWithCheck("DiskMonitor", &missingEnvVars))
CPUMemMonitor, _ = strconv.ParseBool(getEnvWithCheck("CPUMemMonitor", &missingEnvVars))
Expand Down Expand Up @@ -104,11 +107,11 @@ func GetENV() error {

// Get ClusterRegionMap
getEnvMapWithCheck([]string{
"REGION_IO",
"REGION_BJA",
"REGION_HZH",
"REGION_GZG",
"REGION_TOP",
"io",
"bja",
"hzh",
"gzg",
"top",
}, ClusterRegionMap, &missingEnvVars)

if len(missingEnvVars) > 0 {
Expand All @@ -123,6 +126,7 @@ func getEnvWithCheck(key string, missingEnvVars *[]string) string {
if MonitorType == MonitorTypeALL && key == "ClusterNS" {
return value
}
fmt.Println(key)
*missingEnvVars = append(*missingEnvVars, key)
}
return value
Expand Down
4 changes: 3 additions & 1 deletion service/exceptionmonitor/dao/init.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dao

import (
"github.com/labring/sealos/service/exceptionmonitor/api"
"os"

"github.com/labring/sealos/controllers/pkg/database/cockroach"
Expand All @@ -12,7 +13,8 @@ var (

func InitCockroachDB() error {
var err error
os.Setenv("LOCAL_REGION", "6a216614-e658-4482-a244-e4311390715f")
os.Setenv("LOCAL_REGION", api.LOCALREGION)

CK, err = cockroach.NewCockRoach(os.Getenv("GlobalCockroachURI"), os.Getenv("LocalCockroachURI"))
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions service/exceptionmonitor/helper/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

func InitClient() error {
//TODO Get kubernetes.client through k8s.io/client-go/rest.InClusterConfig()
kubeconfigPath := "/home/nonroot/kubeconfig/kubeconfig"

kubeconfig, err := os.ReadFile(kubeconfigPath)
Expand Down
4 changes: 2 additions & 2 deletions service/exceptionmonitor/helper/notification/feishu.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func GetNotificationMessage(notificationInfo Info) string {
{
"tag": "div",
"text": map[string]string{
"content": fmt.Sprintf("集群环境:%s", api.ClusterRegionMap[api.ClusterName]),
"content": fmt.Sprintf("集群环境:%s", api.ClusterName),
"tag": "lark_md",
},
},
Expand Down Expand Up @@ -222,7 +222,7 @@ func createCard(headerTemplate, headerTitle string, elements []map[string]string

func createElements(namespace, backupName, status, startTime, reason string, includeReason bool) []map[string]string {
elements := []map[string]string{
{"label": "集群环境", "value": api.ClusterRegionMap[api.ClusterName]},
{"label": "集群环境", "value": api.ClusterName},
{"label": "命名空间", "value": namespace},
{"label": "备份名", "value": backupName},
{"label": "备份状态", "value": status},
Expand Down

0 comments on commit 42583a5

Please sign in to comment.