-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add database feishu info and cockroach monitor
- Loading branch information
Showing
15 changed files
with
512 additions
and
233 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
54 changes: 54 additions & 0 deletions
54
service/exceptionmonitor/helper/monitor/cockroachdb_monitor.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,54 @@ | ||
package monitor | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"time" | ||
|
||
"github.com/labring/sealos/service/exceptionmonitor/api" | ||
"github.com/labring/sealos/service/exceptionmonitor/helper/notification" | ||
"gorm.io/driver/postgres" | ||
"gorm.io/gorm" | ||
"gorm.io/gorm/logger" | ||
) | ||
|
||
func CockroachMonitor() { | ||
for api.CockroachMonitor { | ||
notificationInfo := &api.Info{ | ||
FeishuWebHook: api.FeishuWebhookURLMap["FeishuWebhookURLCockroachDB"], | ||
} | ||
monitorCockroachDB(api.GlobalCockroachURI, "Global", notificationInfo) | ||
monitorCockroachDB(api.LocalCockroachURI, "Local", notificationInfo) | ||
|
||
time.Sleep(5 * time.Minute) | ||
} | ||
} | ||
|
||
func monitorCockroachDB(uri, label string, notificationInfo *api.Info) { | ||
if err := checkCockroachDB(uri); err != nil { | ||
message := notification.GetCockroachMessage(err.Error(), label) | ||
if sendErr := notification.SendFeishuNotification(notificationInfo, message); sendErr != nil { | ||
log.Printf("Failed to send Feishu notification for %s: %v", label, sendErr) | ||
} | ||
} | ||
} | ||
|
||
func checkCockroachDB(CockroachConnection string) error { | ||
db, err := gorm.Open(postgres.Open(CockroachConnection), &gorm.Config{ | ||
Logger: logger.Discard, | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("failed to connect to CockroachDB: %v", err) | ||
} | ||
|
||
sqlDB, err := db.DB() | ||
if err != nil { | ||
return fmt.Errorf("failed to get database instance: %v", err) | ||
} | ||
defer sqlDB.Close() | ||
|
||
if err := sqlDB.Ping(); err != nil { | ||
return fmt.Errorf("failed to ping CockroachDB: %v", err) | ||
} | ||
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
Oops, something went wrong.